AWS Lambda
Deploy serverless functions to AWS Lambda using the AWS Serverless Application Model (SAM).
Prerequisites
- AWS CLI installed and configured
- AWS SAM CLI installed
- AWS credentials with Lambda permissions
# Install AWS CLIbrew install awscli
# Install SAM CLIbrew install aws-sam-cli
# Configure credentialsaws configureService Configuration
name: my-functionprovider: awsregion: us-east-1project: my-companystack_name: my-function-stack
build: language: go version: "1.23"Required Fields
| Field | Description |
|---|---|
name | Function name |
region | AWS region (e.g., us-east-1) |
project | Project name (used for S3 bucket naming) |
Optional Fields
| Field | Type | Default | Description |
|---|---|---|---|
stack_name | string | ${name}-stack | CloudFormation stack name |
memory_size | int | 128 | Lambda memory in MB |
timeout | int | 30 | Function timeout in seconds |
SAM Template
Pilum works with your existing SAM template. Create template.yaml:
AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31
Globals: Function: Timeout: 30 MemorySize: 128
Resources: MyFunction: Type: AWS::Serverless::Function Properties: FunctionName: my-function Handler: bootstrap Runtime: provided.al2 CodeUri: ./dist/ Architectures: - x86_64 Events: Api: Type: Api Properties: Path: / Method: ANYDeployment Steps
The AWS Lambda recipe executes:
- build —
sam build - package —
sam package --s3-bucket ... - deploy —
sam deploy --stack-name ...
Example Commands
# Deploy Lambda functionpilum deploy --tag=v1.0.0
# Build onlypilum build --tag=v1.0.0
# Preview commandspilum dry-run --tag=v1.0.0Environment Variables
Set Lambda environment variables in your SAM template:
Resources: MyFunction: Type: AWS::Serverless::Function Properties: Environment: Variables: LOG_LEVEL: info TABLE_NAME: !Ref MyTableSecrets
Use AWS Secrets Manager:
Resources: MyFunction: Type: AWS::Serverless::Function Properties: Environment: Variables: DATABASE_URL: '{{resolve:secretsmanager:my-db-secret:SecretString:url}}'Troubleshooting
Credentials Not Found
Unable to locate credentialsConfigure AWS:
aws configure# Or use environment variablesexport AWS_ACCESS_KEY_ID=...export AWS_SECRET_ACCESS_KEY=...export AWS_REGION=us-east-1S3 Bucket Access Denied
Ensure your project bucket exists:
aws s3 mb s3://my-company-deploymentsStack Update Failed
Check CloudFormation events:
aws cloudformation describe-stack-events --stack-name my-function-stackNext Steps
- Service Configuration — Full reference
- Creating Custom Recipes — Customize the workflow
- Troubleshooting — Common issues