定义可触发Lambda函数的多个ARN

时间:2018-01-22 20:35:12

标签: amazon-web-services aws-lambda amazon-dynamodb amazon-cloudformation amazon-dynamodb-streams

以下是我在AWS::Lambda::EventSourceMapping的AWS文档中看到的示例CloudFormation语法:

Type: "AWS::Lambda::EventSourceMapping"
Properties: 
  BatchSize: Integer
  Enabled: Boolean
  EventSourceArn: String
  FunctionName: String
  StartingPosition: String

假设我有一组DDB流ARN,我想将其用作一个lambda函数的触发器(而不是一个ARN作为触发器)。我试图像这样定义这种关系:

Parameters:
   DDBStreamARN:
     Type: String
     Default: arn:aws:dynamodb:us-west-2:someId1
     AllowedValues:
       - arn:aws:dynamodb:us-west-2:someId1
       - arn:aws:dynamodb:us-west-2:someId2
       - ...
     Description: ARNs for the DDB Streams

Resources:
  RegistrationRequestStreamMapping:
     Type: AWS::Lambda::EventSourceMapping
     Properties:
       BatchSize: 70
       EventSourceArn:
         Ref: DDBStreamARN
       FunctionName:
         Fn::GetAtt:
           - TestLambdaFunction
           - Arn
       StartingPosition: TRIM_HORIZON
       Enabled: True

但语法似乎不起作用,因为只有默认值(arn:aws:dynamodb:us-west-2:someId1)作为触发器工作,而其他ARN不会触发lambda函数。关于如何解决这个问题的任何建议?

2 个答案:

答案 0 :(得分:1)

两次部署CFT。一次使用arn:aws:dynamodb:us-west-2:someId1,第二次使用arn:aws:dynamodb:us-west-2:someId2作为DDBStreamARN参数的值。

答案 1 :(得分:0)

您可以为同一lambda定义许多AWS :: Lambda :: EventSourceMapping。

例如;

RegistrationRequestStreamMapping1:
     Type: AWS::Lambda::EventSourceMapping
     Properties:
       BatchSize: 70
       EventSourceArn:
         Ref: DDBStream1ARN
       FunctionName:
         Fn::GetAtt:
           - TestLambdaFunction
           - Arn
       StartingPosition: TRIM_HORIZON
       Enabled: True

RegistrationRequestStreamMapping2:
     Type: AWS::Lambda::EventSourceMapping
     Properties:
       BatchSize: 70
       EventSourceArn:
         Ref: DDBStream2ARN
       FunctionName:
         Fn::GetAtt:
           - TestLambdaFunction
           - Arn
       StartingPosition: TRIM_HORIZON
       Enabled: True