【发布时间】:2020-05-18 17:33:52
【问题描述】:
我最近开始学习 AWS EC2 服务,昨天我刚刚启动了一个 EC2 实例,描述了我的启动配置(附件 Review Launch Configurations),我能够成功 ssh 进入我的 pem 文件,但我也想启动 EC2 实例使用我做的boto3 python。但我无法通过以下脚本 SSH 进入 EC2 实例。
#!/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'])
上面的脚本可以启动 EC2 实例,但是我无法从 ubuntu 子系统登录。
到目前为止已完成的故障排除:获取了我从 AWS 页面启动的 EC2 的详细信息,使用 client.describe_instances() 并在上面定义了 client.run_istances()。
请教,为什么我通过上述脚本启动 EC2 实例时无法 ssh,而从 AWS 页面启动时我可以 ssh EC2。
非常感谢您在这方面的专业知识。
【问题讨论】:
标签: python-3.x amazon-web-services amazon-ec2 ssh boto3