-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-instances.py
76 lines (67 loc) · 2.59 KB
/
create-instances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import boto3,argparse,json,getpass
parser = argparse.ArgumentParser()
parser.add_argument("--application", "-a", choices=['cassandra', 'matching', 'history', 'frontend', 'stress', 'statsd'], required=True, help='application type that will be created')
parser.add_argument("--num", type=int, default=1, help='number of instances that will be created')
parser.add_argument("--instance-type", default='t2.medium')
parser.add_argument("--disk-size", type=int, default=30, help="disk size in GiB")
parser.add_argument("--ec2-image", default='ami-4fffc834', help="ec2 image to install on instance")
parser.add_argument("--key-name", required=True, help="AWS keypair for EC2 instance(make sure you have the private key(pem file))")
parser.add_argument("--subnet-id", required=True, help="AWS subnet-id")
parser.add_argument("--security-group-id", required=True, help="AWS security-group-id")
parser.add_argument("--deployment-group", "-d", default='cadence-dev-{username}-'.format(username=getpass.getuser()), help="Use the same group for the EC2 instances you created. This is implemented as a name prefix of EC2 tag")
args = parser.parse_args()
ec2 = boto3.client('ec2')
#response = ec2.describe_instances()
print 'Going to request an on-demand EC2 instance...'
response = ec2.run_instances(
BlockDeviceMappings=[
{
'DeviceName': '/dev/xvda',
'Ebs': {
'DeleteOnTermination': True,
# Use default of gp2 is 100/3000
#'Iops': 100,
# need bigger for Cassandra
'VolumeSize': args.disk_size,
'VolumeType': 'gp2'
}
},
],
ImageId=args.ec2_image,
InstanceType=args.instance_type,
KeyName=args.key_name,
MaxCount=args.num,
MinCount=args.num,
Monitoring={
'Enabled': True
},
# Will be needed for EBS optimized instances(R4)
#EbsOptimized=True,
NetworkInterfaces=[
{
'AssociatePublicIpAddress': True,
'DeleteOnTermination': True,
'DeviceIndex': 0,
'SubnetId': args.subnet_id,
"Groups": [ args.security_group_id ]
},
],
TagSpecifications=[
{
'ResourceType' : 'instance',
'Tags': [
{
'Key': 'Name',
'Value': args.deployment_group+args.application
},
]
},
],
UserData=''
)
#print for debug
#print response
for ins in response['Instances']:
print "###"
print ins['InstanceId']
print ins['NetworkInterfaces'][0]['PrivateIpAddresses']