A terraform set up for provisioning an AWS API Gateway, Lambda function, DynamoDB table and associated CloudWatch logs.
Disclaimer: While this may be suitable for prototyping, it should not be used for production without adding authentication on the API Gateway, and setting up backups for the DynamoDB table.
If not done already, an AWS profile needs to be configured on your device. You can do this via the AWS CLI (v2) - https://aws.amazon.com/cli/
Run aws configure
.
You will be prompted for your for your AWS Access Key and Secret Key.
You'll need the terraform cli to provision the infrastructure.
See https://www.terraform.io/ for installation details.
This terraform set will provision:
- A DynamoDB table named ProductCollections. This can be easily changed in the code.
- A Lambda function
- An AWS HTTP API Gateway
- CloudWatch log groups for API Gateway and Lambda.
- AWS role policies for invoking the lambda function and creating logs.
- cd into terraform/
- Zip the lambda function file -
zip -r lambda.zip index.js
- Run
terraform init
the first time. - Run
terraform plan
to do a dry run. - If satisfied, run
terraform apply
and follow the prompts.
Once complete you will be given the API URL in the command output.
Get all your items.
Get details of an item with the given id.
Create or Update items. To update an item, include {"id": "someId"} in the body.
ID's are not assigned to items by default in DynamoDB. The lambda function will assign a timestamp by default, so supplying an id is not required.
Delete an item with the given ID.