я новая пчела в python, я создал простой python скрипт, используя библиотеку Boto3 для AWS. Я просто создаю новый сервер Ec2, используя boto3, который работает нормально, но мне нужно использовать результат печати и передать этот результат в другой блок кода, который завершит Ec2. Итак, мой код выглядит так:
import boto3
import botocore
import sys
import time
import threading
ec2 = boto3.resource('ec2')
client = boto3.client('ec2')
# create a new Ec2 instance-AWS AMI Image
create = ec2.create_instances(
ImageId='ami-041bdd9e494102',
MinCount=1,
MaxCount=1,
InstanceType='t2.micro',
KeyName='xyz',
SubnetId='subnet-1233541')
time.sleep(25)
instances = ec2.instances.filter(
Filters=[{
'Name': 'instance-state-name',
'Values': ['running', 'stopped']}]
)
for instance in instances:
time.sleep(20)
print(instance.id, instance.instance_type, instance.state)`
## SO HERE I WANTED to execute the below code which will run after AFTER 40 Seconds and terminate the Instance which was launched previously
ec2.instances.filter(InstanceIds=ids).terminate()