Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to connect to region in boto3

Tags:

python

boto3

How can one achieve the boto command:

boto.ec2.connect_to_region()

using the boto3 suite? It seems not to be at a glance in the docs

I guess it's a simpler and more precise question than the extense answer you can find in the following post.

Thanks for any help

like image 972
Evhz Avatar asked Sep 04 '18 13:09

Evhz


People also ask

How do you fix Botocore exceptions Noregionerror you must specify a region?

noregionerror: you must specify a region error. The fix is you must specify a region. The quickest fix is to open your ~/. aws/config and add region=us-east-1 to the [default] profile.

What is boto3 session session ()?

class boto3.session. Session (aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, region_name=None, botocore_session=None, profile_name=None)[source] A session stores configuration state and allows you to create service clients and resources.

What are waiters in boto3?

Waiters: In the case of Boto3, there are some requests which are not instant. One such example is when you try to start or stop any instance. For such kinds of requests, you can initiate those requests and check back at some later time.


1 Answers

boto3 wants you to specify the region by default. So, the solutions for you in Python is:

>>> import boto3
>>> boto_client = boto3.client('ec2', region_name='us-west-2')

You can also set up a default region. In order to do so:

>>> import boto3
>>> boto_client = boto3.setup_default_session(region_name='us-west-2')
>>> boto_client = boto3.client('ec2')
like image 102
Sujil Maharjan Avatar answered Oct 30 '22 19:10

Sujil Maharjan