3.2.1 Test Deployed Code

Test Deployed Code by Using AWS Services and Tools

SAM CLI

CommandMô tả
sam local invokeRun Lambda locally
sam local start-apiLocal API Gateway
sam local start-lambdaLocal Lambda endpoint
sam local generate-eventGenerate sample events
sam validateValidate template
sam buildBuild dependencies

Testing Flow

sam build
sam local generate-event apigateway aws-proxy > events/api.json
sam local invoke MyFunction -e events/api.json
sam local start-api --port 3000

Lambda Console Testing

  • Create test events from templates
  • Shareable test events in account
  • View: execution result, logs, duration, memory

AWS CloudShell

Browser-based shell environment trong AWS Console, pre-configured với AWS CLI và common tools.

FeatureMô tả
Pre-installedAWS CLI, Python, Node.js, pip, npm, git
Storage1 GB persistent storage per region
CredentialsTự động dùng console login credentials
CostFree (no additional charges)
TimeoutSession expires sau 20 min idle
File transferUpload/download files (max 1GB)
# CloudShell — no credential setup needed
aws lambda invoke --function-name my-function \
  --payload '{"key": "value"}' output.json

# Test API Gateway
curl https://api-id.execute-api.region.amazonaws.com/dev/orders

# Quick DynamoDB check
aws dynamodb scan --table-name Orders --max-items 5
  • Không cần install AWS CLI locally
  • Useful cho quick testing, debugging, ad-hoc commands
  • Supports multiple tabs

CLI Testing (Local hoặc CloudShell)

# Invoke deployed Lambda
aws lambda invoke --function-name my-function \
  --payload '{"key": "value"}' output.json

# Test API Gateway
curl https://api-id.execute-api.region.amazonaws.com/dev/orders

Exam Tip: sam local invoke = local test. aws lambda invoke = test deployed function. Console test events for quick validation.