0

I defined DynamoDB table inside nested stack in cloudformaion just have output stream arn string like:

arn:aws:dynamodb:us-east-1:123456789012:table/books_table/stream/2015-05-11T21:21:33.291

I want to get the substring of this stream arn and get string:

arn:aws:dynamodb:us-east-1:123456789012:table/books_table

Can you give me example how to do substring the stream arn of above case? How to just cut the last two parts? use what function to do it in aws cloudformation? or combination functions to get corresponding string.

ps:

I can not use:

Fn::GetAtt: [ 'dynamodbTableLogicalId', 'Arn' ]

directly, as it 'dynamodbTableLogicalId' hidden inside the nested stack.

user504909
  • 9,119
  • 12
  • 60
  • 109

2 Answers2

0

Assuming you are creating the DynamoDB table using CloudFormation you are already naming your table.

TableName: !Ref "TableName"

an option would be to construct the ARN

!Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${TableName}" 
George Rushby
  • 1,305
  • 8
  • 13
0

Try combining Fn::Join, Fn::Select and Fn::Split. This is ugly, but that's often the case with string transforms in Cloudformation:

Fn::Join [':',
          ['arn', 'aws', 'dynamodb': ${AWS::Region}, ${AWS::AccountId}, 'table/',
           Fn::Select [1, Fn::Split ['/', 'arn:aws:dynamodb:us-east-1:123456789012:table/books_table/stream/2015-05-11T21:21:33.291']]]
]

Note I did not test this code. The interesting part is the steam ARN is calling Fn::Split on the / character, so the books_table is the second element in the resulting array. It is selected using the Fn::Select. It is the last part of the array to be Fn::Join-ed, so the result ought to be what you want.

You can use the Select & Split combo on the region and account ID if you'd need to.

Milan Cermak
  • 7,476
  • 3
  • 44
  • 59