A simple URL shortener built using AWS Lambda, API Gateway, and Serverless Framework with Node.js. The API allows creating short URLs, managing expiration times, and supports both GET and POST HTTP methods for the shortened URLs.
-
Install Dependencies:
- Make sure Node.js (v16 or higher) and pnpm are installed.
- Run the following commands to install dependencies:
pnpm install -
Configure Serverless:
- Update the
serverless.ymlwith your AWS region and custom domain. - Ensure your AWS credentials are configured (via environment variables, AWS CLI, etc.).
- Update the
-
Test Locally with
serverless dev:- You can test your Lambda function locally before deployment using the following command:
serverless devThis will start the application locally and simulate the API Gateway and Lambda functions for easier local testing.
-
Deploy:
- Deploy the service using Serverless Framework:
serverless deploy -
Test the Deployed API:
- Once deployed, test the API endpoints using
Postmanorcurl. - The custom domain for the API is: https://api.stra1g.one/.
- Once deployed, test the API endpoints using
- Short URL creation with custom TTL.
- Expiration check for each short URL.
- Supports both GET and POST methods for shortened URLs.
- Redirects for
GETrequests and POST forwarding forPOSTrequests.
- Serverless Framework for easy deployment and management of Lambda functions.
- AWS Lambda for serverless function execution.
- API Gateway to expose the Lambda functions as HTTP endpoints.
- AWS DynamoDB to store the short URL data.
- Route 53: Add a CNAME record that points to the API Gateway URL (e.g.,
your-api-id.execute-api.us-east-1.amazonaws.com). - ACM (AWS Certificate Manager): Issue an SSL certificate for the custom domain (e.g.,
api.stra1g.one). - API Gateway: Map the custom domain (
api.stra1g.one) to the API. - Deploy the changes in API Gateway and Route 53.
Made by @stra1g 🖤