Lambda Deployment Quick Start

This is a quick reference guide for deploying Lambda functions in three different invocation modes. For comprehensive details, see index.md.

Table of Contents


Setup

Prerequisites

# Install dependencies
npm install

# Build Lambda bundles
npm run build

# Configure AWS credentials
aws configure

Deploy All Functions

# Deploy all three functions to the dev stage
npm run serverless:deploy

# Deploy to production
npm run serverless:deploy -- --stage prod

# Deploy to custom region
npm run serverless:deploy -- --region ap-southeast-1

API Gateway (HTTP/REST)

When to use: Expose Lambda as HTTP endpoints (REST API)

Configuration

Function: helloApi

Handler: lib/index.min.helloHandler

Routes: GET /hello and GET /hello/{name}

Deploy

# Deploy only this function (after initial deployment)
npm run serverless:deploy:function -- --function helloApi

# View API endpoint
npm run serverless:print | grep https

Test Locally

npm run serverless:invoke:local:api

Uses events/hello.apigw.json as the test payload.

Invoke After Deployment

Using curl

# Default name (world)
curl https://xxxxx.execute-api.ap-southeast-1.amazonaws.com/hello

# With path parameter
curl https://xxxxx.execute-api.ap-southeast-1.amazonaws.com/hello/Bayu

# With query parameter
curl "https://xxxxx.execute-api.ap-southeast-1.amazonaws.com/hello?name=Bayu"

Using AWS CLI

aws lambda invoke \
  --function-name aws-lambda-boilerplate-dev-helloApi \
  --payload '{"version":"2.0","routeKey":"GET /hello"}' \
  --region ap-southeast-1 \
  response.json

cat response.json

Using AWS Console

  1. Go to API Gateway → Select aws-lambda-boilerplate-dev
  2. Click DeploymentsStages$default
  3. Copy the Invoke URL and append /hello or /hello/{name}

Response Example

{
  "statusCode": 200,
  "headers": {
    "content-type": "application/json"
  },
  "body": "{\"message\":\"Hello, Bayu!\",\"requestId\":\"xxx\",\"timestamp\":\"2026-05-12T09:13:52Z\",\"input\":{\"name\":\"Bayu\",\"source\":\"query\"}}"
}

Direct Invocation

When to use: Invoke Lambda directly via AWS Lambda API (no HTTP trigger)

Configuration

Function: helloInvoke

Handler: lib/index.min.directHelloHandler

Payload format: { "name": "Bayu" }

Deploy

# Deploy only this function (after initial deployment)
npm run serverless:deploy:function -- --function helloInvoke

Test Locally

npm run serverless:invoke:local

Uses events/hello.invoke.json as the test payload.

Invoke After Deployment

Using AWS CLI

# With a name
aws lambda invoke \
  --function-name aws-lambda-boilerplate-dev-helloInvoke \
  --payload '{"name":"Bayu"}' \
  --region ap-southeast-1 \
  response.json

cat response.json

# Without a name (uses default "world")
aws lambda invoke \
  --function-name aws-lambda-boilerplate-dev-helloInvoke \
  --payload '{}' \
  --region ap-southeast-1 \
  response.json

Using AWS Console

  1. Go to Lambda → Select aws-lambda-boilerplate-dev-helloInvoke
  2. Click TestCreate new test event
  3. Paste test payload and click Test
    {
      "name": "Bayu"
    }
    

Response Example

{
  "message": "Hello, Bayu!",
  "requestId": "xxxx-xxxx-xxxx",
  "timestamp": "2026-05-12T09:13:45.889Z",
  "input": {
    "name": "Bayu",
    "source": "event"
  }
}

Scheduled Cron

When to use: Run Lambda on a schedule (cron job)

Configuration

Function: scheduledCron

Handler: lib/index.min.scheduledHandler

Default schedule: rate(5 minutes)

Trigger: EventBridge rule

Deploy

# Deploy only this function (after initial deployment)
npm run serverless:deploy:function -- --function scheduledCron

# Verify EventBridge rule was created
aws events list-rules --region ap-southeast-1

Change the Schedule

Edit serverless.yml and update the rate parameter:

Rate Expressions (fixed interval)

events:
  - schedule:
      rate: rate(30 minutes)    # Every 30 minutes
      rate: rate(1 hour)        # Every hour
      rate: rate(24 hours)      # Every day

Cron Expressions (specific times)

