mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import boto3
|
|
import argparse
|
|
|
|
|
|
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
|
|
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
|
|
AWS_REGION = os.environ['AWS_REGION']
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--tag", help="tag instances in aws")
|
|
args = parser.parse_args()
|
|
|
|
if args.tag:
|
|
tag = args.tag
|
|
else:
|
|
# reading credentials from config for remote connection
|
|
print('usage: python get_instance_status.py --tag <tag>')
|
|
print('reason: tag missing!!!')
|
|
exit(1)
|
|
|
|
# Connect to Amazon EC2
|
|
ec2 = boto3.resource(service_name='ec2',
|
|
region_name=AWS_REGION,
|
|
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
|
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
|
|
|
|
# Get a list of all instances with the specified tag.
|
|
# (Technically, instances_with_tag is an ec2.instancesCollection.)
|
|
instances_with_tag = ec2.instances.filter(
|
|
Filters=[{'Name': 'tag:Name', 'Values': [tag]}]
|
|
)
|
|
print('The instances with tag {} have these ids:'.format(tag))
|
|
for instance in instances_with_tag:
|
|
print(instance.id)
|
|
|
|
print('Waiting until all those instances exist...')
|
|
for instance in instances_with_tag:
|
|
instance.wait_until_exists()
|
|
|
|
print('Waiting until all those instances are running...')
|
|
for instance in instances_with_tag:
|
|
instance.wait_until_running()
|