1. Introduction
AWS Lambda is a serverless compute solution that allows you to run code without the need for server provisioning or management. You only pay for the compute time you use. This indicates that my own project, which will not receive a lot of traffic, is a great choice for AWS Lambda. This use case is ideal for applications with variable traffic or that can scale to zero.
2. Prerequisites
IAM Role/IAM User with the enough permissions.
AWS CLI installed
Python3
AWS CLI
GIT
3. AWS Resources
You'll need the AWS resources listed below.
AWS IAM Role
AWS Lambda
AWS API Gateway
AWS DynamoDB
4. Architecture
You can create the resources manually using the AWS Console, or you can leverage this using any IAC options like Terraform, AWS SAM/CloudFormation. In this Article you will use the AWS Console to things easier
5. Deployment Steps
Step -1 - Create a role (name it as you wish and add permissions)
Step -2 - Create a lambda function (name it as you wish, chose the latest python version as runtime)
Python codes can be found here:
git clone https://github.com/Assassin010/CRUD-Serverless-API-Python-G.git
git clone https://Assassin10@bitbucket.org/assassin10/crud-serverless-api-python-b.git
git clone https://gitlab.com/Assassin010/CRUD-Serverless-API-Python-L.git
Step -3 - Build the REST API
Create 3 resources
health with path /health
product path /product
products path /products
Step -4
Create Methods for each resources
On health resource, create "GET" method
On product resource, create "GET", "POST", "PATCH" and
"DELETE"On products resource, create "GET"
check all boxes as followed for all Methods on each resource and chose your created lambda (Step -2)
Step -5 Deploy the API
Step -6 Create DynamoDB Table
6. TEST ALL APIs
POST: For a single product
{
"productId": "bag",
"color": "black",
"price": "100",
"quantity": "1500"
}
GET: For a single product
PATCH: For a single product
DELETE: For a single product
GET multiple products:
Notes: You will need POST few products before trying to GET all of them.
7. References
https://aws.amazon.com/lambda/
https://aws.amazon.com/api-gateway/
https://aws.amazon.com/dynamodb/
https://aws.amazon.com/cloudwatch/
https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
Happy coding!
END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like my work and want to support me…
The BEST way is following me on dev.to here
Feel free to give likes, or writing comments so I know how helpful this post was for you.
Gauthier Kwatatshey__
Connect with me on LinkdIn
Top comments (0)