Logging into a AWS instance using boto3 library of python
<p>I am attempting to write a python code that would few of my manual steps in logging into the AWS platform. </p>

<p>In Ubuntu terminal , I used to write the command</p>

<pre><code>ssh -A ec2-user@&lt;ip-address&gt;
</code></pre>

<p>and then again log into another instance using</p>

<pre><code>ssh ec2-user@&lt;ip.address&gt;
</code></pre>

<p>Now I am looking at python code that would be able to automate this logging in process. I have written the following code till now.</p>

<pre><code>import boto3
ec2 = boto3.resource('ec2')
</code></pre>

<p>If you want to perform actions on a running instance, boto3 is not what you're looking for.  What you're asking about is more in the realm of what's called <em>configuration management</em>.</p>

<p>While you could write something yourself using an SSH library like <a href="http://www.paramiko.org/" rel="nofollow">Paramiko</a>, you may want to look at a more purpose-built software package like <a href="http://www.fabfile.org/" rel="nofollow">Fabric</a>.  It's built on-top of the aforementioned Paramiko, with added functionality tailored to running commands on remote servers. For a more full-featured, open source configuration management solution, I recommend looking into <a href="https://www.ansible.com/" rel="nofollow">Ansible</a>.</p>

<p>AWS also has a native service for configuring EC2 instances called <a href="https://aws.amazon.com/ec2/run-command/" rel="nofollow">EC2 Run Command</a>.</p>

python amazon-web-services amazon-ec2 boto3