This project is a serverless URL Shortener built using AWS Lambda, Amazon API Gateway, Amazon DynamoDB, and TypeScript. It allows users to generate short URLs for long URLs and handle redirections efficiently.
- Generate short URLs for long links
- Redirect users from short URLs to original URLs
- Store mappings in DynamoDB with shortCode as the primary key
- Implement error handling for invalid requests
- Deployed using AWS Serverless Application Model (SAM)
- Uses AWS SDK v3 for DynamoDB interactions
- AWS Lambda (Node.js 22.x)
- Amazon API Gateway
- Amazon DynamoDB (On-Demand Billing Mode)
- TypeScript
- AWS SDK v3
- AWS SAM (for deployment)
- Thunder Client (for API testing)
Before running the project, ensure you have the following:
- Node.js installed
- AWS Account with programmatic access configured
- AWS CLI installed and configured
- AWS SAM CLI installed for deployment
| Attribute Name | Type |
|---|---|
| shortCode | String |
| url | String |
├── hello-world
│ ├── app.ts # Lambda function handler
│ ├── package.json # Dependencies
│ ├── tsconfig.json # TypeScript Configuration
│ └── node_modules # Installed packages (after npm install)
├── template.yaml # AWS SAM template defining resources
└── README.md # Project documentation
git clone https://github.com/AbhijeetAayush/Url-Shortener-AWS.git
cd Url-Shortener-AWSnpm install-
Build the application:
sam build
-
Deploy using AWS SAM CLI:
sam deploy --guided
Follow the prompts to configure your deployment settings.
- Endpoint:
POST /shorten
- Request Body:
{ "url": "https://example.com" } - Response:
{ "shortUrl": "https://{api-gateway-url}/Prod/abc123" }
- Endpoint:
GET /{shortCode}
- Behavior: Redirects to the original URL stored in DynamoDB.
- Install the Thunder Client extension.
- Send a POST request to
/shortenwith a JSON body containing aurl. - Use the returned short URL in a GET request to test redirection.
| Status Code | Message |
|---|---|
| 400 | Missing request body |
| 400 | Missing URL |
| 400 | ShortCode is required |
| 404 | Short URL not found |
| 500 | Internal Server Error |
| Name | Description |
|---|---|
| TABLE_NAME | DynamoDB table name storing URLs |
- CloudWatch Logs: View execution logs in AWS CloudWatch for debugging.
- SAM Logs: Run the following to fetch logs locally:
sam logs -n HelloWorldFunction --tail
The AWS Serverless Application Model (SAM) template defines the infrastructure:
- AWS Lambda Function (
hello-world/app.tsas handler) - API Gateway Endpoints (
/shortenfor POST,/{shortCode}for GET) - DynamoDB Table (
ShortenedURLswithshortCodeas primary key) - IAM Policies for Lambda to interact with DynamoDB
This project is licensed under the MIT License.