This is a sample serverless microservice built using Amazon API Gateway, AWS Lambda, and Amazon DynamoDB, all provisioned and managed using Terraform.
The microservice consists of the following components:
- API Gateway: Handles incoming HTTP requests and routes them to the appropriate Lambda function.
- Lambda Functions: Serverless compute functions that implement the business logic of the microservice.
- DynamoDB: A NoSQL database used to store and retrieve data for the microservice.
- CRUD Operations: The microservice supports create, read, update, and delete operations for a specific resource.
- Terraform
- AWS CLI
To use this microservice, follow these steps:
- Deploy the Infrastructure: Use the provided Terraform configuration to deploy the necessary AWS resources.
- Interact with the API: Make HTTP requests to the API Gateway endpoint to interact with the microservice.
- Initialize Terraform:
terraform init
- Plan the Infrastructure:
terraform plan -out=tfplan
- Apply the Infrastructure:
terraform apply tfplan
- Destroy the Infrastructure:
terraform destroy
POST /
: Create a new itemPUT /
: Update an existing itemGET /
: Retrieve all itemsGET /{id}
: Retrieve an item by IDDELETE /{id}
: Delete an item
Note: Terraform will provide API endpoint as output in api_endpoint
.
Create Item
POST /
Content-Type: application/json
{
"name": "Example Item",
"description": "This is an example item.",
"price": 9.99
}
Update Item
PUT /
Content-Type: application/json
{
"id": "c0000000-0000-0000-0000-000000000ffe",
"name": "Update Example Item",
"description": "This is an example item.",
"price": 9.99
}
Retrieve All Items
GET /
[
{
"id": "c0000000-0000-0000-0000-000000000ffe"
"name": "Example Item",
"description": "This is an example item.",
"price": 9.99
},
{
"id": "c0000000-0000-0000-0000-000000000fff"
"name": "Example Another Item",
"description": "This is an another example item.",
"price": 99.99
}
]
Retrieve Item
GET /c0000000-0000-0000-0000-000000000ffe
{
"id": "c0000000-0000-0000-0000-000000000ffe"
"name": "Example Item",
"description": "This is an example item.",
"price": 9.99
}
DELETE Item
DELETE /c0000000-0000-0000-0000-000000000ffe