Retry on errors for 3 times, init Run – 1min wait – 1st retry – 2 mins wait – 2nd retry – 2mins wait – final retry; duplicate logs entries in CloudWatch Logs as retried
the processing is idempotent
Can define a DLQ (dead-letter queue) β SNS or SQS β for failed processing (need correct IAM permissions)
Invoked by
Amazon Simple Storage Service (S3), with S3 Events Notifications
Amazon Simple Notification Service (SNS)
Amazon CloudWatch Events / EventBridge
AWS CodeCommit (CodeCommit Trigger : new branch, new tag, new push)
AWS CodePipeline (invoke a Lambda function during the pipeline, Lambda must callback)
Amazon CloudWatch Logs (log processing)
Amazon Simple Email Service
AWS CloudFormation
AWS Config
AWS IoT
AWS IoT Events
To expose Lambda as an HTTP(S) endpoint
ALB, registered Lambda in a target group; also QueryParameters and Headers needed to be Key/Value paired
support multi-value headers, auto-convert multiple values with same key into arrays to Lambda
API Gateway
Event Source Mapping (synchronous invoked)
Streams
Kinesis Data Streams or DynamoDB Streams
One Lambda invocation per stream shard
Processed items aren’t removed from the stream
process multiple batches in parallel (up to 10 batches per shard)
By default, if your function returns an error, the entire batch is reprocessed until the function succeeds, or the items in the batch expire
Queue
SQS & SQS FIFO queue
Long Polling with batch size (1-10 messages)
the DLQ have to set on SQS, not on Lambda
items would be deleted from queue once successfully processed by Lambda
For SQS (standard) queue Lambda adds 60 more instances per minute to scale up, up to 1000 batches
For SQS FIFO queue Lambda scales to the number of active message groups (defined in GroupID), and messages under same GroupID would be processed in order
Event Object – original sources prepared for application codes
JSON, contains information from the invoking service (e.g., EventBridge, custom, …)
Lambda runtime converts the event to an object (e.g., dict type in Python)
Example: input arguments, invoking service arguments, …
Context Object – details about the Lambda resources described
Provides methods and properties that provide information about the invocation, function, and runtime environment
Error Handling should be in Step Functions, not in Task; using Retry and Catch, running from top to bottom but not sequentially (“OR”)
Wait for Task token: append .waitForTaskToken in Resource, pause the running until receiving a SendTaskSuccess or SendTaskFailure API call. (PUSH mechanism)
Activity Task: Activity Worker on EC2/Lambda/.., using GetTaskActivity API call for poll, sending response with SendTaskSuccess or SendTaskFailure API call (PULL mechanism), with SendTaskHeartBeat + HeartBeatSeconds
Standard vs Express (asynchronous and synchronous)
AWS Serverless Application Modal (SAM)
configure via JSON/YAML, complied to CloudFormation stack
use CodeDeploy for Lambda function
Traffic Shifting
Pre- and Pro- for testing on traffic shifting
rollback by AWS CloudWatch Alarm
run Lambda, API Gateway, DynamoDB locally
Lambda start/invoke
API Gateway
AWS Events (sample payloads for event resources)
SAM Recipe
Transform Header – template
Write Code
Package and Deploy – into S3 Bucket
SAM Accelerate (sam sync) – reduce latency
update existing SAM template
using “–code” option, without updating infrastructure (service APIs and bypass CloudFormation)