-
Notifications
You must be signed in to change notification settings - Fork 3
/
Common-DirectoryFunctions.yaml
326 lines (326 loc) · 12.2 KB
/
Common-DirectoryFunctions.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
AWSTemplateFormatVersion: 2010-09-09
Description: Common-DirectoryFunctions Template.
This creates Lambda Functions related to Directory Services.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Stack Dependencies
Parameters:
- LayersStackName
- BucketsStackName
- TopicsStackName
- Label:
default: Function Configuration
Parameters:
- DirectoryAliasFunctionKey
- DirectoryAliasFunctionObjectVersion
- DirectoryAliasLogRetention
- DirectoryConditionalForwarderFunctionKey
- DirectoryConditionalForwarderFunctionObjectVersion
- DirectoryConditionalForwarderLogRetention
- DirectoryLogSubscriptionFunctionKey
- DirectoryLogSubscriptionFunctionObjectVersion
- DirectoryLogSubscriptionLogRetention
ParameterLabels:
LayersStackName:
default: Layers Stack Name
BucketsStackName:
default: Buckets Stack Name
TopicsStackName:
default: Topics Stack Name
DirectoryAliasFunctionKey:
default: DirectoryAlias Function S3 Key
DirectoryAliasFunctionObjectVersion:
default: DirectoryAlias Function S3 Object Version
DirectoryAliasLogRetention:
default: DirectoryAlias Log Retention
DirectoryConditionalForwarderFunctionKey:
default: DirectoryConditionalForwarder Function S3 Key
DirectoryConditionalForwarderFunctionObjectVersion:
default: DirectoryConditionalForwarder Function S3 Object Version
DirectoryConditionalForwarderLogRetention:
default: DirectoryConditionalForwarder Log Retention
DirectoryLogSubscriptionFunctionKey:
default: DirectoryLogSubscription Function S3 Key
DirectoryLogSubscriptionFunctionObjectVersion:
default: DirectoryLogSubscription Function S3 Object Version
DirectoryLogSubscriptionLogRetention:
default: DirectoryLogSubscription LogRetention
Parameters:
LayersStackName:
Description: Name of the CloudFormation Stack containing Layers
Type: String
MinLength: 2
MaxLength: 64
Default: Layers
AllowedPattern: ^[A-Z][-a-zA-Z0-9]*$
ConstraintDescription: must begin with an upper case letter and contain alphanumeric characters and dashes.
BucketsStackName:
Description: Name of the CloudFormation Stack containing Buckets
Type: String
MinLength: 2
MaxLength: 64
Default: Buckets
AllowedPattern: ^[A-Z][-a-zA-Z0-9]*$
ConstraintDescription: must begin with an upper case letter and contain alphanumeric characters and dashes.
TopicsStackName:
Description: Name of the CloudFormation Stack containing Topics
Type: String
MinLength: 2
MaxLength: 64
Default: Topics
AllowedPattern: ^[A-Z][-a-zA-Z0-9]*$
ConstraintDescription: must begin with an upper case letter and contain alphanumeric characters and dashes.
DirectoryAliasFunctionKey:
Description: Key of Object within the S3 Bucket containing the DirectoryAlias Lambda Function zipfile
Type: String
MinLength: 2
MaxLength: 64
Default: DirectoryAlias.zip
AllowedPattern: ^[-_.a-zA-Z0-9]*\.zip$
ConstraintDescription: must be a valid zipfilename, not containing slashes.
DirectoryAliasFunctionObjectVersion:
Description: Version of Object within the S3 Bucket containing the DirectoryAlias Lambda Function zipfile
Type: String
MaxLength: 32
Default: ''
ConstraintDescription: must be a valid S3 Object Version.
DirectoryAliasLogRetention:
Description: Number of days to retain CloudWatch Log Events for the DirectoryAlias Lambda Function
Type: Number
Default: 30
AllowedValues:
- 1
- 3
- 5
- 7
- 14
- 30
- 60
- 90
ConstraintDescription: must be 1, 3, 5, 7, 14, 30, 60 or 90.
DirectoryConditionalForwarderFunctionKey:
Description: Key of Object within the S3 Bucket containing the DirectoryConditionalForwarder Lambda Function zipfile
Type: String
MinLength: 2
MaxLength: 64
Default: DirectoryConditionalForwarder.zip
AllowedPattern: ^[-_.a-zA-Z0-9]*\.zip$
ConstraintDescription: must be a valid zipfilename, not containing slashes.
DirectoryConditionalForwarderFunctionObjectVersion:
Description: Version of Object within the S3 Bucket containing the DirectoryConditionalForwarder Lambda Function zipfile
Type: String
MaxLength: 32
Default: ''
ConstraintDescription: must be a valid S3 Object Version.
DirectoryConditionalForwarderLogRetention:
Description: Number of days to retain CloudWatch Log Events for the DirectoryConditionalForwarder Lambda Function
Type: Number
Default: 30
AllowedValues:
- 1
- 3
- 5
- 7
- 14
- 30
- 60
- 90
ConstraintDescription: must be 1, 3, 5, 7, 14, 30, 60 or 90.
DirectoryLogSubscriptionFunctionKey:
Description: Key of Object within the S3 Bucket containing the DirectoryLogSubscription Lambda Function zipfile
Type: String
MinLength: 2
MaxLength: 64
Default: DirectoryLogSubscription.zip
AllowedPattern: ^[-_.a-zA-Z0-9]*\.zip$
ConstraintDescription: must be a valid zipfilename, not containing slashes.
DirectoryLogSubscriptionFunctionObjectVersion:
Description: Version of Object within the S3 Bucket containing the DirectoryLogSubscription Lambda Function zipfile
Type: String
MaxLength: 32
Default: ''
ConstraintDescription: must be a valid S3 Object Version.
DirectoryLogSubscriptionLogRetention:
Description: Number of days to retain CloudWatch Log Events for the DirectoryLogSubscription Lambda Function
Type: Number
Default: 30
AllowedValues:
- 1
- 3
- 5
- 7
- 14
- 30
- 60
- 90
ConstraintDescription: must be 1, 3, 5, 7, 14, 30, 60 or 90.
Conditions:
ConfigureDirectoryAliasFunctionObjectVersion: !Not [ !Equals [ !Ref DirectoryAliasFunctionObjectVersion, '' ]]
ConfigureDirectoryConditionalForwarderFunctionObjectVersion: !Not [ !Equals [ !Ref DirectoryConditionalForwarderFunctionObjectVersion, '' ]]
ConfigureDirectoryLogSubscriptionFunctionObjectVersion: !Not [ !Equals [ !Ref DirectoryLogSubscriptionFunctionObjectVersion, '' ]]
Resources:
DirectoryAliasRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DirectoryAliasPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- ds:CreateAlias
- ds:EnableSso
- ds:DisableSso
Resource: '*'
DirectoryAliasLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/DirectoryAlias
RetentionInDays: !Ref DirectoryAliasLogRetention
DirectoryAliasFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: DirectoryAlias
Description: A Lambda function that creates an alias for a directory service.
Role: !GetAtt DirectoryAliasRole.Arn
Runtime: nodejs10.x
Timeout: 30
Layers:
- !ImportValue
Fn::Sub: ${LayersStackName}-AsyncCustomResourceLayerVersionArn
Handler: DirectoryAlias.handler
Code:
S3Bucket: !ImportValue
Fn::Sub: ${BucketsStackName}-FunctionsBucket
S3Key: !Ref DirectoryAliasFunctionKey
S3ObjectVersion: !If [ ConfigureDirectoryAliasFunctionObjectVersion, !Ref DirectoryAliasFunctionObjectVersion, !Ref 'AWS::NoValue' ]
DependsOn: DirectoryAliasLogGroup
DirectoryConditionalForwarderRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DirectoryConditionalForwarderPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- ds:DescribeConditionalForwarders
- ds:CreateConditionalForwarder
- ds:DeleteConditionalForwarder
Resource: '*'
DirectoryConditionalForwarderLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/DirectoryConditionalForwarder
RetentionInDays: !Ref DirectoryConditionalForwarderLogRetention
DirectoryConditionalForwarderFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: DirectoryConditionalForwarder
Description: A Lambda function that creates an alias for a directory service.
Role: !GetAtt DirectoryConditionalForwarderRole.Arn
Runtime: nodejs10.x
Timeout: 30
Layers:
- !ImportValue
Fn::Sub: ${LayersStackName}-AsyncCustomResourceLayerVersionArn
Handler: DirectoryConditionalForwarder.handler
Code:
S3Bucket: !ImportValue
Fn::Sub: ${BucketsStackName}-FunctionsBucket
S3Key: !Ref DirectoryConditionalForwarderFunctionKey
S3ObjectVersion: !If [ ConfigureDirectoryConditionalForwarderFunctionObjectVersion, !Ref DirectoryConditionalForwarderFunctionObjectVersion, !Ref 'AWS::NoValue' ]
DependsOn: DirectoryConditionalForwarderLogGroup
DirectoryLogSubscriptionRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DirectoryLogSubscriptionPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- ds:ListLogSubscriptions
- ds:CreateLogSubscription
- ds:DeleteLogSubscription
Resource: '*'
DirectoryLogSubscriptionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/DirectoryLogSubscription
RetentionInDays: !Ref DirectoryLogSubscriptionLogRetention
DirectoryLogSubscriptionFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: DirectoryLogSubscription
Description: A Lambda function that creates an alias for a directory service.
Role: !GetAtt DirectoryLogSubscriptionRole.Arn
Runtime: nodejs10.x
Timeout: 30
Layers:
- !ImportValue
Fn::Sub: ${LayersStackName}-AsyncCustomResourceLayerVersionArn
Handler: DirectoryLogSubscription.handler
Code:
S3Bucket: !ImportValue
Fn::Sub: ${BucketsStackName}-FunctionsBucket
S3Key: !Ref DirectoryLogSubscriptionFunctionKey
S3ObjectVersion: !If [ ConfigureDirectoryLogSubscriptionFunctionObjectVersion, !Ref DirectoryLogSubscriptionFunctionObjectVersion, !Ref 'AWS::NoValue' ]
DependsOn: DirectoryLogSubscriptionLogGroup
Outputs:
DirectoryAliasFunctionArn:
Description: The DirectoryAlias Lambda Function ARN
Value: !GetAtt DirectoryAliasFunction.Arn
Export:
Name: !Sub ${AWS::StackName}-DirectoryAliasFunctionArn
DirectoryConditionalForwarderFunctionArn:
Description: The DirectoryConditionalForwarder Lambda Function ARN
Value: !GetAtt DirectoryConditionalForwarderFunction.Arn
Export:
Name: !Sub ${AWS::StackName}-DirectoryConditionalForwarderFunctionArn
DirectoryLogSubscriptionFunctionArn:
Description: The DirectoryLogSubscription Lambda Function ARN
Value: !GetAtt DirectoryLogSubscriptionFunction.Arn
Export:
Name: !Sub ${AWS::StackName}-DirectoryLogSubscriptionFunctionArn