How do I validate my Amazon passkey and secret?

I wrote a function to test AWS keys by simply creating an ec2 connection object

import boto.ec2 try: ec2Conn = boto.ec2.connect_to_region(region, aws_access_key_id=access_key, aws_secret_access_key=secret_key) return ec2Conn except boto.exception.EC2ResponseError as e: print e 

But even if the secret key is wrong, it creates an ec2 connection object.

So, I check the access key and the secret key, extracting the areas,

 region = ec2Conn.get_all_regions() 

Is there any method or method, and not a selection area, for checking the access key and secret key?

+7
source share
1 answer

The only way to verify AWS credentials is to actually use them to sign the request and see if it works. You are right that just creating a connection object does not say anything because it does not fulfill the request. Therefore, you need to select some kind of request that should always work, will not return a huge amount of data and does not create any resources on the server side. I think get_all_regions() is a pretty good choice.

+10
source

All Articles