Questions tagged [boto3]

Boto 3 - The Amazon Web Services (AWS) SDK for Python

About

Boto is the Amazon Web Services (AWS) software development kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. Boto provides an easy to use, object-oriented API as well as low-level direct service access.

Links

7627 questions
35
votes
2 answers

How to view Boto3 HTTPS request string

I have been able to view the attributes of the PreparedRequest that botocore sends, but I'm wondering how I can view the exact request string that is sent to AWS. I need the exact request string to be able to compare it to another application I'm…
zachhilbert
  • 639
  • 1
  • 5
  • 12
34
votes
5 answers

How to use Boto3 pagination

BACKGROUND: The AWS operation to list IAM users returns a max of 50 by default. Reading the docs (links) below I ran following code and returned a complete set data by setting the "MaxItems" to 1000. paginator =…
user45097
  • 561
  • 2
  • 7
  • 16
34
votes
2 answers

How to list available regions with Boto3 (Python)

As AWS expands and adds new regions, I'd like to have my code automatically detect that. Currently, the "Select your region" is hard coded but I would like to parse the following for just the RegionName. import boto3 ec2 =…
Shawn
  • 561
  • 1
  • 5
  • 12
34
votes
3 answers

Query DynamoDB with a hash key and a range key with Boto3

I am having trouble using AWS Boto3 to query DynamoDB with a hash key and a range key at the same time using the recommend KeyConditionExpression. I have attached an example query: import boto3 from boto3 import dynamodb from boto3.session import…
Sean Pannella
  • 343
  • 1
  • 3
  • 4
33
votes
5 answers

Update nested map dynamodb

I have a dynamodb table with an attribute containing a nested map and I would like to update a specific inventory item that is filtered via a filter expression that results in a single item from this map. How to write an update expression to update…
Nico Müller
  • 1,784
  • 1
  • 17
  • 37
33
votes
10 answers

Boto3 S3, sort bucket by last modified

I need to fetch a list of items from S3 using Boto3, but instead of returning default sort order (descending) I want it to return it via reverse order. I know you can do it via awscli: aws s3api list-objects --bucket mybucketfoo --query…
Nate
  • 1,630
  • 2
  • 24
  • 41
32
votes
3 answers

Adding type-hinting to functions that return boto3 objects?

How do I add type-hinting to my functions that return various boto3 resources? I'd like to get automatic completion/checking on my return values in IDEs like PyCharm. Boto3 does some factory creation magic so I can't figure out how to declare the…
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197
32
votes
8 answers

How do you use "NextToken" in AWS API calls

I've run into a little issue that I am really struggling to understand how it works. I have a tool I am writing that basically does a describe-organization to collect all the accounts in our AWS organization. Per the documentation here it says it…
Geoff Sweet
  • 603
  • 2
  • 6
  • 12
32
votes
7 answers

How to SSH and run commands in EC2 using boto3?

I want to be able to ssh into an EC2 instance, and run some shell commands in it, like this. How do I do it in boto3?
Dawny33
  • 10,543
  • 21
  • 82
  • 134
32
votes
4 answers

How to update metadata of an existing object in AWS S3 using python boto3?

boto3 documentation does not clearly specify how to update the user metadata of an already existing S3 Object.
arc000
  • 833
  • 1
  • 9
  • 16
32
votes
3 answers

How do I get the size of a boto3 Collection?

The way I have been using is to transform the Collection into a List and query the length: s3 = boto3.resource('s3') bucket = s3.Bucket('my_bucket') size = len(list(bucket.objects.all())) However, this forces resolution of the whole collection and…
Rahul Gupta-Iwasaki
  • 1,683
  • 2
  • 21
  • 39
30
votes
6 answers

"cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_'" on AWS Lambda using a layer

What I want to achieve To scrape an website using AWS Lambda and save the data on S3. The issues I'm having When I execute Lambda, the following error message appears. { "errorMessage": "Unable to import module 'lambda_function': cannot import…
dixhom
  • 2,419
  • 4
  • 20
  • 36
29
votes
5 answers

S3 giving me NoSuchKey error even when the key exists

This is my boto3 command for getting the object with a specific key from an S3 bucket: resp = s3client.get_object(Bucket='<>-<>', Key='MzA1MjY1NzkzX2QudHh0') It gives the following error: botocore.errorfactory.NoSuchKey: An error occurred…
Dawny33
  • 10,543
  • 21
  • 82
  • 134
29
votes
3 answers

Catching boto3 ClientError subclass

With code like the snippet below, we can catch AWS exceptions: from aws_utils import make_session session = make_session() cf = session.resource("iam") role = cf.Role("foo") try: role.load() except Exception as e: print(type(e)) raise…
Daniel Kats
  • 5,141
  • 15
  • 65
  • 102
29
votes
2 answers

Displaying EC2 Instance name using Boto 3

I'm not sure how to display the name of my instance in AWS EC2 using boto3 This is some of the code I have: import boto3 ec2 = boto3.resource('ec2', region_name='us-west-2') vpc = ec2.Vpc("vpc-21c15555") for i in vpc.instances.all(): …
Liondancer
  • 15,721
  • 51
  • 149
  • 255