<p>You can benefit from EC2 inventory script provided by Ansible - <a href="https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py" rel="nofollow noreferrer">click</a>
It will allow you to to connect to all ec2-instances, one by one (in <code>serial: 1</code> mode)</p>

CC BY-SA 4.0
2018-06-12T12:30:27.300Z
2018-06-12T12:30:27.300Z
13dimitar
<p>Is there any way through which I can connect to all ec2-instances one by one through Python script to extract some server information from there. Please note that all ec2-instances lies behind a bastion host. Using shell script I can do that but how about python. Is there any specific library?</p>

CC BY-SA 4.0
2018-06-02T23:20:34.993Z
More information might be helpful, like whats the end result? You want to run commands on these servers? Why not use ansible?
Levi
CC BY-SA 4.0
2018-06-04T18:57:51.557Z
@Levi I need to extract some information from database.yml files residing in each ec2 instances
Prashast
<amazon-web-services><amazon-ec2><python>
Way to Connect to all ec2-instances one by one
Prashast
# Way to Connect to all ec2-instances one by one

(Asked by: username_0 on 2018-06-01)

Is there any way through which I can connect to all ec2-instances one by one through Python script to extract some server information from there. Please note that all ec2-instances lies behind a bastion host. Using shell script I can do that but how about python. Is there any specific library?

**Tags:** amazon-web-services, amazon-ec2, python

> **Comments:**
> **username_1**: More information might be helpful, like whats the end result? You want to run commands on these servers? Why not use ansible?  
> **username_0**: @username_1 I need to extract some information from database.yml files residing in each ec2 instances  

---

## 1 answers

### Answer by username_2 on 2018-06-12. Score: 0 | Accepted answer

You can benefit from EC2 inventory script provided by Ansible - [click](https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py)
It will allow you to to connect to all ec2-instances, one by one (in `serial: 1` mode)


---

