This guide walks through creating a serverless web application using AWS Lambda, API Gateway, and DynamoDB.
- AWS Account
- Basic knowledge of AWS services
- Python (for the Lambda function)
- Go to the DynamoDB console.
- Create a new table with the following configuration:
- Primary/Partition Key:
Email
- Primary/Partition Key:
- Navigate to the IAM console and create a new role for Lambda with the least-privilege model.
- Attach the following permissions:
- DynamoDB Access (to allow the Lambda function to interact with the table)
- CloudWatch Logs Access (to monitor logs)
- In the Lambda console, create a new function.
- Select Python as the runtime.
- Assign the IAM role created in the previous step to the Lambda function.
- Go to the API Gateway console.
- Create a new API.
- Add a Resource to serve as the endpoint for incoming requests.
- For the resource, create a POST method.
- Select the integration type and link it to the Lambda function.
- Click Save.
- Enable CORS on the resource:
- Select the resource.
- Enable CORS with default options.
- Click Deploy API.
- Create a new stage (e.g.,
dev,prod). - Note the Invoke URL generated after deployment.
- Open your
script.jsfile. - Update the
API_URLwith the Invoke URL from API Gateway. - Open
index.htmland fill out the form.
- Submit the form and check the DynamoDB table to see if the data is saved.
- If the data isn’t saving, review your configurations and ensure all steps are completed correctly.
project-folder/
│-- Frondend/index.html
│-- Frondend/script.js
│-- Lambda/lambda_function.py
Credit: https://github.com/yeshwanthlm
- Ensure CORS is enabled for API Gateway to allow cross-origin requests.
- Use CloudWatch Logs for debugging any issues with the Lambda function.