简体   繁体   English

golang 如何获取 AWS 资源 ARN

[英]golang How to fetch AWS Resource ARN

I need a function or a piece of code that can retrieve the ARN of a named resource in AWS.我需要一个函数或一段代码来检索 AWS 中命名资源的 ARN。

I created a table in DynamoDB and in console I can see the ARN:我在 DynamoDB 中创建了一个表,在控制台中我可以看到 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?如果我事先只知道表名my_new_table ,如何使用普通 Go 或 AWS SDK for Go 以编程方式获取此 ARN?

Use DescribeTable .使用描述表

The table's ARN will be available as TableArn in the returned TableDescription within the returned DescribeTableOutput .表的 ARN 将在返回的DescribeTableOutput中作为返回的TableDescription中的TableArn提供。

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).请注意,您无法仅从表名称推断出需要进行此 API 调用的 AWS 区域(假设您没有在表名称中对该区域进行编码)。 So, you need to know which AWS region to send the API request to in advance (or potentially try all regions).因此,您需要提前知道将 API 请求发送到哪个 AWS 区域(或者可能尝试所有区域)。 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.此外,顺便说一句,您实际上不需要进行 DynamoDB API 调用来确定 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.考虑到 AWS 区域、AWS 帐号(您可以使用 STS GetCallerIdentity 检索)和表名称,您可能会计算它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM