尝试从 python 函数实例启动实例时没有启动,但没有收到 python 语法错误。
region = 'us-east-2'
ec2 = boto3.client('ec2')
ec2 = boto3.resource('ec2')
client = boto3.client('ec2')
def lambda_handler(event, context):
response = client.describe_images(
Filters=[
{
'Name': 'description',
'Values': [
'lambdaami',
]
},
],
Owners=[
'self'
]
)
AMI = sorted(response['Images'], key=lambda x: x['CreationDate'], reverse=True)
print AMI[0]['ImageId']
INSTANCE = ec2.create_instance(ImageId='ImageId', InstanceType='t2.micro', MinCount=1, MaxCount=1)
print (INSTANCE[0].id)```
Kindly help.....
答案1
我已经通过帮助社区解决了这个问题,这里是代码。
import boto3
ec2 = boto3.resource('ec2', region_name='us-east-2')
def lambda_handler(event, context):
images = ec2.images.filter(
Filters=[
{
'Name': 'description',
'Values': [
'lambdaami',
]
},
],
Owners=[
'self'
])
AMI = sorted(images, key=lambda x: x.creation_date, reverse=True)
IMAGEID = AMI[0].image_id
INSTANCE = ec2.create_instances(ImageId=IMAGEID, InstanceType='t2.micro', MinCount=1, MaxCount=1)
print(INSTANCE[0].image_id)```