Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify aws region within boto program?

I want to list the ec2 instances in aws account with boto module.I am getting the issue as

"You must specify a region".Here is the program.

import boto3
ec2 = boto3.resource('ec2')
for instance in ec2.instances.all()
print instance.id, instance.state

I didn't specify any default region. How can I specify it programmatically ?

like image 507
nagurameer Avatar asked Sep 02 '25 09:09

nagurameer


1 Answers

Since you are using the resource interface, your code will look like this:

import boto3
ec2 = boto3.resource('ec2', region_name = 'us-west-2')
for instance in ec2.instances.all()
    print instance.id, instance.state
like image 190
John Hanley Avatar answered Sep 05 '25 00:09

John Hanley