A serverless HTTP proxy service built with AWS CDK that provides a scalable, secure middleware layer for API routing and request processing. This application creates a Lambda-backed API Gateway that can route requests to different handler modules dynamically. If you find this stack useful you might like to try our fully authenticated, globally distributed API Authentication proxy over at https://requestrocket.com. Early access registrations are available by https://app.requestrocket.com/
This application consists of:
- AWS Lambda Function: Node.js 18.x runtime with Express.js handling HTTP requests
- API Gateway: RESTful API with proxy integration and CORS support
- AWS CDK: Infrastructure as Code for deployment and management
- TypeScript: Strongly typed development with build process
- π Dynamic Module Loading: Routes requests to different handlers based on endpoint paths
- π CORS Enabled: Cross-origin request support with configurable policies
- π Request Logging: Comprehensive request/response logging for debugging
- π Header Sanitization: Automatic filtering of sensitive headers
- π Multi-format Support: Handles JSON, binary data, and various media types
- π Serverless: Auto-scaling with pay-per-use pricing model
- Node.js 18.x or higher
- Yarn package manager
- AWS CLI configured with appropriate permissions
- AWS CDK CLI installed globally
serverless-proxy/
βββ src/
β βββ app.ts # CDK app entry point
β βββ cdk_stack.ts # Main CDK stack definition
β βββ lambda_api/ # Lambda function source
β β βββ application.ts # Express.js application setup
β β βββ service.ts # Lambda handler entry point
β β βββ application/ # Route handlers
β β β βββ proxy.ts # Proxy endpoint handlers
β β βββ utilities/ # Shared interfaces and utilities
β βββ stack/ # CDK infrastructure modules
βββ .github/workflows/ # CI/CD pipeline definitions
-
Install all dependencies:
yarn installall
-
Build the project:
yarn buildall
The application uses a modular architecture where each endpoint corresponds to a module in the application/ directory.
- Create a new TypeScript file in
src/lambda_api/application/ - Export
get,post, and/ordelfunctions as needed - Each function should return an
expressResponseTypeobject
Example endpoint handler:
import { expressResponseType } from "../utilities/interfaces";
export async function get(request: any) {
const response: expressResponseType = {
status: 200,
message: "Success",
data: { result: "Your data here" },
};
return response;
}
export async function post(request: any) {
// Handle POST requests
// Access request.body, request.params, request.query
}Requests to /proxy/:path are automatically routed to the corresponding module:
/proxy/myendpointβapplication/myendpoint.ts- HTTP methods are mapped to exported functions (
get,post,del)
# Run tests for the main project
yarn test
# Run tests for the Lambda API
yarn --cwd src/lambda_api testThe Lambda function has access to these environment variables:
RESOURCEREGION: AWS region where resources are deployedSTAGE: Deployment stage (dev/qas/prod)MANAGEMENTAPIKEY: Management API key for secure operations
The project uses GitHub Actions for CI/CD:
-
Development: Push to any branch
git push origin feature/my-feature
-
Quality Assurance: Push to
qasbranchgit push origin qas
-
Production: Push to
mainbranchgit push origin main
For local deployment or testing:
# Deploy to development environment
cdk deploy --profile your-aws-profile
# Deploy with specific parameters
cdk deploy -c stage=dev -c region=us-east-1- PR Checks: Automated build and CDK synth on pull requests to main
- Auto Deploy: Deployment triggered on merge to main/qas/prod branches
- Required Secrets:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
Configure deployment settings in cdk.json or via command line:
stage: Deployment environment (dev/qas/prod)region: AWS region for deploymentmanagementApiKey: API key for management operations
CORS is configured to allow all origins by default. Modify in src/lambda_api/application.ts:
const corsOptions = {
origin: function (origin: string | undefined, callback: Function) {
// Add your origin validation logic here
callback(null, true);
},
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
};All requests are automatically logged with:
- Request method and URL
- Headers, body, query parameters
- Response status and timing
Monitor your application through:
- Lambda function logs
- API Gateway access logs
- CloudWatch metrics and alarms
- Headers are automatically sanitized to remove sensitive AWS-specific headers
- CORS policies can be customized for production environments
- API Gateway provides built-in DDoS protection and throttling
| Command | Description |
|---|---|
yarn installall |
Install dependencies for all packages |
yarn buildall |
Build all TypeScript projects |
yarn test |
Run tests for the main project |
yarn build |
Build only the CDK project |
yarn build_lambda_api |
Build only the Lambda API |
After deployment, your API will be available at:
https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/
GET /proxy/{endpoint}- Route to corresponding handler modulePOST /proxy/{endpoint}- Route to corresponding handler moduleDELETE /proxy/{endpoint}- Route to corresponding handler module
All responses follow the expressResponseType interface:
{
status: number;
message?: string;
data?: any;
headers?: any;
type?: string;
cache?: string;
}- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
RequestRocket is a universal API proxy platform that simplifies authentication and makes API integration faster, easier, and more secure.
Built for developers, data engineers, and business intelligence teams, RequestRocket transforms the way systems connect by abstracting away the complexity of API authentication protocols β from API Keys and OAuth2 to JWT and custom tokens.
With a global serverless infrastructure, RequestRocket offers low-latency, high-availability API endpoints that handle retries, caching, telemetry, and even AI-driven just-in-time prefetching. Itβs secure, scalable, and ready to plug into your stack β no matter how large or complex.
Whether you're building a new SaaS product, integrating with dozens of enterprise APIs, or trying to securely connect business tools like Power BI to third-party data, RequestRocket is your authentication translation layer. Spend less time debugging tokens and more time building the things that matter.
For Developers: Start Building Without the Headaches Join developers around the world using RequestRocket to simplify their API stack, reduce integration time, and ship faster. Create your free account and start building today.
π Sign up now at https://app.requestrocket.com β Itβs free to get started.