Skip to content

Start/Stop EC2 using Lambda function #10516

Answered by mdazfar2
NitishKumar525 asked this question in Q&A
Discussion options

You must be logged in to vote

The error message you're encountering suggests there's an issue with the endpoint URL. The region name you provided seems incorrect. AWS regions typically follow the format us-east-2, us-east-2c is not a valid region name.

 import boto3

region = 'us-east-2'  
instances = ['i-081929e311352ba0c']
ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
    ec2.stop_instances(InstanceIds=instances)
    print('Stopped your instances: ' + str(instances))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NitishKumar525
Comment options

Answer selected by NitishKumar525
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants