Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

python - Boto3: AuthFailure when trying to query AWS with EC2 Client

I've created a small python script that is just querying the AWS spot pricing for certain instances, this was working yesterday and has been for the past week. However despite using different credentials the machine I'm running this against is receiving the following error:

aws_query = client.describe_spot_price_history(
        StartTime=today,
        EndTime=today,
        InstanceTypes=[
            'g2.2xlarge'
        ],
        ProductDescriptions=[
            'Linux/UNIX',
        ],
        MaxResults=3
    )

This returns the following:

botocore.exceptions.ClientError: An error occurred (AuthFailure) when calling the DescribeSpotPriceHistory operation: AWS was not able to validate the provided access credentials

I understand the error, but it makes no sense. The IAM role associated with the instance this is running from definitely has permissions to do this.

There have been no changes that I can think of that would impact this.

Note, this script runs from my local machine fine.

Does anyone have any ideas what may have caused this?

As an alternative - Does anyone know how I can ask Boto3 to confirm the credentials it is using?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First check the instance has an IAM role associated with it:

curl http://169.254.169.254/latest/meta-data/iam/info

If you want to get the temporary credentials for the instance, try this:

import boto3
print boto3.Session().get_credentials().access_key
print boto3.Session().get_credentials().secret_key

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...