update docs
This commit is contained in:
33
docs/lambdas-md/lambda-06-triggers.md
Normal file
33
docs/lambdas-md/lambda-06-triggers.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Triggers
|
||||
|
||||
> Fan-in catalogue: API GW, Function URL, S3, SQS, SNS, EventBridge, DynamoDB streams, Kinesis, ALB, schedule, Step Functions.
|
||||
|
||||
## Three invocation models
|
||||
|
||||
Every trigger falls into one of three models, and the model determines retry behaviour, error handling, and whether the caller can see the response.
|
||||
|
||||
| Model | Caller behaviour | Retries on error | Max event size |
|
||||
|-------|------------------|------------------|----------------|
|
||||
| **Synchronous** | Blocks for response; gets result or error directly | None — caller decides | 6 MB request + response |
|
||||
| **Asynchronous** | Gets 202 immediately; Lambda queues + retries internally | 2 retries (3 total) over up to 6 h | 256 KB event |
|
||||
| **Poll-based (ESM)** | Lambda polls the source on your behalf; batches records | Keeps retrying until success or record expires/goes to DLQ | Depends on source |
|
||||
|
||||
## Trigger catalogue
|
||||
|
||||
| Trigger | Model | Key notes |
|
||||
|---------|-------|-----------|
|
||||
| **API Gateway (REST / HTTP)** | Sync | 29 s integration timeout regardless of Lambda timeout. HTTP API is cheaper and lower-latency than REST API. Transforms request/response. |
|
||||
| **Function URL** | Sync | Direct HTTPS endpoint on the function; no API Gateway layer. Supports up to 15 min timeout and response streaming. Simpler, cheaper, fewer features. |
|
||||
| **ALB (Application Load Balancer)** | Sync | Like API GW but routes at L7; useful when Lambda is one target among EC2/ECS targets. 29 s timeout. |
|
||||
| **S3 event notification** | Async | Fires on object create/delete/etc. At-least-once delivery. Large PUT creates exactly one event per object but notifications can duplicate. Common pattern: S3 → SNS → SQS → Lambda for fan-out + replay. |
|
||||
| **SNS** | Async | Fan-out: one message → multiple subscribers. At-least-once. Dead-letter queue on the subscription, not the topic. |
|
||||
| **EventBridge (CloudWatch Events)** | Async | Event bus with content-based routing rules. Also the managed scheduler (cron/rate expressions, timezone-aware since 2022). At-least-once. |
|
||||
| **SQS** | Poll-based (ESM) | Lambda polls and batches (up to 10 000 msg). Standard: at-least-once, unordered. FIFO: ordered per message group, exactly-once with dedup. Visibility timeout must be ≥ 6× function timeout. Partial batch failure via `batchItemFailures`. |
|
||||
| **Kinesis Data Streams** | Poll-based (ESM) | One Lambda shard per stream shard. Records expire (24 h–1 yr); Lambda retries until success or expiry. Use bisect-on-error and `batchItemFailures` to avoid one bad record blocking an entire shard. |
|
||||
| **DynamoDB Streams** | Poll-based (ESM) | Captures item-level changes. Ordered per partition key. 24 h retention. Same retry behaviour as Kinesis. Use for CDC (change-data-capture) patterns. |
|
||||
| **Step Functions** | Sync (Task state) | Step Functions calls the function synchronously and waits for the result. Retries and timeouts are defined in the state machine, not Lambda. See the [Step Functions](lambda-12-step-functions.md) section. |
|
||||
| **Cognito / SES / IoT etc.** | Sync or Async | Service-specific; check the docs for each. Cognito triggers (pre-signup, pre-token) are sync and block the auth flow. |
|
||||
|
||||
## Choosing between SQS and SNS+SQS
|
||||
|
||||
Use plain **SQS → Lambda** when you have one consumer and want to buffer, batch, and retry. Use **SNS → SQS → Lambda** when you need fan-out (multiple independent consumers each get a copy) or when the producer is an AWS service that speaks SNS natively (S3 event notifications, for example). The SNS layer decouples producers from the queue topology.
|
||||
Reference in New Issue
Block a user