我的结构与此类似
SQS -> Lambda -> DLQ
当如下异步调用 Lambda 时,失败消息将成功添加到 DLQ。
$ aws lambda invoke --function-name my-function --invocation-type Event --payload '{ "key": "value" }' response.json
但是,当 lambda 在向 SQS 添加新消息时触发,然后失败时,消息不会存储在 DLQ 中。
我发现当新消息发布到SQS时触发的事件本质上是同步的。
Lambda 轮询队列并与一个同步调用您的函数 包含队列消息的事件。
参考 - https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html.
所以我想要一个-
或
如果您使用同步调用 lambda 的源(例如 SQS、DynamoDbStream 或 KinesisStream),则需要将 DLQ 附加到源。例子:
SQS
MySqsQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: MySqsQueueName
RedrivePolicy:
deadLetterTargetArn: !GetAtt Dlq.Arn
maxReceiveCount: 1000
VisibilityTimeout: 700
Dlq:
Type: AWS::SQS::Queue
Properties:
QueueName: MySqsQueueName # Hardcoding the name to avoid the dependency loop.
RedriveAllowPolicy:
redrivePermission: "byQueue"
sourceQueueArns:
- !Sub arn:aws:sqs:${AWS::Region}:${AWS::AccountId}:MySqsQueueName
VisibilityTimeout: 700
DynamoDbStream:
DynamoDbStreamFanoutHandler:
Type: AWS::Serverless::Function
Properties:
...
Events:
DynamoStream:
Type: DynamoDB
Properties:
BatchSize: 100
BisectBatchOnFunctionError: True
DestinationConfig:
OnFailure:
Destination: !Ref DlqArn ## The DLQ config is here.
Enabled: True
MaximumBatchingWindowInSeconds: 10
MaximumRecordAgeInSeconds: -1
MaximumRetryAttempts: 100
ParallelizationFactor: 2
StartingPosition: TRIM_HORIZON
Stream: !GetAtt DynamoDbTable.StreamArn