Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import sys
  2. import boto3
  3.  
  4. DEV_ID = 'XXX'
  5. DEV2_ID = 'XXX'
  6.  
  7. mode = sys.argv[1]
  8. instance_name = sys.argv[2]
  9. if instance_name == 'dev':
  10. instance_ids = [DEV_ID]
  11. elif instance_name == 'dev2':
  12. instance_ids = [DEV2_ID]
  13. elif instance_name == 'all':
  14. instance_ids = [DEV_ID, DEV2_ID]
  15.  
  16. client = boto3.client('ec2', region_name='ap-northeast-1')
  17. if mode == 'check':
  18. res = client.describe_instances(InstanceIds=instance_ids)
  19. for r in res['Reservations']:
  20. i = r['Instances'][0]
  21. if i['InstanceId'] == DEV_ID:
  22. print('dev', i['State'])
  23. elif i['InstanceId'] == DEV2_ID:
  24. print('kaggle', i['State'])
  25. elif mode == 'start':
  26. client.start_instances(InstanceIds=instance_ids)
  27. elif mode == 'stop':
  28. client.stop_instances(InstanceIds=instance_ids)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement