执行 aws cli 命令时出现以下错误aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small"
:
A client error (AuthFailure) occurred when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials
凭据来自以下脚本:
import boto3
sts_client = boto3.client('sts')
assumedRoleObject = sts_client.assume_role(
RoleArn="arn:aws:iam::<>:role/service-role/Test-Project",
RoleSessionName="AssumeRoleSession2"
)
credentials = assumedRoleObject['Credentials']
print credentials['AccessKeyId']
print "#"*100
print credentials['SecretAccessKey']
print "#"*100
print credentials['SessionToken']
print "#"*100
我还测试了对角色启用管理员访问权限。还是行不通。
角色的信任关系如下:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"*",
"arn:aws:iam::<>:user/<username>"
],
"Service": [
"lambda.amazonaws.com",
"ec2.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}