13

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?

Thomas
  • 10,289
  • 13
  • 39
  • 55

2 Answers2

7

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
Laurent Jalbert Simard
  • 5,949
  • 1
  • 28
  • 36
  • 2
    Thanks Laurent for your answer. Unfortunately, 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. – Thomas Apr 05 '18 at 20:08
  • I understand, I suggest you update the question to reflect that. I'll leave my answer as is, it may help someone else. – Laurent Jalbert Simard Apr 05 '18 at 22:23
  • For future folks, this only works if you have the resource in the same CloudFormation template – tmanion Sep 06 '18 at 22:17
  • 1
    For future folks, this doesn't work as is and in order to access this attribute `You must specify the StreamSpecification property to use this attribute.` which documentation [is available here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-streamspecification.html). Otherwise you'll get `Attribute: StreamArn was not found for resource` – Samuel Prevost May 15 '19 at 12:18
  • In my case, I'm dealing with an existing table/stream so I pass the needed Arn in through a template parameter. – rainabba Apr 16 '20 at 23:37
  • Please assume you don't define the table resource here as that is the more common case. – Samantha Atkins Apr 24 '20 at 04:45
0

You may need a custom resource to do this. Your custom resource can use API to get the stream ARN and return it.

Shahar Mosek
  • 1,922
  • 3
  • 17
  • 27