xxxxxxxxxx
import boto3
ec2 = boto3.client('ec2')
response = ec2.terminate_instances(
InstanceIds=[
'your_ec2_instance_id'
]
)
print(response)
xxxxxxxxxx
import boto3
# Configure the region and your AWS credentials
ec2 = boto3.resource('ec2', region_name='us-west-2')
# Specify the instance ID to delete
instance_id = 'i-0123456789abcdef0'
# Stop the EC2 instance before deleting it (optional but recommended)
ec2.Instance(instance_id).stop()
# Terminate (delete) the EC2 instance
ec2.Instance(instance_id).terminate()