A template for creating AWS Lambda REST APIs with Go, deployed using Docker. This setup supports local testing without requiring AWS API Gateway for routing.
- AWS Lambda: Run your Go applications in AWS Lambda.
- Docker: Deploy using Docker containers.
- Local Testing: Test your API locally without AWS API Gateway.
- Routing: Handle routing within the Go application.
- MIT License: Open-source and free to use.
Dennj Osele - [email protected]
git clone https://github.com/dennj/aws-lambda-go-rest-docker.git
cd aws-lambda-go-rest-docker
docker build --platform linux/amd64 -t docker-image:test .
docker run -d -p 9000:9000 --name lambda-go docker-image:test
curl -X GET "http://localhost:9000/v1/getinfo/12345"
curl -X POST "http://localhost:9000/v1/set/12345/of/67890"
docker ps
docker stop lambda-go
docker rm lambda-go
aws ecr create-repository --repository-name lambda-go-rest
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
docker tag lambda-go-rest <account-id>.dkr.ecr.<region>.amazonaws.com/lambda-go-rest:latest
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/lambda-go-rest:latest
aws lambda create-function --function-name lambda-go \
--package-type Image \
--code ImageUri=<account-id>.dkr.ecr.<region>.amazonaws.com/lambda-go-rest:latest \
--role <your-execution-role-arn>
aws apigatewayv2 create-api --name "LambdaGoAPI" --protocol-type HTTP
aws apigatewayv2 create-integration \
--api-id <api-id> \
--integration-type AWS_PROXY \
--integration-uri arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account-id>:function:lambda-go/invocations \
--payload-format-version 2.0
aws apigatewayv2 create-route \
--api-id <api-id> \
--route-key "ANY /{proxy+}" \
--target "integrations/<integration-id>"
aws apigatewayv2 create-deployment --api-id <api-id> --stage-name prod
aws lambda add-permission --function-name lambda-go \
--statement-id apigateway-access \
--action lambda:InvokeFunction \
--principal apigateway.amazonaws.com \
--source-arn arn:aws:execute-api:<region>:<account-id>:<api-id>/*/*/*