This project is a simple serverless microservice on AWS that enables users to create and manage movies data. The entire backend is based on API Gateway, Lambda and DynamoDB. To manage, document and visualize all APIs in one place, SwaggerHub is used.
The goal of this project is to show how to create an application composed of small, easily deployable, loosely coupled, independently scalable, serverless components.
As I’m strongly against managing environments manually and take Infrastructure as Code 💙 for granted, AWS SAM will be a great fit for this serverless project. As a result, the entire application should be deployed in any AWS account with a single CloudFormation template.
1️⃣ A user sends a request to the server by calling APIs from SwaggerHub UI. The request which includes all necessary information is sent to Amazon API Gateway restful service.
2️⃣ API Gateway transfers the collected user information to a Lambda function.
3️⃣ AWS Lambda function executes event-based logic calling DynamoDB database.
4️⃣ DynamoDB provides a persistence layer where data can be stored/retrieved by the API's Lambda function.
The high-level architecture for the serverless microservice is illustrated in the diagram below:
To codify, build, package, deploy, and manage our AWS resources in a fully automated fashion, use the following:
👉 AWS SAM
👉 AWS CloudFormation
👉 AWS CLI
👉 AWS SDK for Python (boto3)
👉 Docker
If you don't want to install or maintain a local IDE, use AWS Cloud9 instead (you can find how to set up AWS Cloud9 here). Otherwise you might need to install the latest AWS CLI, AWS SAM and Python on your development machine.
Here is the list of AWS resources that the project template creates:
✔️ AWS Lambda
✔️ Amazon DynamoDB
✔️ Amazon API Gateway
✔️ AWS IAM
✔️ Amazon S3 (that is where your CloudFormation template will be stored)
Lambda functions are written on Python 3.8.
🎉 Create a new movie:
🎉 Get a list of all movies:
🎉 Get a movie by uuid:
🎉 Delete a movie by uuid:
🎉 Update an existing movie:
You can find all the details of the project by reading my articles on dev.to
:
👉 AWS project - Building a serverless microservice with Lambda (read)
👉 Serverless - Create, debug and deploy Lambda and API Gateway via AWS SAM and AWS Cloud9 (read)
To clone the GitHub repository, execute the following command:
cd my-folder
git clone https://github.com/Tiamatt/AwsServerlessMicroserviceWithLambda.git
If you want to migrating a repository from GitHub into AWS CodeCommit, read this article.
To build and deploy your application for the first time, run the following in your shell:
sam build --use-container
sam deploy --guided
To delete the sample application that you created, use the AWS CLI:
aws cloudformation delete-stack --stack-name aws-serverless-microservice-app-stack
Finally, don't forget to do your happy dance!