I need a function or a piece of code that can retrieve the ARN of a named resource in AWS.
I created a table in DynamoDB and in console I can see the ARN:
arn:aws:dynamodb:eu-central-1:111122223333:table/my_new_table
How can I programmatically fetch this ARN using plain Go or AWS SDK for Go if I only know the table name my_new_table
beforehand?
CodePudding user response:
Use DescribeTable.
The table's ARN will be available as TableArn
in the returned TableDescription within the returned DescribeTableOutput.
Note that you cannot infer the AWS region that you need to make this API call to from the table name alone (assuming you haven't encoded the region in the table name). So, you need to know which AWS region to send the API request to in advance (or potentially try all regions). But I presume you know the region in advance.
Also, as an aside, you don't actually need to make a DynamoDB API call to determine the ARN. You could potentially calculate it given knowledge of the AWS region, the AWS account number (you can retrieve this using STS GetCallerIdentity), and the table name.