-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildBaseAmi.yaml
64 lines (56 loc) · 1.99 KB
/
buildBaseAmi.yaml
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
Description: Create an AMI from an EC2 instance.
Parameters:
ImageId:
Description: Image ID for base EC2 instance.
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
InstanceType:
Description: Instance type to launch EC2 instances.
Type: String
# use a very small one for this
Default: t3.micro
AllowedValues: [ t3.micro, t3.small, t3.medium, t3.large, t3.xlarge ]
Resources:
# Completes when the instance is fully provisioned and ready for AMI creation.
AMICreate:
Type: AWS::CloudFormation::WaitCondition
CreationPolicy:
ResourceSignal:
Timeout: PT10M
Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
# BlockDeviceMappings:
# - DeviceName: "/dev/xvda"
# Ebs:
# VolumeSize: '10'
# VolumeType: gp2
UserData:
"Fn::Base64": !Sub |
#!/bin/bash -x
# put script here for what to add to ami
#update
sudo yum update -y
#install docker
sudo amazon-linux-extras install docker
# start service
sudo service docker start
# add docker permissions to user
sudo usermod -a -G docker ec2-user
sudo chkconfig docker on
# add docker compose
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# signal the finishing of the ami
/opt/aws/bin/cfn-signal \
-e $? \
--stack ${AWS::StackName} \
--region ${AWS::Region} \
--resource AMICreate
# shutdown so the ami can be created
shutdown -h now
Outputs:
Instance:
Value: !Ref Instance