golang How to fetch AWS Resource ARN

huangapple go评论86阅读模式
英文:

golang How to fetch AWS Resource ARN

问题

我需要一个函数或一段代码,可以在AWS中检索命名资源的ARN。

我在DynamoDB中创建了一个表,在控制台中我可以看到ARN:

arn:aws:dynamodb:eu-central-1:111122223333:table/my_new_table

如果我只事先知道表名my_new_table,我如何使用纯Go或AWS SDK for Go以编程方式获取此ARN?

英文:

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?

答案1

得分: 1

使用DescribeTable

表的ARN将在返回的DescribeTableOutput中的返回的TableDescription中作为TableArn可用。

请注意,仅凭表名无法推断出您需要进行此API调用的AWS区域(假设您没有在表名中编码区域)。因此,您需要事先知道要将API请求发送到哪个AWS区域(或者尝试所有区域)。但我假设您事先知道区域。

此外,顺便说一下,您实际上不需要进行DynamoDB API调用来确定ARN。您可以根据对AWS区域、AWS帐户号(可以使用STS GetCallerIdentity检索此信息)和表名的了解来计算它。

英文:

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.

huangapple
  • 本文由 发表于 2022年6月28日 22:28:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/72788320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定