Skip to content

Commit 61fb134

Browse files
author
adamkaygray
committed
ami id, docker ports, instance type
1 parent 0d089a5 commit 61fb134

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

awsdeploy.yml

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Resources:
2424
App:
2525
Type: 'AWS::EC2::Instance'
2626
Properties:
27-
InstanceType: t2.micro
28-
ImageId: ami-0ac019f4fcb7cb7e6
27+
InstanceType: !Ref InstanceType
28+
ImageId: !Ref Ubuntu16Ami
2929
KeyName: !Ref KeyName
3030
SecurityGroups:
3131
- !Ref AppSG
@@ -84,14 +84,75 @@ Resources:
8484
- |
8585
sudo docker pull chakkiworks/doccano:latest
8686
- >
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
8888
chakkiworks/doccano:latest
8989
- >
9090
sudo docker exec doccano tools/create-admin.sh ${ADMIN} ${EMAIL}
9191
${PASSWORD}
9292
Metadata:
9393
'AWS::CloudFormation::Designer':
9494
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"
95156
Metadata:
96157
'AWS::CloudFormation::Designer':
97158
116a7f7b-14c5-489a-a3c8-faf276be7ab0:
@@ -124,6 +185,9 @@ Parameters:
124185
- t2.micro
125186
- t2.small
126187
- t2.medium
188+
- t3.micro
189+
- t3.small
190+
- t3.medium
127191
ConstraintDescription: must be a valid EC2 instance type.
128192
KeyName:
129193
Description: Name of an EC2 KeyPair to enable SSH access to the instance.

0 commit comments

Comments
 (0)