Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference the latest Stream of a DynamoDB table in a Cloudformation template

I am writing a plugin for the serverless framework, which references a DynamoDB Stream by its ARN. I can construct the DynamoDB tables ARN with the information I have at hand, but I don't know the timestamp part, that would be necessary to build the full stream ARN. I don't have access to the original DynamoDB Cloudformation definition, when I need to reference the Stream ARN, those two things can happen in entirely different templates. All I have is the ARN of the already created DynamoDB at this point.

Is there a way to reference the latest stream via a variable similar to arn:aws:dynamodb:${AWS::Region}::${AWS::AccountId}:table/eventbus-test/stream/${LATEST}?

Or can I build it in another way by means of a serverless configuration or Cloudformation template?

like image 694
Thomas Avatar asked Apr 05 '18 17:04

Thomas


People also ask

How do you reference existing resources in CloudFormation?

To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.

How do you make a DynamoDB table in cloud formation?

Review and download the CloudFormation template. Launch the CloudFormation Stack. Upload the CloudFormation template, and launch the stack to create the DynamoDB table. Verify the DynamoDB Table Was Created.

Does DynamoDB stream Arn change?

The latestStreamArn does not expire after 24 hours. A stream is created when you enable DynamoDB Streams either through a CreateTable or UpdateTable API call. latestStreamArn will change if you disable a DynamoDB stream and then re-enable it.


1 Answers

According to the doc. You can access it with the Fn::GetAtt intrinsic function with the StreamArn parameter. For example:

Resources: 
  Table:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
      - AttributeName: leaseKey
        AttributeType: S
      KeySchema:
      - KeyType: HASH
        AttributeName: leaseKey
      ProvisionedThroughput:
        ReadCapacityUnits: '1'
        WriteCapacityUnits: '1'
Outputs:
  TableStreamArn:
    Value: !GetAtt Table.StreamArn
like image 187
Laurent Jalbert Simard Avatar answered Sep 19 '22 13:09

Laurent Jalbert Simard