gpt4 book ai didi

amazon-web-services - 无法在 InstanceProfileCredentialsProvider 上加载 EC2 实例的凭证

转载 作者:行者123 更新时间:2023-12-04 08:02:02 29 4
gpt4 key购买 nike

我已将 EC2 角色附加到实例、我的 EC2 实例,并且我正在运行我的 AWS JAVA SDK。当我尝试以这种方式加载凭据时:

InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();

我收到以下错误:
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load credentials.
at com.amazonaws.auth.InstanceProfileCredentialsProvider.loadCredentials(InstanceProfileCredentialsProvider.java:195)
at com.amazonaws.auth.InstanceProfileCredentialsProvider.getCredentials(InstanceProfileCredentialsProvider.java:124)

任何人都可以建议我可能缺少什么?

最佳答案

我能够通过从我的 EC2 实例运行代码并增强我的代码来解决它,这是代码:

 String arn = "arn:aws:iam::"+accountnumber+":role/My-CrossAccount-CustomRole-ReadOnly";

InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();

stscred = new STSAssumeRoleSessionCredentialsProvider(instanceCred.getCredentials(),arn,"123",clientConfiguration);

确保您有 "sts:AssumeRole"在你的角色行动中。

关于amazon-web-services - 无法在 InstanceProfileCredentialsProvider 上加载 EC2 实例的凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32825380/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com