0
votes

I am recently started learning AWS EC2 Services, Yesterday I just launched an EC2 Instance describing my launch configurations (attached Review Launch Configurations), and I am able to successfully ssh into my pem file, But I also wanted to Launch EC2 instance using boto3 python, which I did. But I can't ssh into EC2 instance launched through the below script.

#!/usr/bin/python

import boto3
client = boto3.client('ec2')
response = client.run_instances(
BlockDeviceMappings=[
    {
        'DeviceName' :'/dev/xvda',
        'Ebs' : {
            'DeleteOnTermination' : True,
        },
    },
    ],

ImageId= 'ami-04590e7389a6e577c',
InstanceType= 't2.micro',
KeyName= 'ec2-keypair',
MaxCount = 1,
MinCount = 1,
Monitoring={
    'Enabled' : False
},

 )

for instance in response['Instances']:
     print(instance['InstanceId'])

The above script is able to launch EC2 instance , but I unable to login from ubuntu subsystem.

Troubleshooting done so far: Grabbed the details of the EC2 I launched from AWS page, using client.describe_instances() and defined client.run_istances() above.

Please educate, why I am unable to ssh if I launch EC2 instance through above script whereas I can ssh EC2 when launched from AWS Page.

I really appreciate your Expertise on this.

Security Group

1

1 Answers

2
votes

Your run_instances() is not showing a Security Group to attach. Therefore, no access will be available.

When launching an Amazon EC2 instance through the management console, there is a default "Launch Wizard" Security Group provided that includes SSH (port 22) inbound access, as shown in your question.

If you want to permit this for the instance launched via code, you will need to reference an existing Security Group that has the desired ports open.