Created
February 14, 2018 22:21
-
-
Save calavera/785152e269c49d152e12e9e19c3c40e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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