This is a sample project that demonstrates how to use AWS Lambda with API Gateway, DynamoDB, and SQS using the Serverless Framework and LocalStack. The project is written in Go and includes two Lambda functions:
createOrder
- creates a new order in a DynamoDB tableprocessPayment
- simulates processing a payment using an SQS queue
The project is organized into the following directories and files:
├── bin/
├── src/
│ ├── createOrder/
│ │ ├── createOrder.go
│ │ └── main.go
│ └── processPayment/
│ ├── processPayment.go
│ └── main.go
├── build.sh
├── Dockerfile
├── docker-compose.yml
├── go.mod
├── go.sum
├── main.go
└── serverless.yml
bin/
- contains the compiled Go binaries for each Lambda functionsrc/
- contains the source code for each Lambda function, organized into subdirectoriesbuild.sh
- a script for compiling the Go binaries for each Lambda functionDockerfile
- a Dockerfile for running the project using LocalStackdocker-compose.yml
- a Docker Compose file for starting LocalStack and running the projectgo.mod
- the Go module file that specifies the project's dependenciesgo.sum
- a checksum file for the project's dependenciesmain.go
- the main file that contains the Lambda handler function that routes requests to the appropriate Lambda functionserverless.yml
- the Serverless Framework configuration file that specifies the API Gateway, DynamoDB, and SQS resources for the project
To run the project locally using LocalStack, follow these steps:
- Install Docker and Docker Compose.
- Clone the repository and navigate to the project directory.
- Run
docker-compose up
to start LocalStack and run the project. - Navigate to
http://localhost:4566/health
to ensure that LocalStack is running. - Use an HTTP client such as
curl
orPostman
to send requests to the API Gateway endpoints. The endpoints are defined inserverless.yml
and are printed to the console when you rundocker-compose up
.
To deploy the project to production on AWS, follow these steps:
- Ensure that you have an AWS account and have set up your AWS credentials on your local machine.
- Install the Serverless Framework CLI.
- Set up your Serverless Framework credentials by running serverless config credentials --provider aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_KEY.
- Navigate to the project directory.
- Run ./deploy.sh prod to deploy the project to AWS.
This project is licensed under the MIT License. See LICENSE
for more information.