Skip to content

Instantly share code, notes, and snippets.

@calavera
Created February 14, 2018 22:21
Show Gist options
  • Save calavera/785152e269c49d152e12e9e19c3c40e2 to your computer and use it in GitHub Desktop.
Save calavera/785152e269c49d152e12e9e19c3c40e2 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type data struct {
Payload map[string]interface{} `json:"payload"`
Site map[string]interface{} `json:"site"`
}
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
var d data
err := json.NewDecoder(strings.NewReader(request.Body)).Decode(&d)
fmt.Printf("Submission ID for demo: %s\n", d.Payload["id"])
status := http.StatusOK
if err != nil {
fmt.Println(err)
status = http.StatusUnprocessableEntity
}
return events.APIGatewayProxyResponse{
StatusCode: status,
}, nil
}
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment