Skip to content

Instantly share code, notes, and snippets.

@Kalimaha
Created May 16, 2020 05:32
Show Gist options
  • Save Kalimaha/6faf0920d033154c30e257ffbfb0e5a8 to your computer and use it in GitHub Desktop.
Save Kalimaha/6faf0920d033154c30e257ffbfb0e5a8 to your computer and use it in GitHub Desktop.
Go Lambda
package main
import (
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type MyResponse struct {
ResponseId string
}
// Invoke it locally
// aws --profile sideprojects lambda invoke --function-name RetrievePotatoes --payload '{"pathParameters": {"requestId": "42"}}' response.json
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
requestId := request.PathParameters["requestId"]
response := MyResponse{ResponseId: requestId}
body, _ := json.Marshal(response)
return events.APIGatewayProxyResponse{Body: string(body), StatusCode: 200}, nil
}
func main() {
lambda.Start(Handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment