Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Source Code:

To create a startEC2 instance:

import boto3
region = 'us-east-1'
instances = ['i-07a02o78cbbe1af09’]
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))

To create a stopEC2 instance:

import boto3
region = 'us-east-1'
instances = ['i-07a02o78cbbe1af09’]
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances)

You might also like