This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
141 lines (131 loc) · 3.71 KB
/
template.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
apiDockerImage:
Type: String
Resources:
UserTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: id
KeyType: HASH
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
BoardTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: id
KeyType: HASH
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: !ImportValue TestVpc
GroupDescription: hyperbol-api
SecurityGroupIngress:
- SourceSecurityGroupId: !ImportValue HyperbolElbSecurityGroup
Description: allow http from loadbalancer
FromPort: 8000
IpProtocol: tcp
ToPort: 8000
TaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: sts:AssumeRole
Path: !Sub "/${AWS::StackName}/"
Policies:
- PolicyName: DynamoDb
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
Resource:
- !GetAtt UserTable.Arn
- !GetAtt BoardTable.Arn
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 60
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Image: !Ref apiDockerImage
Name: api
Command:
- run
- server
PortMappings:
- ContainerPort: 8000
Protocol: tcp
Environment:
- Name: USER_TABLE
Value: !Ref UserTable
- Name: BOARD_TABLE
Value: !Ref BoardTable
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: api
Cpu: "256"
ExecutionRoleArn: !ImportValue HyperbolApiTaskExecutionRole
Memory: "512"
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
TaskRoleArn: !GetAtt TaskRole.Arn
Cluster:
Type: AWS::ECS::Cluster
Service:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref Cluster
DesiredCount: 1
LaunchType: FARGATE
PlatformVersion: "1.3.0"
PropagateTags: TASK_DEFINITION
TaskDefinition: !Ref TaskDefinition
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- !Ref SecurityGroup
Subnets:
- !ImportValue TestVpcSubnetPrivateA
- !ImportValue TestVpcSubnetPrivateB
- !ImportValue TestVpcSubnetPrivateC
LoadBalancers:
- ContainerName: api
ContainerPort: 8000
TargetGroupArn: !ImportValue HyperbolTargetGroup