Skip to content

An example for serverless application development on local machine (AWS Lambda, DynamoDB)

Notifications You must be signed in to change notification settings

raahii/serverless-app-local

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Local development environment for aws serverless application

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.

About

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.

Required

  • aws-cli
  • docker-compose
  • golang (~1.11)
    • export GO111MODULE=on

Getting Started

  • 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

Make a request to DynamoDB

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}'

Make a request to api server

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"
        ]
    }

Web user interface (dashboard)

The port is 8888. Access with your browser to watch localstack resources.