Deploying to AWS Lambda
Deploy your Yama application to AWS Lambda for serverless functions.
Prerequisites
- AWS account
- AWS CLI configured
- Serverless Framework or AWS SAM
Serverless Framework
Installation
npm install -g serverlessConfiguration
Create serverless.yml:
service: my-yama-app
provider:
name: aws
runtime: nodejs20.x
region: us-east-1
environment:
DATABASE_URL: ${env:DATABASE_URL}
JWT_SECRET: ${env:JWT_SECRET}
functions:
api:
handler: dist/server.handler
events:
- http:
path: /{proxy+}
method: ANY
timeout: 30
memorySize: 512Deploy
serverless deployAWS SAM
Template
Create template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
YamaApi:
Type: AWS::Serverless::Function
Properties:
Handler: dist/server.handler
Runtime: nodejs20.x
CodeUri: .
Events:
ApiEvent:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
Environment:
Variables:
DATABASE_URL: !Ref DatabaseUrl
JWT_SECRET: !Ref JwtSecretDeploy
sam build
sam deploy --guidedLambda Layers
Use Lambda layers for dependencies:
layers:
nodeModules:
path: layer
compatibleRuntimes:
- nodejs20.xEnvironment Variables
Set via AWS Console or CLI:
aws lambda update-function-configuration \
--function-name my-yama-app \
--environment Variables="{DATABASE_URL=...,JWT_SECRET=...}"API Gateway
Yama works with API Gateway:
- Automatic routing
- Request/response transformation
- CORS configuration
Database Connection
For Lambda, use connection pooling:
// Use RDS Proxy or connection pooling
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 1, // Lambda-specific: reuse connections
});Cold Starts
Optimize cold starts:
- Use provisioned concurrency
- Minimize dependencies
- Use Lambda layers for shared code
Monitoring
Monitor with CloudWatch:
- Function logs
- Execution metrics
- Error tracking
Next Steps
- Learn about Docker deployment
- See Environment Variables guide
Last updated on