-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_launch_config.rb
63 lines (50 loc) · 1.66 KB
/
create_launch_config.rb
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
require File.expand_path(File.dirname(__FILE__) + '/config')
(vpc_id, dummy) = ARGV
unless vpc_id
puts "Usage: create_launch_config <VPC_ID>"
exit 1
end
ec2Client = Aws::EC2::Client::new
#Use our custom AMI id
ami_id = 'ami-c49174ac'
#Copy out war into the tomcat webapps directory when the instance is
#spun up - user data is the following two lines base-64 encoded.
#$!/bin/sh
#aws s3 cp s3://xt-war-buckets/b2bnext-webapp.war /var/lib/tomcat7/webapps
user_data = 'IyEvYmluL3NoDQphd3MgczMgY3AgczM6Ly94dC13YXItYnVja2V0cy9iMmJuZXh0LXdlYmFwcC53YXIgL3Zhci9saWIvdG9tY2F0Ny93ZWJhcHBz'
#Need the security group name
sg_infos = ec2Client.describe_security_groups({
:filters => [
{
:name => "vpc-id",
:values => [vpc_id]
}
]
})[:security_groups]
private_launch_sg = (sg_infos.select {
|sg| sg[:group_name] == "private-subnet-launch-sg"
}).first[:group_id]
puts "private launch security group id #{private_launch_sg}"
asgClient = Aws::AutoScaling::Client::new
asgClient.create_launch_configuration({
:launch_configuration_name => "b2bnext-launch-config",
:image_id => ami_id,
:key_name => "chef",
:security_groups => [private_launch_sg],
:user_data => user_data,
:instance_type => "t1.micro",
:associate_public_ip_address => false,
:instance_monitoring => { :enabled => false },
:block_device_mappings=>[
{
:device_name=>"/dev/sda1",
:ebs=>
{
:delete_on_termination=>true,
:volume_type=>"standard",
:volume_size=>8
}
}
],
:iam_instance_profile => 'arn:aws:iam::930295567417:instance-profile/war-deployer-role'
})