@@ -24,8 +24,8 @@ Resources:
24
24
App :
25
25
Type : ' AWS::EC2::Instance'
26
26
Properties :
27
- InstanceType : t2.micro
28
- ImageId : ami-0ac019f4fcb7cb7e6
27
+ InstanceType : !Ref InstanceType
28
+ ImageId : !Ref Ubuntu16Ami
29
29
KeyName : !Ref KeyName
30
30
SecurityGroups :
31
31
- !Ref AppSG
@@ -84,14 +84,75 @@ Resources:
84
84
- |
85
85
sudo docker pull chakkiworks/doccano:latest
86
86
- >
87
- sudo docker run -d --name doccano --env-file /env.list -p 80:80
87
+ sudo docker run -d --name doccano --env-file /env.list -p 80:8000
88
88
chakkiworks/doccano:latest
89
89
- >
90
90
sudo docker exec doccano tools/create-admin.sh ${ADMIN} ${EMAIL}
91
91
${PASSWORD}
92
92
Metadata :
93
93
' AWS::CloudFormation::Designer ' :
94
94
id : 3547c02e-5393-4b26-a9af-6f00dc2cbcdb
95
+ DescribeImagesRole :
96
+ Type : AWS::IAM::Role
97
+ Properties :
98
+ AssumeRolePolicyDocument :
99
+ Version : ' 2012-10-17'
100
+ Statement :
101
+ - Action : sts:AssumeRole
102
+ Effect : Allow
103
+ Principal :
104
+ Service : lambda.amazonaws.com
105
+ ManagedPolicyArns :
106
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
107
+ Policies :
108
+ - PolicyName : DescribeImages
109
+ PolicyDocument :
110
+ Version : ' 2012-10-17'
111
+ Statement :
112
+ - Action : ec2:DescribeImages
113
+ Effect : Allow
114
+ Resource : " *"
115
+ GetLatestAMI :
116
+ Type : AWS::Lambda::Function
117
+ Properties :
118
+ Runtime : python3.6
119
+ Handler : index.handler
120
+ Role : !Sub ${DescribeImagesRole.Arn}
121
+ Timeout : 60
122
+ Code :
123
+ ZipFile : |
124
+ import boto3
125
+ import cfnresponse
126
+ import json
127
+ import traceback
128
+
129
+ def handler(event, context):
130
+ try:
131
+ response = boto3.client('ec2').describe_images(
132
+ Owners=[event['ResourceProperties']['Owner']],
133
+ Filters=[
134
+ {'Name': 'name', 'Values': [event['ResourceProperties']['Name']]},
135
+ {'Name': 'architecture', 'Values': [event['ResourceProperties']['Architecture']]},
136
+ {'Name': 'root-device-type', 'Values': ['ebs']},
137
+ ],
138
+ )
139
+
140
+ amis = sorted(response['Images'],
141
+ key=lambda x: x['CreationDate'],
142
+ reverse=True)
143
+ id = amis[0]['ImageId']
144
+
145
+ cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, id)
146
+ except:
147
+ traceback.print_last()
148
+ cfnresponse.send(event, context, cfnresponse.FAIL, {}, "ok")
149
+ Ubuntu16Ami :
150
+ Type : Custom::FindAMI
151
+ Properties :
152
+ ServiceToken : !Sub ${GetLatestAMI.Arn}
153
+ Owner : " 099720109477"
154
+ Name : " ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20190913"
155
+ Architecture : " x86_64"
95
156
Metadata :
96
157
' AWS::CloudFormation::Designer ' :
97
158
116a7f7b-14c5-489a-a3c8-faf276be7ab0 :
@@ -124,6 +185,9 @@ Parameters:
124
185
- t2.micro
125
186
- t2.small
126
187
- t2.medium
188
+ - t3.micro
189
+ - t3.small
190
+ - t3.medium
127
191
ConstraintDescription : must be a valid EC2 instance type.
128
192
KeyName :
129
193
Description : Name of an EC2 KeyPair to enable SSH access to the instance.
0 commit comments