1 | AWSTemplateFormatVersion: '2010-09-09'
|
2 | Description: 'stack: {{stackName}} | deployed by Kes'
|
3 |
|
4 | Resources:
|
5 |
|
6 |
|
7 |
|
8 | {{#each dynamos}}
|
9 | {{@key}}DynamoDB:
|
10 | Type: AWS::DynamoDB::Table
|
11 | DeletionPolicy: Retain
|
12 | Properties:
|
13 | AttributeDefinitions:
|
14 | {{#each this.attributes}}
|
15 | - AttributeName: {{name}}
|
16 | AttributeType: {{type}}
|
17 | {{/each}}
|
18 | KeySchema:
|
19 | {{#if this.KeySchema}}
|
20 | {{#each this.KeySchema}}
|
21 | - AttributeName: {{this.AttributeName}}
|
22 | KeyType: {{this.KeyType}}
|
23 | {{/each}}
|
24 | {{else}}
|
25 | {{#each this.attributes}}
|
26 | - AttributeName: {{name}}
|
27 | KeyType: {{schema}}
|
28 | {{/each}}
|
29 | {{/if}}
|
30 | ProvisionedThroughput:
|
31 | ReadCapacityUnits: {{this.read}}
|
32 | WriteCapacityUnits: {{this.write}}
|
33 | TableName: {{../prefix}}-{{@key}}
|
34 | StreamSpecification:
|
35 | StreamViewType: "NEW_AND_OLD_IMAGES"
|
36 | {{#if this.GlobalSecondaryIndexes}}
|
37 | GlobalSecondaryIndexes:
|
38 | {{#each this.GlobalSecondaryIndexes}}
|
39 | - IndexName: {{IndexName}}
|
40 | KeySchema:
|
41 | {{#each this.KeySchema}}
|
42 | - AttributeName: {{this.AttributeName}}
|
43 | KeyType: {{this.KeyType}}
|
44 | {{/each}}
|
45 | {{#if this.Projection}}
|
46 | Projection:
|
47 | {{#each this.Projection}}
|
48 | {{@key}}: {{this}}
|
49 | {{/each}}
|
50 | {{/if}}
|
51 | ProvisionedThroughput:
|
52 | ReadCapacityUnits: {{../read}}
|
53 | WriteCapacityUnits: {{../write}}
|
54 | {{/each}}
|
55 | {{/if}}
|
56 |
|
57 | {{/each}}
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | {{# each dynamos}}
|
68 | {{#if this.enableAutoScaling}}
|
69 |
|
70 | {{@key}}ReadCapacityScalableTarget:
|
71 | Type: "AWS::ApplicationAutoScaling::ScalableTarget"
|
72 | Properties:
|
73 | {{#if this.ReadMinCapacity}}
|
74 | MinCapacity: {{ this.ReadMinCapacity }}
|
75 | {{else}}
|
76 | MinCapacity: 5
|
77 | {{/if}}
|
78 | {{#if this.ReadMaxCapacity}}
|
79 | MaxCapacity: {{ this.ReadMaxCapacity }}
|
80 | {{else}}
|
81 | MaxCapacity: 10
|
82 | {{/if}}
|
83 | ResourceId:
|
84 | Fn::Sub: table/{{../../prefix}}-{{@key}}
|
85 | RoleARN: {{../../iams.scalingRoleArn}}
|
86 | ScalableDimension: "dynamodb:table:ReadCapacityUnits"
|
87 | ServiceNamespace: dynamodb
|
88 | {{@key}}TableReadScalingPolicy:
|
89 | Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
|
90 | Properties:
|
91 | PolicyName: ReadAutoScalingPolicy
|
92 | PolicyType: TargetTrackingScaling
|
93 | ScalingTargetId:
|
94 | Ref: {{@key}}ReadCapacityScalableTarget
|
95 | TargetTrackingScalingPolicyConfiguration:
|
96 | TargetValue: {{ ../../AutoScalingPolicyConfiguration.targetValue }}
|
97 | ScaleInCooldown: {{ ../../AutoScalingPolicyConfiguration.scaleInCooldown }}
|
98 | ScaleOutCooldown: {{ ../../AutoScalingPolicyConfiguration.scaleOutCooldown }}
|
99 | PredefinedMetricSpecification:
|
100 | PredefinedMetricType: DynamoDBReadCapacityUtilization
|
101 |
|
102 |
|
103 | {{@key}}WriteCapacityScalableTarget:
|
104 | Type: "AWS::ApplicationAutoScaling::ScalableTarget"
|
105 | Properties:
|
106 | {{#if this.WriteMinCapacity}}
|
107 | MinCapacity: {{ this.WriteMinCapacity }}
|
108 | {{else}}
|
109 | MinCapacity: 1
|
110 | {{/if}}
|
111 | {{#if this.WriteMaxCapacity}}
|
112 | MaxCapacity: {{ this.WriteMaxCapacity }}
|
113 | {{else}}
|
114 | MaxCapacity: 2
|
115 | {{/if}}
|
116 | ResourceId:
|
117 | Fn::Sub: table/{{../../prefix}}-{{@key}}
|
118 | RoleARN: {{../../iams.scalingRoleArn}}
|
119 | ScalableDimension: "dynamodb:table:WriteCapacityUnits"
|
120 | ServiceNamespace: dynamodb
|
121 | {{@key}}TableWriteScalingPolicy:
|
122 | Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
|
123 | Properties:
|
124 | PolicyName: WriteAutoScalingPolicy
|
125 | PolicyType: TargetTrackingScaling
|
126 | ScalingTargetId:
|
127 | Ref: {{@key}}WriteCapacityScalableTarget
|
128 | TargetTrackingScalingPolicyConfiguration:
|
129 | TargetValue: {{ ../../AutoScalingPolicyConfiguration.targetValue }}
|
130 | ScaleInCooldown: {{ ../../AutoScalingPolicyConfiguration.scaleInCooldown }}
|
131 | ScaleOutCooldown: {{ ../../AutoScalingPolicyConfiguration.scaleOutCooldown }}
|
132 | PredefinedMetricSpecification:
|
133 | PredefinedMetricType: DynamoDBWriteCapacityUtilization
|
134 | {{/if}}
|
135 | {{/each}}
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | {{# if es.name}}
|
142 |
|
143 |
|
144 |
|
145 | {{es.name}}Domain:
|
146 | Type: "AWS::Elasticsearch::Domain"
|
147 | DeletionPolicy: Retain
|
148 | Properties:
|
149 | DomainName: {{prefix}}-{{es.name}}
|
150 | ElasticsearchVersion: {{# if es.version}}{{es.version}}{{ else }}'5.3'{{/if}}
|
151 | ElasticsearchClusterConfig:
|
152 | InstanceCount: {{# if es.instanceCount}}{{es.instanceCount}}{{ else }}1{{/if}}
|
153 | InstanceType: {{# if es.instanceType}}{{es.instanceType}}{{ else }}"t2.small.elasticsearch"{{/if}}
|
154 | SnapshotOptions:
|
155 | AutomatedSnapshotStartHour: 0
|
156 | EBSOptions:
|
157 | EBSEnabled: true
|
158 | VolumeType: gp2
|
159 | VolumeSize: {{es.volumeSize}}
|
160 | AdvancedOptions:
|
161 | rest.action.multi.allow_explicit_index: "true"
|
162 | AccessPolicies:
|
163 | Version: "2012-10-17"
|
164 | Statement:
|
165 | - Effect: "Allow"
|
166 | Principal:
|
167 | AWS: {{iams.lambdaProcessingRoleArn}}
|
168 | Action: "es:*"
|
169 | Resource:
|
170 | - Fn::Sub: "arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/{{prefix}}-{{es.name}}/*"
|
171 | - Effect: "Allow"
|
172 | Principal:
|
173 | AWS: {{iams.lambdaApiGatewayRoleArn}}
|
174 | Action: "es:*"
|
175 | Resource:
|
176 | - Fn::Sub: "arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/{{prefix}}-{{es.name}}/*"
|
177 | {{# if vpc }}
|
178 | VPCOptions:
|
179 | SecurityGroupIds:
|
180 | - {{vpc.securityGroup}}
|
181 | SubnetIds:
|
182 | {{#each vpc.subnets}}
|
183 | - {{this}}
|
184 | {{/each}}
|
185 | {{/if}}
|
186 |
|
187 | {{#if es.alarms}}
|
188 | {{# each es.alarms}}
|
189 | {{../es.name}}{{@key}}Alarm:
|
190 | Type: AWS::CloudWatch::Alarm
|
191 | Properties:
|
192 | {{#if alarm_description}}
|
193 | AlarmDescription: {{ alarm_description }}
|
194 | {{/if}}
|
195 | AlarmName: {{../prefix}}-{{../es.name}}-{{@key}}Alarm
|
196 | ComparisonOperator: {{ comparison_operator }}
|
197 | EvaluationPeriods: {{#if evaluation_periods }}{{ evaluation_periods }}{{ else }}5{{/if}}
|
198 | MetricName: {{ metric }}
|
199 | Statistic: {{#if statistic }}{{ statistic }}{{ else }}Average{{/if}}
|
200 | Threshold: {{ threshold }}
|
201 | Period: {{#if period }}{{ period }}{{ else }}60{{/if}}
|
202 | Namespace: AWS/ES
|
203 | Dimensions:
|
204 | - Name: ClientId
|
205 | Value:
|
206 | Fn::Sub: ${AWS::AccountId}
|
207 | - Name: DomainName
|
208 | Value:
|
209 | Ref: {{../es.name}}Domain
|
210 | {{/each}}
|
211 | {{/if}}
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | {{/if}}
|
217 |
|
218 |
|
219 | Outputs:
|
220 | {{#each dynamos}}
|
221 | {{@key}}DynamoDBStreamArn:
|
222 | Value:
|
223 | Fn::GetAtt:
|
224 | - {{@key}}DynamoDB
|
225 | - StreamArn
|
226 | {{/each}}
|
227 |
|
228 | {{#if es.name}}
|
229 | {{es.name}}DomainEndpoint:
|
230 | Value:
|
231 | Fn::GetAtt:
|
232 | - {{es.name}}Domain
|
233 | - DomainEndpoint
|
234 | {{/if}}
|