0
votes

I have a cloudformation template that creates Table along with EventSourceMapping for Stream. I am using Conditions in Table creation, but it complains about the dependency for EventSourceMapping since my EventSourceMapping depends on Table creation. I want some suggestions how to manage the dependency. Here is my sample code:

Parameters: TableName: Description: Name of the DynamoDb Table Type: String

Conditions: TableCreationCondition: !Equals [ !Ref TableName, "" ]

Resources:

 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

1 Answers

0
votes

You could set this property on the DynamoDB Table:

DependsOn: !Ref DynamoDBTableStream