This project will guide you through building and deploying a serverless API using AWS Lambda and DynamoDB, integrated with GitHub Actions and Terraform . The primary goal is to construct an API that serves resume data in JSON format and make it accessible on the internet using API Gateway .
curl https://lpn6ekqu21.execute-api.us-east-1.amazonaws.com/prod/resumeThis project automates the deployment of an AWS Lambda function using Terraform and GitHub Actions. The Lambda function serves as the backend for a resume API, providing endpoints to fetch resume details stored in a dynamoDB table .
The architecture involves:
- AWS Lambda: Runs the backend code for the API.
- AWS API Gateway: Provides a RESTful API endpoint.
- DynamoDB: Stores the json resume data.
- Terraform: Manages the infrastructure as code.
- GitHub Actions: Automates the CI/CD pipeline.
Before you begin, ensure you have met the following requirements:
- An AWS account with necessary permissions.
- Terraform installed.
- AWS CLI configured with your credentials.
- A GitHub account with access to the repository.
AWS-CLOUD-RESUME-API/
├── .github/
│ └── workflows/
│ └── deploy.yml
├── src/
│ ├── lambda_function.py
│ └── lambda_function.zip
├── .gitignore
├── main.tf
├── provider.tf
├── README.md
├── requirements.txt
└── resume.json
- Sign Up for AWS: If you don't already have an AWS account, sign up at aws.amazon.com.
- Set Up Credentials: Configure your AWS CLI with your credentials using
aws configure.
- Create a JSON file containing your resume data. Follow a schema Here
- Store this JSON file for later use.
- Table Name: Resumes
- Primary Key:
id(String) - Populate the table with your resume data using the AWS Management Console, AWS CLI, or a script.
- Create a Python script (
lambda_function.py) to fetch resume data from DynamoDB and return it in JSON format.
- Zip the
lambda_function.pyfile.
- Create
main.tfandprovider.tffor infrastructure as code as a way to automatically create the lambda function and the API Gateway configurations .
- Create an S3 bucket in the AWS console or the AWS CLI with the same name as the one used in
provider.tffile .
- Initialize Terraform:
terraform init
- Plan the Deployment:
terraform plan
- Apply Deployment:
terraform apply
- After the deployement an api endpoint url is going to be generated , keep it for the test after .
- Create a GitHub Actions workflow (
.github/workflows/deploy.yml) to automatically deploy updates to your Lambda function on every push to the repository.
- API Gateway URL: Test your endpoint to ensure it returns the resume data in JSON format (the one generated after executing the terraform setup) using
curl. - GitHub Actions: Make a change to your code, push to the repository, and verify that the GitHub Actions workflow deploys the updated Lambda function.
- For a detailed step by step guide to build this project , follow the steps in this blog
