1.0.0 • Published 9 months ago
@rasensio/aws-lambda-koa v1.0.0
AWS Lambda Koa
A lightweight and flexible AWS Lambda framework built on top of Koa.js with TypeScript support.
Features
- Built on Koa.js with full TypeScript support
- AWS Lambda integration using serverless-http
- Configurable middleware system
- Built-in support for:
- CORS
- Rate limiting
- Logging (JSON/Text formats)
- AWS CloudWatch metrics
- Authentication (JWT/AWS Cognito)
- Health check endpoint
- Request body validation
- Error handling
Installation
npm install @rasensio/aws-lambda-koaQuick Start
import { createLambdaServer } from '@rasensio/aws-lambda-koa';
import Router from '@koa/router';
// Create your routes
const router = new Router();
router.get('/hello', (ctx) => {
ctx.body = { message: 'Hello World!' };
});
// Initialize the server
const server = createLambdaServer();
server.init({
routes: [{ router, prefix: '/api' }]
});
// Export the handler
export const handler = server.getHandler();Configuration
server.init({
routes: [{ router, prefix: '/api', auth: true }],
cors: {
origins: ['http://localhost:3000'],
credentials: true
},
rateLimit: {
windowMs: 15 * 60 * 1000, // 15 minutes
maxRequests: 100
},
logging: {
level: 'info',
format: 'json'
},
metrics: {
namespace: 'MyApp',
enabled: true
},
auth: {
jwtSecret: 'your-secret',
// or
cognitoUserPoolId: 'your-pool-id',
cognitoClientId: 'your-client-id'
}
});Requirements
- Node.js >= 14
- TypeScript >= 4.5
- AWS Lambda environment
License
ISC
Author
Rodrigo Asensio - @rasensio
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Links
1.0.0
9 months ago