简体   繁体   English

AWS GO SDK 承担分配给 EC2 实例的角色

[英]AWS GO SDK Assume role given to EC2 instance

I am running a small go application inside ec2 instance.我在 ec2 实例中运行一个小型 go 应用程序。 It access Amazon SQS as a consumer.它以消费者身份访问 Amazon SQS。 I have configured keys at ~/.aws/credential file.我在 ~/.aws/credential 文件中配置了密钥。 The EC2 instance has been assigned an IAM role. EC2 实例已分配一个 IAM 角色。

  1. Can my go application use the IAM role assigned to the EC2 instance?我的 go 应用程序可以使用分配给 EC2 实例的 IAM 角色吗?
  2. If yes, how that can be done using configurations without a code change?如果是,如何在不更改代码的情况下使用配置来完成?
  3. If role is configured, should I still provide keys in somewhere?如果配置了角色,我还应该在某处提供密钥吗?

If you used github.com/aws/aws-sdk-go-v2/config and config.LoadDefaultConfig() method to retrieve AWS credentials,如果您使用github.com/aws/aws-sdk-go-v2/configconfig.LoadDefaultConfig()方法检索 AWS 凭证,

  1. Yes.是的。 Your application will retrieve temporary credentials with IAM Role you assigned.您的应用程序将使用您分配的 IAM 角色检索临时凭证。
  2. aws-sdk-go-v2 will retrieve credentials from instance metadata. aws-sdk-go-v2 将从实例元数据中检索凭证。 Detailed retrieving process is described AWS official docs here .详细的检索过程AWS 官方文档中有所描述。 "How do roles for EC2 instances work" section describes the process as below. “EC2 实例的角色如何工作”部分描述了如下过程。

When the application runs, it obtains temporary security credentials from Amazon EC2 instance metadata , as described in Retrieving Security Credentials from Instance Metadata .当应用程序运行时,它会从 Amazon EC2 实例元数据中获取临时安全凭证,如从实例元数据中检索安全凭证中所述。 These are temporary security credentials that represent the role and are valid for a limited period of time.这些是代表角色的临时安全凭证,在有限的时间段内有效。

With some AWS SDKs, the developer can use a provider that manages the temporary security credentials transparently.借助某些 AWS 开发工具包,开发人员可以使用透明地管理临时安全凭证的提供商。 (The documentation for individual AWS SDKs describes the features supported by that SDK for managing credentials.) (各个 AWS 开发工具包的文档描述了 SDK 支持的用于管理凭证的功能。)

Alternatively, the application can get the temporary credentials directly from the instance metadata of the EC2 instance.或者,应用程序可以直接从 EC2 实例的实例元数据中获取临时凭证。 Credentials and related values are available from the iam/security-credentials/role-name category (in this case, iam/security-credentials/Get-pics) of the metadata.凭证和相关值可从元数据的 iam/security-credentials/role-name 类别(在本例中为 iam/security-credentials/Get-pics)中获得。 If the application gets the credentials from the instance metadata, it can cache the credentials.如果应用程序从实例元数据中获取凭证,它可以缓存这些凭证。

Also you can refer to here about aws-sdk-go-v2's credential retrieval order.您也可以参考此处了解 aws-sdk-go-v2 的凭证检索顺序。

  1. You don't have to provide key.您不必提供密钥。 aws-sdk-go-v2 will retrieve it from EC2 instance metadata . aws-sdk-go-v2 将从 EC2 实例元数据中检索它。

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

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