Created
September 28, 2020 21:36
-
-
Save jonathanhle/e2af40ad8fa765b29eb5f4252875754e to your computer and use it in GitHub Desktop.
stop_start_ec2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 | |
| import timeit | |
| region = 'us-east-1' | |
| instances = ['i-0d1044d1adfasdasda'] | |
| ec2_client = boto3.client('ec2', region_name=region) | |
| waiter_stop = ec2_client.get_waiter('instance_stopped') | |
| waiter_okay = ec2_client.get_waiter('instance_status_ok') | |
| def stop_start_ec2(): | |
| ec2_client.stop_instances(InstanceIds=instances) | |
| waiter_stop.wait(InstanceIds=instances) | |
| print('stopped your instances: ' + str(instances)) | |
| ec2_client.start_instances(InstanceIds=instances) | |
| waiter_okay.wait(InstanceIds=instances) | |
| print('started your instances: ' + str(instances)) | |
| if __name__ == "__main__": | |
| print(timeit.timeit(stop_start_ec2, number=1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment