DEV Community

Cover image for Serverless Resume API with Terraform and GitHub Actions
Gbenga Ojo-Samuel
Gbenga Ojo-Samuel

Posted on

Serverless Resume API with Terraform and GitHub Actions

Introduction

In today's world, building applications that automatically adjust to changing demands is crucial. A unique way to showcase this is by deploying your resume in JSON format using serverless AWS services. This guide will walk you through deploying your JSON resume data with Terraform, leveraging AWS Lambda, DynamoDB, and API Gateway. This setup ensures your resume is always available, scales seamlessly, and can be accessed through a user-friendly API.
Before we begin, ensure you have the following:

  1. AWS Account: An active AWS account with the necessary permissions.
  2. Terraform: Installed on your local machine.
  3. AWS CLI: Installed and configured on your local machine.

Step 1: Define Your JSON Resume Data
Create your resume in JSON format. You can use a JSON schema from the link below:
https://jsonresume.org/schema

Step 2: Define Your Lambda function
We will be creating a python code that our lambda function will use to retrieve the resume data from DynamoDB. See complete code in the repository.

Image description

Step 3: Create Terraform Configuration
Create a new directory for your Terraform configuration files. Inside this directory, we will create a sub-directory for our modules. Each folder in the modules directory will contain the infrastructures required to be deployed for each AWS service. See below.

Image description

  • Api Gateway module: This describes the detailed terraform configuration for our Api Gateway.

Image description

  • DynamoDB Module: This module contains the terraform codes for deploying DynamoDB and also uploading the resume JSON data on it.

Image description

  • Iam_Role Module: This module contains the terraform codes that defines the necessary permissions for lambda function to access DynamoDB and CloudWatch.

Image description

  • Lambda Module: This module defines the terraform codes for archiving the python code in a zip file and also create a lambda function from same.

Image description

The full terraform configuration codes can be found in the repository below:
https://github.com/Samuel7050/AWS_RESUME_CHALLENGE.git

Step 3: Test your codes locally
Run terraform init to initialize the terraform plugins and providers

Image description

Run terraform validate to validate the terraform codes

Image description

Run terraform plan to preview the infrastructures to be deployed. Also note that the Zip file for the lambda function will also be created in the project directory.

Image description

Run terraform apply --auto-approve to deploy the infrastructure on AWS.

Image description

Copy the** api_gateway_invoke_url** as indicated in the output above and run a test locally from VScode . Ensure you include **/path_part **of the api gateway. See below

https://susia7qsb6.execute-api.us-east-1.amazonaws.com/dev/data

Image description

Paste on a web browser

Image description

To clean up locally, run terraform destroy --auto-approve

Image description

Step 4: Configure GitHub Actions
To automate the deployment process using GitHub Actions, create a .github/workflows directory in your project root directory and add a file named deploy.yml

Image description

Step 5: Configure GitHub Secrets
In your GitHub repository, navigate to Settings > Secrets and variables and add the following secrets and variable, as shown below:

Image description

Image description

Whenever there is a push action on the main branch or a pull request to the main branch, the GitHub action is automatically triggered. See result of a push action to the main branch of the repository.

The PR from my feature branch to main branch failed as seen below

Image description

The workflow failed because of already existing policy as seen in the error code below

Image description

Lets fix the error and do another PR the to main branch again to trigger the workflow

Image description

Image description

Image description

Image description

Image description

Image description

To verify, copy the api_gateway_invoke_url/data as shown below and run on your browser. Note that /data is my api gateway path_part

https://sx60706aef.execute-api.us-east-1.amazonaws.com/dev/data

Image description

Conclusion
By following these steps, you've deployed your resume in JSON format using AWS Lambda, DynamoDB, API Gateway, and automated the process using GitHub Actions. This setup ensures your resume is highly available, scalable, and easily accessible via a REST API, with the added benefit of continuous integration and deployment. You can now share your resume API endpoint with potential employers or integrate it into your personal website.

Top comments (2)

Collapse
 
rishabk7 profile image
Rishab Kumar

Great work @gbenga700
thank you for participating in the Cloud Resume API Challenge.

Collapse
 
gbenga700 profile image
Gbenga Ojo-Samuel

Thanks@rishabk7
You are truly an inspiration in the cloud space