简体   繁体   English

InvalidClientTokenId 在具有实例配置文件的 AWS EC2 实例上调用 get-caller-identity 时

[英]InvalidClientTokenId when calling get-caller-identity on an AWS EC2 instance with instance profile

We're having an issue where we're on a CentOS EC2 instance that is using a role through an attached instance profile.我们在 CentOS EC2 实例上遇到了一个问题,该实例通过附加的实例配置文件使用角色。 When we're on the console after SSHing in, we run the python awscli command line tool to get our identity:当我们在 SSH 登录后在控制台上时,我们运行 python awscli命令行工具来获取我们的身份:

$ aws sts get-caller-identity

we're getting我们得到

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid调用 GetCallerIdentity 操作时发生错误 (InvalidClientTokenId):请求中包含的安全令牌无效

other commands, such as aws ec2 describe-instances work and are allowed by the instance profile.其他命令,例如aws ec2 describe-instances工作,并且被实例配置文件允许。

From reading the AWS documentation, no permissions should be required to get-caller-identity and there's no explicit deny set on the role associated with instance.通过阅读 AWS 文档,get-caller-identity 不需要任何权限,并且没有对与实例关联的角色设置明确的deny

We checked and there's no .aws/credentials file and no env variables set, so access should be entirely managed through the metadata service on the EC2 instance.我们检查过,没有.aws/credentials文件,也没有设置env变量,因此访问应该完全通过 EC2 实例上的元数据服务进行管理。

Is there something missing in our setup or invocation of the awscli that might cause the permission to fail?我们的awscli设置或调用中是否缺少可能导致权限失败的内容?

Just documenting the fix for anyone that runs into this issue.只是为遇到此问题的任何人记录修复程序。

All calls to the awscli should probably include a --region <region> parameter.所有对awscli调用awscli应该包含一个--region <region>参数。

Eg例如

$ aws sts get-caller-identity --region us-east-2

We were prompted for the region on our aws ec2 describe-instances call but on the aws sts get-caller-identity call, it just failed.我们在aws ec2 describe-instances调用中被提示输入区域,但在aws sts get-caller-identity调用中,它失败了。

Additionally, we found that the AWS_REGION environment variable didn't seem to affect calls: we still needed to include the --region <region> parameter.此外,我们发现AWS_REGION环境变量似乎没有影响调用:我们仍然需要包含--region <region>参数。

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

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