Skip to content

This repository contains Terraform configurations and AWS Lambda functions to create a simple URL shortener API using AWS API Gateway, AWS Lambda, and DynamoDB.

Notifications You must be signed in to change notification settings

omerap12/Serverless-url-shortener-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Serverless URL Shortener API

This repository contains Terraform configurations and AWS Lambda functions to create a simple URL shortener API using AWS API Gateway, AWS Lambda, and DynamoDB. The API allows users to create short URLs and retrieve the original full URLs associated with the short URLs. READ

Terraform Configurations

The Terraform configurations in this repository create the following AWS resources:

  • API Gateway: An API Gateway with HTTP protocol enabled. It has two routes:
  1. GET /read: Retrieves the original full URL associated with a short URL.
  2. POST /write: Creates a short URL associated with a full URL.
  • AWS Lambda Functions:
  1. read_lambda: Handles the GET /read route. It retrieves the full URL associated with a short URL from DynamoDB.
  2. write_lambda: Handles the POST /write route. It stores the short URL and full
  • URL mapping in DynamoDB. DynamoDB Table: A DynamoDB table named url-table to store the mappings between short URLs and full URLs.

Prerequisites

Before applying the Terraform configurations, make sure you have the following:

  • AWS account credentials configured.
  • Terraform installed on your local machine.

Deployment

  1. Clone this repository:
  git clone https://github.com/omerap12/Serverless-url-shortener-api.git
  cd Serverless-url-shortener-api
  1. Initialize Terraform and apply the configurations:
terraform init
terraform apply
  1. After applying the Terraform configurations, the API Gateway endpoint URLs for read and write operations will be provided as outputs. You can find them in the Terraform output variables.

Usage Examples

Add Short URL

To add a short URL, use the following curl command:

curl -X POST -d '{"full_url":"test.com","short_url":"test"}' -H "Content-Type: application/json" -i $api_url_write

Get Full URL

To get a Full URL from a short URL, use the following curl command:

curl -X GET -d '{"short_url":"test"}' -H "Content-Type: application/json" -i $api_url_read

Lambda Functions

read_lambda Function

The read_lambda function handles the GET /read route. It takes a short URL as input, retrieves the corresponding full URL from DynamoDB, and returns the full URL in the response.

write_lambda Function

The write_lambda function handles the POST /write route. It takes a JSON payload containing a short URL and a full URL, stores the mapping in DynamoDB, and returns a success message in the response.

Cleanup

To destroy the resources created by Terraform, run:

terraform destroy

About

This repository contains Terraform configurations and AWS Lambda functions to create a simple URL shortener API using AWS API Gateway, AWS Lambda, and DynamoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published