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>There are 2 ways mostly to configure the boto3 library.</p>

<ol>
<li><p>You need to configure it first on your system and use the same configuration everywhere. You can use <a href="http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html" rel="nofollow"><strong>AWS CLI</strong></a> for this by running <code>aws configure</code> on your terminal.</p></li>
<li><p>Set the environment variables and call the boto3 configuration via <code>process.env.ENV_KEY</code> and then use it like : </p></li>
</ol>

<p><code>
client = boto3.client(
    'ec2',
    aws_access_key_id=process.env.ACCESS_KEY,
    aws_secret_access_key=process.env.SECRET_KEY,
    aws_session_token=process.env.SESSION_TOKEN,
)
</code></p>

python amazon-web-services amazon-ec2 boto3