在AWS Cloudformation模板中使用条件时如何管理资源依赖性?

时间:2018-06-25 19:44:16

标签: amazon-web-services stream amazon-dynamodb

我有一个cloudformation模板,用于创建Table以及EventSourceMapping for Stream。我在表创建中使用条件,但是它抱怨EventSourceMapping的依赖性,因为我的EventSourceMapping依赖于表创建。我想要一些有关如何管理依赖项的建议。这是我的示例代码:

参数:   表名:     说明:DynamoDb表的名称     类型:字符串

条件:   TableCreationCondition:!等于[!Ref TableName,“”]

资源:

 DynamoDBTable:
    #Condition: TableCreationCondition
    Type: "AWS::DynamoDB::Table"
    DeletionPolicy: Retain
    Properties:
      AttributeDefinitions:
      - AttributeName: !Ref HashKeyElementName
        AttributeType: !Ref HashKeyElementType
      KeySchema:
      - AttributeName: !Ref HashKeyElementName
        KeyType: HASH
      TableName: !Ref TableName
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES
      ProvisionedThroughput:
        ReadCapacityUnits: !Ref ReadCapacityUnits
        WriteCapacityUnits: !Ref WriteCapacityUnits
      SSESpecification:
          SSEEnabled: true

  DynamoDBTableStream:
    Type: AWS::Lambda::EventSourceMapping
    Properties:
      BatchSize: 1 #trigger one lambda per document
      Enabled: True
      EventSourceArn: 
        Fn::GetAtt:
          - DynamoDBTable
          - StreamArn 
      FunctionName: 
        Fn::GetAtt: 
          - MyLambdaFunction
          - Arn 
      StartingPosition: LATEST

1 个答案:

答案 0 :(得分:0)

您可以在DynamoDB表上设置此属性:

DependsOn: !Ref DynamoDBTableStream