Deployment and Invocation Guide
This guide explains how to deploy and invoke the three sample Lambda functions in the AWS Lambda Boilerplate.
Table of Contents
- Prerequisites
- Deployment Overview
- API Gateway HTTP API
- Direct Invocation
- Scheduled Cron
- Local Testing
- Post-Deployment Invocation
- Troubleshooting
Prerequisites
Local Setup
- Install Node.js 20+ and npm
- Clone the repository
- Run
npm install - Run
npm run buildto create the Lambda bundles
AWS Setup
- Install AWS CLI v2
Configure AWS credentials:
aws configureYou'll need:
- AWS Access Key ID
- AWS Secret Access Key
- Default region:
ap-southeast-1(or your chosen region) - Default output format:
json
Ensure your AWS account has permissions to:
- Create/manage Lambda functions
- Create/manage API Gateway APIs
- Create/manage EventBridge rules
- Create/manage IAM roles
- Create/manage CloudWatch logs
Install Serverless Framework CLI globally (optional but recommended):
npm install -g serverless
Deployment Overview
All three functions are defined in serverless.yml and deployed together:
npm run serverless:deploy
To deploy only a specific function after the initial deployment:
npm run serverless:deploy:function
To remove the entire stack:
npm run serverless:remove
API Gateway HTTP API
Description
Exposes two HTTP endpoints via API Gateway v2 (HTTP API):
GET /hello— returns greeting with default nameworldGET /hello/{name}— returns greeting with the provided path parameter
Supported query parameters:
?name=Bayu— overrides the name if no path parameter is present
Configuration
File: serverless.yml
helloApi:
name: ${self:service}-${sls:stage}-helloApi
description: Sample Lambda function exposed via API Gateway HTTP API (v2)
handler: lib/index.min.helloHandler
memorySize: 128
timeout: 6
events:
- httpApi:
method: GET
path: /hello
- httpApi:
method: GET
path: /hello/{name}
Deploy
Build and deploy the entire stack:
npm run serverless:deployOr deploy only this function (after initial deployment):
npm run serverless:deploy:function -- --function helloApiNote the HTTP API endpoint URL in the output:
endpoints: GET https://xxxxx.execute-api.ap-southeast-1.amazonaws.com/hello
Test Locally
Before deploying, test the API Gateway handler locally:
npm run serverless:invoke:local:api
This invokes the function with events/hello.apigw.json as the payload.
Post-Deployment Invocation
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 '{"httpMethod": "GET", "path": "/hello"}' \
--region ap-southeast-1 \
response.json
cat response.json
Using the AWS Console
- Go to API Gateway in the AWS Console
- Select the created API (
aws-lambda-boilerplate-dev) - Click
Deployments→Stages→$default - Copy the Invoke URL
- Append
/helloor/hello/Bayuand open in a browser or use curl
Response Example
{
"statusCode": 200,
"headers": {
"content-type": "application/json"
},
"body": "{\"message\":\"Hello, Bayu!\",\"requestId\":\"xxx-xxx\",\"timestamp\":\"2026-05-12T09:13:52.252Z\",\"input\":{\"name\":\"Bayu\",\"source\":\"query\"}}"
}
Direct Invocation
Description
A simple Lambda function with no event source. Invoked directly via AWS Lambda APIs or the console.
Accepts a JSON payload with an optional name field.
Configuration
File: serverless.yml
helloInvoke:
name: ${self:service}-${sls:stage}-helloInvoke
description: Directly invokable sample Lambda function deployed with Serverless Framework
handler: lib/index.min.directHelloHandler
memorySize: 128
timeout: 6
Deploy
Build and deploy the entire stack:
npm run serverless:deployOr deploy only this function (after initial deployment):
npm run serverless:deploy:function -- --function helloInvoke
Test Locally
Before deploying, test the direct handler locally:
npm run serverless:invoke:local
This invokes the function with events/hello.invoke.json as the payload:
{
"name": "Bayu"
}
Post-Deployment Invocation
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 Serverless Framework
# After deployment
npm run serverless:invoke:local -- --stage prod --function helloInvoke
Using the AWS Console
- Go to Lambda in the AWS Console
- Select the function
aws-lambda-boilerplate-dev-helloInvoke - Click
Test→Create new test event - Paste the payload:
{ "name": "Bayu" } - Click
Test
Response Example
{
"message": "Hello, Bayu!",
"requestId": "xxxx-xxxx-xxxx",
"timestamp": "2026-05-12T09:13:45.889Z",
"input": {
"name": "Bayu",
"source": "event"
}
}
Scheduled Cron
Description
A Lambda function triggered on a schedule via EventBridge (formerly CloudWatch Events). Runs every 5 minutes by default. No user input — it simply logs the event and returns execution metadata.
Configuration
File: serverless.yml
scheduledCron:
name: ${self:service}-${sls:stage}-scheduledCron
description: Sample Lambda function triggered by a scheduled EventBridge rule
handler: lib/index.min.scheduledHandler
memorySize: 128
timeout: 30
events:
- schedule:
name: ${self:service}-${sls:stage}-scheduledCron-rule
description: Triggers scheduledCron every 5 minutes
rate: rate(5 minutes)
enabled: true
Changing the Schedule
To modify the schedule, edit serverless.yml:
Rate expressions:
rate: rate(30 minutes) # Every 30 minutes
rate: rate(1 hour) # Every hour
rate: rate(24 hours) # Every day
Cron expressions:
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 the schedule (without removing it):
events:
- schedule:
rate: rate(5 minutes)
enabled: false # Won't run, but rule remains
Deploy
Build and deploy the entire stack:
npm run serverless:deployOr deploy only this function (after initial deployment):
npm run serverless:deploy:function -- --function scheduledCronVerify the rule was created:
aws events list-rules --region ap-southeast-1
Test Locally
Before deploying, you can test the scheduled handler locally (it won't actually run on a schedule):
Look at the test file test/scheduled.spec.ts for examples of what the handler receives and returns.
Post-Deployment Invocation
Invoke Manually via AWS CLI
aws lambda invoke \
--function-name aws-lambda-boilerplate-dev-scheduledCron \
--region ap-southeast-1 \
response.json
cat response.json
View Execution Logs
CloudWatch Logs will show all invocations (automated and manual):
# List log streams
aws logs describe-log-streams \
--log-group-name /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron \
--region ap-southeast-1
# View recent logs
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron \
--follow \
--region ap-southeast-1
View EventBridge Rule Details
# Describe the rule
aws events describe-rule \
--name aws-lambda-boilerplate-dev-scheduledCron-rule \
--region ap-southeast-1
# List targets
aws events list-targets-by-rule \
--rule aws-lambda-boilerplate-dev-scheduledCron-rule \
--region ap-southeast-1
Using the AWS Console
- Go to EventBridge → Rules
- Find the rule
aws-lambda-boilerplate-dev-scheduledCron-rule - Click it to see details, schedule, and targets
- Click
Editto change the schedule
Response Example
The function returns execution metadata:
{
"status": "ok",
"executedAt": "2026-05-12T09:13:00.000Z",
"requestId": "xxxx-xxxx-xxxx",
"source": "aws.events",
"account": "123456789012",
"region": "ap-southeast-1"
}
Local Testing
All Functions
Build once, then test all three locally in sequence:
npm run build
# Test direct invoke
npm run serverless:invoke:local
# Test API Gateway
npm run serverless:invoke:local:api
# Test scheduled (returns immediately, doesn't actually run on schedule)
Development Workflow
- Make code changes in
src/handlers/ - Run tests to ensure they pass:
npm run test:run - Test locally:
npm run serverless:invoke:local # direct npm run serverless:invoke:local:api # API Gateway - Lint and check:
npm run lint:run - Build:
npm run build - Deploy:
npm run serverless:deploy
Post-Deployment Invocation
Stage and Region Overrides
Deploy to a different stage/region:
npm run serverless:deploy -- --stage prod --region ap-southeast-1
Then invoke using dynamic function names:
aws lambda invoke \
--function-name aws-lambda-boilerplate-prod-helloInvoke \
--payload '{"name":"Test"}' \
--region ap-southeast-1 \
response.json
Monitoring and Logs
View all Lambda function logs:
# Direct invoke logs
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-helloInvoke --follow
# API Gateway logs
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-helloApi --follow
# Scheduled logs
aws logs tail /aws/lambda/aws-lambda-boilerplate-dev-scheduledCron --follow
Cleanup
Remove all deployed resources:
npm run serverless:remove
This will delete:
- All three Lambda functions
- The API Gateway API
- The EventBridge rule
- Associated IAM roles and CloudWatch log groups
Troubleshooting
Issue: "Credentials not found"
Solution:
aws configure
# Enter your AWS Access Key ID, Secret Access Key, and region (ap-southeast-1)
Issue: "Function not found" during local invoke
Solution:
npm run build
The build step creates lib/index.min.cjs which contains the exported handlers that Serverless Framework references.
Issue: API Gateway returns 404
Solution:
Verify the route matches:
curl https://{api-id}.execute-api.ap-southeast-1.amazonaws.com/helloCheck the endpoint URL in Serverless output:
npm run serverless:print | grep https
Issue: Scheduled function doesn't run
Solution:
Verify the rule is enabled:
aws events describe-rule --name aws-lambda-boilerplate-dev-scheduledCron-rule --region ap-southeast-1Check the rule target has permission:
aws events list-targets-by-rule --rule aws-lambda-boilerplate-dev-scheduledCron-rule --region ap-southeast-1Manually invoke to test:
aws lambda invoke --function-name aws-lambda-boilerplate-dev-scheduledCron --region ap-southeast-1 response.json
Issue: "Permission Denied" during deploy
Solution:
Ensure your AWS credentials have the required IAM permissions:
lambda:CreateFunction,lambda:UpdateFunctionCode,lambda:DeleteFunctionapigateway:*events:PutRule,events:PutTargetsiam:CreateRole,iam:PutRolePolicylogs:CreateLogGroup
Ask your AWS account administrator to attach these policies to your IAM user.
Summary Table
| Function | Type | Trigger | Routes | Deploy Command | Local Test |
|---|---|---|---|---|---|
helloApi |
API Gateway (v2) | HTTP GET | /hello, /hello/{name} |
serverless deploy function --function helloApi |
npm run serverless:invoke:local:api |
helloInvoke |
Direct Invocation | AWS Lambda API | — | serverless deploy function --function helloInvoke |
npm run serverless:invoke:local |
scheduledCron |
Scheduled/EventBridge | Cron rate(5 minutes) |
— | serverless deploy function --function scheduledCron |
Manual via AWS CLI |
For more information, see: