Adding Numbers with API Gateway, Lambda and DynamoDB

This is a small project that shows how to use the API Gateway to simply add two numbers together. The entered numbers are added together using a Lambda function and the numbers, and sum are added to a DynamoDB table.

I have created a CloudFormation template that can be found in my GitLab repo.

Creating the Template

The easiest and quickest way to test is to copy the template, save the CloudFormation template locally, and then upload the file to the CloudFormation service.

The default region to run this is eu-west-2, however this can be modified.

Once the template has finished creating all the resources, there will be a URL for the API gateway in the Outputs tab of the CloudFormation stack. This is the API gateway public URL that can be used to GET all the numbers in the DynamoDB table or to send a POST request to have the two numbers created.

Testing

Now that all the resources have been created, the first method can be tested. I will test the GET method that will get all the sums that have been added to the table. As it has just been setup, there is nothing but an empty list to return, which is the output below.

Sending a POST request to add two numbers together will add the sum to the DynamoDB table, and then another GET request can be made to see sums that have been made.

After adding some more numbers, there is more data in the table.

Leave a Comment

Your email address will not be published. Required fields are marked *