serverless lambda in golang with aws dynamodb local
make: choco install make
| apt-get install make
file-watcher: pip install https://github.com/joh/when-changed/archive/master.zip
aws-sam: aws-sam: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
docker: choco install docker-desktop
| sudo apt-get install docker-ce docker-ce-cli containerd.io
dynamodb-admin: npm install dynamodb-admin -g
Full list of commands are listed in Makefile
If you are on windows, you need to have git bash
cli installed to run the commands1
make aws-sam
Open another terminal
make watch
Only file changes in the src directory is detected.
Also note that if you change the sam-template.yml file, you will have to restart the aws-sam development server too
Open another terminal
make db
- Need to ensure that aws-sam and dynamodb local run on the same docker network
sam local start-api --docker-network local-network
# docker-compose.yml for amazon/dynamodb-local
networks:
backend:
name: local-network
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- 1234:8000
networks:
- backend
- Need to configure the aws sdk client to point to the local dynamodb endpoint, e.g.
var config = aws.NewConfig().WithEndpoint("http://localhost:1234").
var Client = dynamodb.New(..., config)
If running docker on windows, need to speicfy the endpoint as http://host.docker.internal:1234
instead of http://localhost:1234
. This is due to the fact that the host has a changing IP address.
After make db
, open the browser, and go to http://localhost:8001
make stop-db
npm install -g serverless
serverless create --template aws-go-mod --path my-folder
Then replace the serverless.yml
with the sam-template.yml
serverless framework does not yet fully support golang development, e.g. no sls offline dev server
Regardless, the generated template is helpful