user3435964
user3435964

Reputation: 949

how to use system environment variables in boto

I have exported AWS ACCESS KEY and SECRET via the environment variables, is there way to use those variables in the boto script instead of writing them to a file on the system? I don't want to write the key and secret in any file on the remote server.

Upvotes: 7

Views: 13405

Answers (3)

Ajay Renganathan
Ajay Renganathan

Reputation: 31

Update: In 2024 we use IAM instance role in AWS to set permissions for EC2 instances to access S3.

See: IAM roles for Amazon EC2 - Amazon Elastic Compute Cloud

Upvotes: 2

sysconfig
sysconfig

Reputation: 1407

If by use you mean read them and feed them into boto: You don't need to do that. Boto reads them, and in all calls which would usually expect the aws_access_key_id= and aws_secret_access_key= parameters, you just leave them out altogether. Hence a call like this would work without problems:

# note that we don't pass any credentials here...

conn = boto.ec2.connect_to_region("eu-west-1")

Just be sure the environment variables are set correctly. These are the correct names to use:

AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY

More details here: http://boto.readthedocs.org/en/latest/boto_config_tut.html#introduction

Upvotes: 10

garnaat
garnaat

Reputation: 45916

Boto looks for the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and, if they are present in the environment, it will use them.

Upvotes: 7

Related Questions