events:
  - schedule:
      rate: cron(0 8 * * ? *)           # Every day at 08:00 UTC
      rate: cron(0 0 ? * MON *)         # Every Monday at 00:00 UTC
      rate: cron(0 12 * * ? *)          # Every day at 12:00 UTC (noon)
      rate: cron(0/30 * * * ? *)        # Every 30 minutes

Disable Schedule (without removing)

events:
  - schedule:
      rate: rate(5 minutes)
      enabled: false            # Rule won't execute

Test Locally

The scheduled handler runs on a schedule in AWS. Test manually with AWS CLI:

aws lambda invoke \
  --function-name aws-lambda-boilerplate-dev-scheduledCron \
  --region ap-southeast-1 \
  response.json

cat response.json

View Scheduled Executions

CloudWatch Logs

# Follow logs in real-time
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron --follow --region ap-southeast-1

# View recent logs
aws logs get-log-events \
  --log-group-name /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron \
  --log-stream-name '<stream-name>' \
  --region ap-southeast-1

EventBridge Rule Details

# Describe the rule
aws events describe-rule \
  --name aws-lambda-boilerplate-dev-scheduledCron-rule \
  --region ap-southeast-1

# List rule targets
aws events list-targets-by-rule \
  --rule aws-lambda-boilerplate-dev-scheduledCron-rule \
  --region ap-southeast-1

AWS Console

  1. Go to EventBridgeRules
  2. Find and click aws-lambda-boilerplate-dev-scheduledCron-rule
  3. View schedule, targets, and execution history

Response Example

{
  "status": "ok",
  "executedAt": "2026-05-12T09:13:00.000Z",
  "requestId": "xxxx-xxxx-xxxx",
  "source": "aws.events",
  "account": "123456789012",
  "region": "ap-southeast-1"
}

Local Testing

Test All Functions Locally

# Build once
npm run build

# Test direct invoke
npm run serverless:invoke:local

# Test API Gateway
npm run serverless:invoke:local:api

Test After Code Changes

# 1. Make changes in src/handlers/
# 2. Run unit tests
npm run test:run

# 3. Lint
npm run lint:fix

# 4. Build
npm run build

# 5. Test locally
npm run serverless:invoke:local
npm run serverless:invoke:local:api

# 6. Deploy
npm run serverless:deploy

Common Commands

Deployment

# Deploy everything to dev
npm run serverless:deploy

# Deploy to production
npm run serverless:deploy -- --stage prod

# Deploy specific function
npm run serverless:deploy:function -- --function helloApi

# Deploy and show output
npm run serverless:print

# Remove all resources
npm run serverless:remove

Local Testing

# Test direct invoke handler
npm run serverless:invoke:local

# Test API Gateway handler
npm run serverless:invoke:local:api

# Build & run all tests
npm run test

# Lint & fix issues
npm run lint:fix

Monitoring

# View logs for all functions
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-helloApi --follow
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-helloInvoke --follow
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron --follow

# List all Lambda functions
aws lambda list-functions --region ap-southeast-1

# Get function details
aws lambda get-function --function-name aws-lambda-boilerplate-dev-helloApi --region ap-southeast-1

Cleanup

# Remove all deployed resources
npm run serverless:remove

# Remove from specific stage
npm run serverless:remove -- --stage prod

Comparison Table

Function Type Trigger How to Test Deploy Command
helloApi HTTP/REST API API Gateway curl, browser, AWS CLI serverless deploy function --function helloApi
helloInvoke Direct Invocation Lambda API AWS CLI, Console test serverless deploy function --function helloInvoke
scheduledCron Scheduled Job EventBridge cron AWS CLI invoke, logs serverless deploy function --function scheduledCron

Troubleshooting

"Credentials not found"

aws configure
# Enter AWS Access Key ID, Secret Access Key, and region

"Function not found" during deploy

npm run build
# Re-run build to create lib/ directory

API Gateway returns 404

# Check endpoint URL
npm run serverless:print | grep https

# Verify route matches
curl https://{api-id}.execute-api.ap-southeast-1.amazonaws.com/hello

Scheduled function doesn't run

# Verify rule is enabled
aws events describe-rule \
  --name aws-lambda-boilerplate-dev-scheduledCron-rule \
  --region ap-southeast-1

# Check EventBridge logs
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron --follow

"Permission Denied" during deploy

Ensure your AWS IAM user has permissions for:

  • lambda:*
  • apigateway:*
  • events:PutRule, events:PutTargets
  • iam:CreateRole, iam:PutRolePolicy
  • logs:CreateLogGroup

More Information

results matching ""

    No results matching ""