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-functiontype: aws-lambdaprovider: awsregion: us-east-1project: my-company
build: language: go version: "1.23"The CloudFormation stack is named after the service (my-function above).
Required Fields
| Field | Description |
|---|---|
name | Function name |
region | AWS region (e.g., us-east-1) |
project | Project name |
Function Configuration
Memory, timeout, runtime, and handler are not Pilum fields — they belong in
your SAM template.yaml (see below), which is the single source of truth for
function configuration. Pilum drives the build and deploy; SAM owns the function.
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 exactly two commands (verify anytime with --dry-run):
- build —
sam build - deploy —
Terminal window sam deploy --stack-name <service-name> --region <region> \--resolve-s3 --capabilities CAPABILITY_IAM \--no-confirm-changeset --no-fail-on-empty-changeset --no-progressbar \--tags pilum:service=<service-name> pilum:version=<tag>
There is no separate package step: sam deploy --resolve-s3 uploads build
artifacts to SAM’s managed S3 bucket itself. --no-fail-on-empty-changeset
makes redeploying an unchanged service a success rather than an error, and the
stack is tagged with the Pilum service name and version for traceability.
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