boto3 / s3 - how can you connect with uid/pwd in like you could previously ?

Multi tool use


boto3 / s3 - how can you connect with uid/pwd in like you could previously ?
I have some code which I want to port to boto3.
Previously it was possible to do this :
conn = boto.connect_s3(sys.argv[1], sys.argv2)
In the current documentation it's assumed that you have a config file setup with the uid/pwd in it or that you use environment variables and so there is no explicit passing of the uid/pwd when initiating a connection.
Is it now impossible to to just pass in the values as per my example or is there some way I've missed in the documentation ?
Thanks
1 Answer
1
When writing AWS Python code, the SDK can automatically find your AWS credentials. If you have setup the AWS CLI, then the credentials are stored in ~/.aws/credentials.
In your code, the first two parameters are aws_access_key_id and aws_secret_access_key. This stays the same when moving from boto to boto3.
Compare the following code. The first is for boto (your example) and the second is for boto3.
BOTO Example:
import boto
conn = boto.connect_s3(
aws_access_key_id='<aws access key>',
aws_secret_access_key='<aws secret key>')
for bucket in conn.get_all_buckets():
print(bucket.name)
BOTO3 Example:
import boto3
client = boto3.client(
's3',
aws_access_key_id='<aws access key>',
aws_secret_access_key='<aws secret key>')
response = client.list_buckets()
for bucket in response['Buckets']]
print(bucket['Name'])
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
See: Credentials — Boto 3 Docs documentation
– John Rotenstein
20 mins ago