I have been creating AWS EC2 instances using Ubuntu and Boto for months. They start-up, I issue commands from Python etc. This has been working fine.
I create the instances using this:
instances = ec2.create_instances(
ImageId=image_id,
MinCount=1,
MaxCount=num_instances,
InstanceType=instance_type,
IamInstanceProfile={ 'Name': 'SSMInstanceProfile' },
Placement={'AvailabilityZone': availability_zone}
Today I created and downloaded a private key file from EC2 console. I then created another instance using Boto (exactly how I have been doing previously).
I got the public DNS address from the console and tried to ssh on to it from my local machine using:
ssh -i /path/to/private/key.pem ec2-user@1.2.3.4.region.compute.amazonaws.com
etc
Nothing happened, the command line just hung.
Do I need to change how I create my boto instances, to accept the new .pem
key file?
If not, do I need to change something in the EC2 console to map SSMInstanceProfile
to be SSH'd using that .pem
?
When attempting to SSH into an Amazon EC2 instance, a 'hanging' response indicates that your SSH client was unable to connect to the instance. (If it did connect, but the connection was refused, the error would appear immediately.)
Things to check:
0.0.0.0/0
)Most times, the problem is related to the Security Group. Instead of using the Default security group, I recommend that you create a new Security Group with:
0.0.0.0/0
)Or, instead of attempting to connect via SSH, you could use AWS Systems Manager Session Manager. Please note that this requires some permissions to be added to the IAM Role associated with the EC2 instance. See: Add instance permissions for Session Manager