Skip to content

AWS Lambda

Deploy serverless functions to AWS Lambda using the AWS Serverless Application Model (SAM).

Prerequisites

  1. AWS CLI installed and configured
  2. AWS SAM CLI installed
  3. AWS credentials with Lambda permissions
Terminal window
# Install AWS CLI
brew install awscli
# Install SAM CLI
brew install aws-sam-cli
# Configure credentials
aws configure

Service Configuration

name: my-function
provider: aws
region: us-east-1
project: my-company
stack_name: my-function-stack
build:
language: go
version: "1.23"

Required Fields

FieldDescription
nameFunction name
regionAWS region (e.g., us-east-1)
projectProject name (used for S3 bucket naming)

Optional Fields

FieldTypeDefaultDescription
stack_namestring${name}-stackCloudFormation stack name
memory_sizeint128Lambda memory in MB
timeoutint30Function 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: ANY

Deployment Steps

The AWS Lambda recipe executes:

  1. buildsam build
  2. packagesam package --s3-bucket ...
  3. deploysam deploy --stack-name ...

Example Commands

Terminal window
# Deploy Lambda function
pilum deploy --tag=v1.0.0
# Build only
pilum build --tag=v1.0.0
# Preview commands
pilum dry-run --tag=v1.0.0

Environment Variables

Set Lambda environment variables in your SAM template:

Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
LOG_LEVEL: info
TABLE_NAME: !Ref MyTable

Secrets

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 credentials

Configure AWS:

Terminal window
aws configure
# Or use environment variables
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_REGION=us-east-1

S3 Bucket Access Denied

Ensure your project bucket exists:

Terminal window
aws s3 mb s3://my-company-deployments

Stack Update Failed

Check CloudFormation events:

Terminal window
aws cloudformation describe-stack-events --stack-name my-function-stack

Next Steps