2017-05-24 92 views
0

我得到以下錯誤,執行AWS CLI命令時:aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small"(使用CLI)AWS是無法驗證所提供的訪問憑據

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" 
    } 
    ] 
} 
+0

你從'AWS IAM GET-user'得到什麼? –

+0

@AdamOwczarczyk我得到了同樣的錯誤:調用GetUser操作時出現客戶端錯誤(InvalidClientTokenId):請求中包含的安全令牌無效。' – Dawny33

+0

因此,您的'aws configure'出錯了,您提供的憑證是無效的,或者,或者,您的會話令牌超時,因爲您將其設置爲非常短的時間段。 Manish的答案有更多細節。 –

回答

0

我能想到的原因有二隻,爲什麼它不工作,只是檢查它是否符合你的情況。

只是爲了確保,要導出所有的3個變量在會話中,即

export AWS_ACCESS_KEY_ID="ASIAI******JQ" 
export AWS_SECRET_ACCESS_KEY="n******u1pRocjL" 
export AWS_SESSION_TOKEN="FQ*****vKJKTisUF" 

,或者如果你正在使用的憑據在本地機器上,你擁有所有的3個變量在那裏,太文件在默認情況下。

此外,因爲會話令牌的有效期爲默認間隔一小時,只是檢查,如果你的機器的時間不同步(極小的可能性,但值得一試。)

相關問題