gpt4 book ai didi

amazon-web-services - 使用cloudformation模板在dynamodb表中发生任何变化时如何触发函数?

转载 作者:行者123 更新时间:2023-12-03 07:15:31 25 4
gpt4 key购买 nike

使用cloudformation模板在dynamodb表中发生任何变化时如何触发函数

我用过

“类型”:“AWS::Lambda::函数”,

“类型”:“AWS::DynamoDB::表”,

最佳答案

您必须为 DynamoDB Streams 创建一个 AWS::Lambda::EventSourceMapping 类型资源,它将调用 lambda 函数。

假设您的 cloudformation 模板中有 Lambdafunction 和 dynamodb 表资源,下一步将定义 EventSourceMapping,如下面的代码片段所示:

MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.7
Timeout: '50'
..............
MyDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
.......................
DynamoDBTableStream:
Type: AWS::Lambda::EventSourceMapping
Properties:
# The maximum number of DB items to send to Lambda
BatchSize: 1 # It can be changed based on the need
Enabled: True
EventSourceArn: !GetAtt MyDynamoDBTable.StreamArn
FunctionName: !GetAtt MyLambdaFunction.Arn
# Always start at the tail of the Stream
StartingPosition: LATEST

关于amazon-web-services - 使用cloudformation模板在dynamodb表中发生任何变化时如何触发函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64021429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com