首页 文章

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

提问于
浏览
0

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

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

条件:TableCreationCondition:!Equals [!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

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

    DependsOn: !Ref DynamoDBTableStream
    

相关问题