This repository contains a json api server using AWS Lambda Function and DynamoDB. It also contains some lambda functions written in golang, but they are just examples.
This sample enables development of serverless application using AWS cloud services on your machine by using docker. The author has developed this on MacOS and has not considered other OS specific issues.
Here, aws-sam-cli is used to reproduce Lambda Function and calling it from API Gateway. And we use localstack to reproduce DynamoDB.
Other AWS services (ex. S3, SQS, etc) are also available as long as they are supported by localstack.
- aws-cli
- docker-compose
- golang (~1.11)
export GO111MODULE=on
-
Start/Stop/Restart the appication
make start
make stop
make restart
-
Compile Go source codes
make build
-
Watch the api server logs
docker-compose logs -f sam
The port is 4569 by default.
aws dynamodb list-tables --endpoint-url 'http://localhost:4569'
aws dynamodb create-table --endpoint-url 'http://localhost:4569' \
--table-name 'dummy' \
--attribute-definitions '[{"AttributeName":"key","AttributeType": "S"}]' \
--key-schema '[{"AttributeName":"key","KeyType": "HASH"}]' \
--provisioned-throughput '{"ReadCapacityUnits": 5,"WriteCapacityUnits": 5}'
The port is 8000 by default. All of api configuration is specified in lambda/template.yaml
.
-
/
:lambda/hello
Hello World function.
curl localhost:8000/
"Hello, 60.61.189.189"
-
/tables
:lambda/list-tables
Return table names in dynamodb.
curl localhost:8000/tables
{ "table_names": [ "dummy" ] }
The port is 8888. Access with your browser to watch localstack resources.