Serverless Functions
Deploy serverless APIs and backend functions on AWS Lambda with modern web frameworks like Express.js, Hono, NestJS, and Fastify.
Thunder provides the @thunderso/cdk-functions package for deploying Lambda functions with API Gateway, supporting both standard zip deployments and container images for custom runtimes.
Supported Frameworks
Serverless API Architecture
The serverless architecture provides scalable, event-driven compute for APIs without managing servers.
Route 53 handles DNS resolution for custom domains. API Gateway manages HTTP requests, authentication, and routing. Lambda executes serverless functions with automatic scaling and pay-per-request pricing.
Zip Deployment Pipeline
The zip deployment pipeline packages and deploys lightweight Lambda functions for standard use cases.
GitHub triggers deployments on code changes. CodePipeline orchestrates the workflow while CodeBuild packages the function code into a zip file and deploys directly to Lambda.
Container Deployment Pipeline
The container deployment pipeline builds custom runtime environments for advanced use cases and larger dependencies.
GitHub triggers deployments. CodeBuild builds Docker images with custom runtimes, pushes to ECR, then deploys container images to Lambda for advanced use cases requiring custom dependencies or alternative runtimes like Bun.
Quick Start
Get your serverless API deployed to AWS Lambda in minutes. This guide covers installation, basic configuration, and deployment.
Installation
bun add -D tsx @thunderso/cdk-functionsBasic Setup
mkdir stack && touch stack/index.tsConfiguration
import { Cdk, FunctionStack, type FunctionProps } from '@thunderso/cdk-functions';
const fnProps: FunctionProps = { env: { account: 'your-account-id', region: 'us-east-1', }, application: 'my-api', service: 'backend', environment: 'production', functionProps: { codeDir: 'dist/', handler: 'index.handler', },};
new FunctionStack( new Cdk.App(), `${fnProps.application}-${fnProps.service}-${fnProps.environment}-stack`, fnProps);Deploy
bunx cdk deploy --all --app="bunx tsx stack/index.ts"Custom Domain Setup
Connect your API to a custom domain using Route 53 and ACM certificates. The certificate must be issued in the same region as your Lambda function.
const fnProps: FunctionProps = { // ... other props domain: 'api.example.com', hostedZoneId: 'Z1D633PJN98FT9', regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abcd1234-abcd-1234-abcd-1234abcd1234',};Advanced Configuration
Lambda Settings
Fine-tune your function’s performance with runtime selection, memory allocation, timeout configuration, and ARM64 architecture support for better price-performance.
import { Runtime, Architecture } from 'aws-cdk-lib/aws-lambda';
const fnProps: FunctionProps = { // ... other props functionProps: { runtime: Runtime.NODEJS_20_X, architecture: Architecture.ARM_64, memorySize: 1792, timeout: 10, tracing: true, keepWarm: true, },};Environment Variables
Manage configuration with plain environment variables and secure secrets from AWS Secrets Manager. The library automatically grants Lambda permissions to read specified secrets.
const fnProps: FunctionProps = { // ... other props functionProps: { variables: [ { API_URL: 'https://api.example.com' }, { NODE_ENV: 'production' } ], secrets: [ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:db-url-abc123' } ], }};Container Deployments
Deploy Lambda functions as container images to use custom runtimes, package large dependencies, or run alternative runtimes like Bun. Container images support up to 10GB compared to the 250MB zip limit.
Node.js Container
Use the official AWS Lambda Node.js base image for standard Node.js deployments with custom dependencies or build processes.
FROM public.ecr.aws/lambda/nodejs:22 AS baseWORKDIR ${LAMBDA_TASK_ROOT}
COPY . .RUN bun install --productionRUN bun run build
FROM public.ecr.aws/lambda/nodejs:22WORKDIR ${LAMBDA_TASK_ROOT}
COPY --from=base /var/task/dist/* ./COPY --from=base /var/task/node_modules node_modules
CMD [ "index.handler" ]const fnProps: FunctionProps = { // ... other props functionProps: { dockerFile: 'Dockerfile.node', },};Bun Runtime Container
Deploy Lambda functions using the Bun runtime for faster cold starts and improved performance. Requires a fetch-compatible handler that matches the Fetch API standard.
FROM oven/bun:latest AS baseWORKDIR /tmp
COPY . .RUN bun installRUN bun run build
FROM public.ecr.aws/lambda/provided:al2023WORKDIR ${LAMBDA_TASK_ROOT}
COPY --from=base /tmp/dist/* ./COPY --from=base /tmp/node_modules node_modules
CMD [ "lambda-bun.fetch" ]const fnProps: FunctionProps = { // ... other props functionProps: { dockerFile: 'Dockerfile.bun', },};