-
Notifications
You must be signed in to change notification settings - Fork 312
/
parallelcluster-api.yaml
379 lines (345 loc) · 14.5 KB
/
parallelcluster-api.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'AWS ParallelCluster API'
Parameters:
Region:
Description: When set to a given region name (e.g. eu-west-1), the API can control resources in that region only. Set to '*' to control all regions.
Type: String
Default: '*'
ParallelClusterFunctionRole:
Description: |
When specified, the ARN of the execution role for the ParallelCluster Lambda function
Type: String
Default: ''
ApiDefinitionS3Uri:
Description: S3 URI of the ParallelCluster API spec
Type: String
Default: s3:https://<REGION>-aws-parallelcluster/parallelcluster/3.10.0/api/ParallelCluster.openapi.yaml
CustomDomainName:
Description: When specified, the custom domain name of the ParallelCluster API. Requires specifying a custom domain certificate
Type: String
Default: ''
CustomDomainCertificate:
Description: When specified, the ARN of the certificate for the custom domain name of the ParallelCluster API. Required when specifying a custom domain name
Type: String
Default: ''
CustomDomainHostedZoneId:
Description: When specified, the id of the Hosted Zone where the custom domain record of the ParallelCluster API is registered
Type: String
Default: ''
PoliciesTemplateUri:
Description: "S3 URI of the ParallelCluster Policies Template. Defaults to: s3:https://<REGION>-aws-parallelcluster/parallelcluster/3.10.0/templates/policies/policies.yaml"
Type: String
Default: ''
VpcEndpointId:
Description: When specified, configure a private API with the specified endpoint
Type: String
Default: ''
EnableIamAdminAccess:
Description: |
When set to true the ParallelCluster API takes care of IAM resource creation when deploying clusters or generating custom AMIs.
WARNING - setting this to true grants IAM admin privileges to the Lambda function
Type: String
Default: false
AllowedValues:
- true
- false
EnableFSxS3Access:
Description: |
When set to true the ParallelCluster API can access, write to the S3 buckets specified in the Filed FsxS3Bucket, it is needed to import/export from/to S3 when creating an FSx filesystem.
NOTE - setting this to true grants the Lambda function S3 Get*, List* and PutObject privileges on the buckets specified in FsxS3Buckets.
Type: String
Default: false
AllowedValues:
- true
- false
FsxS3Buckets:
Description: |
Comma separated list of S3 bucket ARNs, to allow the lambda function to import/export from/to S3 when creating an FSx filesystem.
NOTE - The setting is used only when EnableFSxS3Access is set to true. (example arn:aws:s3:::<S3_BUCKET_1>,arn:aws:s3:::<S3_BUCKET_2>)
Type: String
Default: ''
AllowedPattern: ^((arn:[a-z\-\*]*:s3:[a-z0-9\-]*:([0-9]{12})*:[^,\s\/]+)?(,arn:[a-z\-\*]*:s3:[a-z0-9\-]*:([0-9]{12})*:[^,\s\/]+)*)$|^\*$
ConstraintDescription: |
The list of S3 buckets is incorrectly formatted. The list should have the format: arn:<PARTITION>:s3:<REGION>:<ACCOUNT_ID>:<BUCKET_NAME>[,arn:<PARTITION>:s3:<REGION>:<ACCOUNT_ID>:<BUCKET_NAME>,...]
Example: arn:aws:s3:::test-bucket-1,arn:aws:s3:::test-bucket-2,arn:aws:s3:::test-bucket-3
PermissionsBoundaryPolicy:
Description: |
ARN of a IAM policy to use as PermissionsBoundary for all IAM resources created by ParallelCluster API.
When specified, IAM permissions assumed by the API are conditionally restricted to the usage of the given PermissionsBoundary
Type: String
Default: ''
ConstraintDescription: "The value must be a valid ARN in the format: arn:{AWS::Partition}:iam::{AWS::AccountId}:policy/PolicyNameParameter"
AllowedPattern: "^(arn:.*:iam::.*:policy\\/([a-zA-Z0-9_-]+))|()$"
CreateApiUserRole:
Description: Creates a IAM role authorized to invoke the API. The Api is configured with a resource based policy to grant invoke permission to the created user only.
Type: String
Default: true
AllowedValues:
- true
- false
CustomBucket:
Description: (Debug only) bucket to retrieve S3 artifacts for internal resources.
Type: String
Default: ''
IAMRoleAndPolicyPrefix:
Type: String
Description: 'Prefix for IAM roles and policies'
Default: ''
MaxLength: 10
Mappings:
ParallelCluster:
Constants:
Version: 3.10.0 # major.minor.patch+alpha/beta_identifier
ShortVersion: 3.10.0 # major.minor.patch
Stage: prod
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 30
Tags:
'parallelcluster:version': !FindInMap [ParallelCluster, Constants, Version]
Api:
Auth:
DefaultAuthorizer: AWS_IAM
ResourcePolicy:
CustomStatements:
Effect: 'Deny'
Action: 'execute-api:Invoke'
Resource: ['execute-api:/*/*/*']
Principal: '*'
Condition:
StringNotLike:
# This allows also creds assumed through sts for the ParallelClusterApiUserRole role
aws:PrincipalArn: !If
- CreateApiUserRoleCondition
- !Sub
- arn:${AWS::Partition}:*::${AWS::AccountId}:*/${IAMRoleAndPolicyPrefix}PCAPIUserRole-${StackIdSuffix}*
- { StackIdSuffix: !Select [2, !Split ['/', !Ref 'AWS::StackId']] }
- '*'
TracingEnabled: True
EndpointConfiguration:
Type: REGIONAL
MethodSettings:
- HttpMethod: '*'
ResourcePath: '/*'
ThrottlingRateLimit: 100
ThrottlingBurstLimit: 10
MetricsEnabled: true
Conditions:
UseCustomParallelClusterFunctionRole: !Not [!Equals [!Ref ParallelClusterFunctionRole, '']]
CreateIamResources: !Not [!Condition UseCustomParallelClusterFunctionRole]
UseCustomDomain: !Not [!Equals [!Ref CustomDomainName, '']]
UseRoute53Configuration: !Not [!Equals [!Ref CustomDomainHostedZoneId, '']]
UseCustomDomainAndRoute53Configuration: !And
- !Condition UseCustomDomain
- !Condition UseRoute53Configuration
UsePrivateVpcEndpoint: !And
- !Not [!Condition UseCustomDomainAndRoute53Configuration]
- !Not [!Equals [!Ref VpcEndpointId, '']]
DoNotUseCustomDomain: !And
- !Not [!Condition UsePrivateVpcEndpoint]
- !Not [!Condition UseCustomDomainAndRoute53Configuration]
CreateApiUserRoleCondition: !Equals [!Ref CreateApiUserRole, true]
UseCustomBucket: !Not [!Equals [!Ref CustomBucket, '']]
UseCustomPoliciesTemplateUri: !Not [!Equals [!Ref PoliciesTemplateUri, '']]
HasPermissionBoundary: !Not [!Equals [!Ref PermissionsBoundaryPolicy, '']]
Resources:
# Policies nested stack
PclusterPolicies:
Type: AWS::CloudFormation::Stack
Condition: CreateIamResources
Properties:
TemplateURL: !If
- UseCustomPoliciesTemplateUri
- !Ref PoliciesTemplateUri
- !Sub
- "https://${AWS::Region}-aws-parallelcluster.s3.${AWS::Region}.${AWS::URLSuffix}/parallelcluster/${Version}/templates/policies/policies.yaml"
- { Version: !FindInMap [ParallelCluster, Constants, Version] }
TimeoutInMinutes: 10
Parameters:
Region: !Ref Region
EnableFSxS3Access: !Ref EnableFSxS3Access
EnableIamAdminAccess: !Ref EnableIamAdminAccess
FsxS3Buckets: !Ref FsxS3Buckets
PermissionsBoundaryPolicy: !Ref PermissionsBoundaryPolicy
IAMRoleAndPolicyPrefix: !Ref IAMRoleAndPolicyPrefix
EnableBatchAccess: true
PclusterLayer:
Type: AWS::Lambda::LayerVersion
Properties:
LayerName: !Sub
- PCLayer-${StackIdSuffix}
- { StackIdSuffix: !Select [2, !Split ['/', !Ref 'AWS::StackId']] }
Description: Library which contains aws-parallelcluster python package and dependencies
Content:
S3Bucket: !If [ UseCustomBucket, !Ref CustomBucket, !Sub "${AWS::Region}-aws-parallelcluster" ]
S3Key: !Sub
- parallelcluster/${Version}/layers/aws-parallelcluster/lambda-layer.zip
- { Version: !FindInMap [ParallelCluster, Constants, Version]}
CompatibleRuntimes:
- python3.9
# We need to define three AWS::Serverless::Api due to an issue with the handling of AWS::NoValue
# See related GitHub issue: https://github.com/aws/serverless-application-model/issues/1435
ApiGatewayApiWithCustomDomainAndRoute53Configuration:
Condition: UseCustomDomainAndRoute53Configuration
Type: AWS::Serverless::Api
Properties:
Tags:
'parallelcluster:version': !FindInMap [ParallelCluster, Constants, Version]
StageName: !FindInMap [ParallelCluster, Constants, Stage]
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: !Ref ApiDefinitionS3Uri
Domain:
DomainName: !Ref CustomDomainName
CertificateArn: !Ref CustomDomainCertificate
Route53:
HostedZoneId: !Ref CustomDomainHostedZoneId
ApiGatewayApiWithoutCustomDomain:
Condition: DoNotUseCustomDomain
Type: AWS::Serverless::Api
Properties:
Tags:
'parallelcluster:version': !FindInMap [ParallelCluster, Constants, Version]
StageName: !FindInMap [ParallelCluster, Constants, Stage]
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: !Ref ApiDefinitionS3Uri
ApiGatewayApiWithPrivateVpcEndpoint:
Condition: UsePrivateVpcEndpoint
Type: AWS::Serverless::Api
Properties:
Tags:
'parallelcluster:version': !FindInMap [ParallelCluster, Constants, Version]
StageName: !FindInMap [ParallelCluster, Constants, Stage]
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: !Ref ApiDefinitionS3Uri
EndpointConfiguration:
Type: PRIVATE
VPCEndpointIds: [!Ref VpcEndpointId]
Auth:
DefaultAuthorizer: AWS_IAM
ResourcePolicy:
IntrinsicVpceWhitelist: [!Ref VpcEndpointId]
# Note that even for Chinese regions here we need to use apigateway.amazonaws.com instead of apigateway.amazonaws.com.cn
APIGatewayExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- 'sts:AssumeRole'
PermissionsBoundary: !If [HasPermissionBoundary, !Ref PermissionsBoundaryPolicy, !Ref 'AWS::NoValue']
RoleName: !Sub
- ${IAMRoleAndPolicyPrefix}APIGatewayExecutionRole-${StackIdSuffix}
- { StackIdSuffix: !Select [ 0, !Split [ '-', !Select [ 2, !Split [ '/', !Ref 'AWS::StackId']]]] }
Policies:
- PolicyName: !Sub ${IAMRoleAndPolicyPrefix}lambda-invoke
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !GetAtt ParallelClusterFunction.Arn
ParallelClusterFunction:
Type: AWS::Lambda::Function
Properties:
TracingConfig:
Mode: Active
MemorySize: 2048
Timeout: 30
Role: !If [UseCustomParallelClusterFunctionRole, !Ref ParallelClusterFunctionRole, !GetAtt [ PclusterPolicies, Outputs.ParallelClusterLambdaRoleArn ]]
Tags:
- Key: 'parallelcluster:resource'
Value: api
- Key: 'parallelcluster:version'
Value: !FindInMap [ParallelCluster, Constants, Version]
Runtime: python3.9
Handler: pcluster.api.awslambda.entrypoint.lambda_handler
Layers:
- !Ref PclusterLayer
# Lambda fails creation without specifying a non-empty code or container
Code:
ZipFile: " "
ParallelClusterApiUserRole:
Type: AWS::IAM::Role
Condition: CreateApiUserRoleCondition
Properties:
RoleName: !Sub
- ${IAMRoleAndPolicyPrefix}PCAPIUserRole-${StackIdSuffix}
- { StackIdSuffix: !Select [2, !Split ['/', !Ref 'AWS::StackId']] }
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
AWS:
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root
PermissionsBoundary: !If [HasPermissionBoundary, !Ref PermissionsBoundaryPolicy, !Ref 'AWS::NoValue']
Policies:
- PolicyName: !Sub ${IAMRoleAndPolicyPrefix}ParallelClusterApiInvokePolicy
PolicyDocument:
Statement:
- Action:
- execute-api:Invoke
Effect: Allow
Resource: !Sub
- arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiId}/*/*/*
- ApiId: !If
- UseCustomDomainAndRoute53Configuration
- !Ref ApiGatewayApiWithCustomDomainAndRoute53Configuration
- !If
- UsePrivateVpcEndpoint
- !Ref ApiGatewayApiWithPrivateVpcEndpoint
- !Ref ApiGatewayApiWithoutCustomDomain
Version: '2012-10-17'
### -----------
ParallelClusterFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${ParallelClusterFunction}
RetentionInDays: 30
Outputs:
ParallelClusterLambdaArn:
Description: 'ARN of the ParallelCluster Lambda function'
Value: !GetAtt ParallelClusterFunction.Arn
ParallelClusterApiInvokeUrl:
Description: 'Url to reach the API endpoint'
Export:
Name: !Sub ${AWS::StackName}-ParallelClusterApiInvokeUrl
Value: !If
- UseCustomDomain
- !Sub
- https://${CustomDomain}
- { CustomDomain: !Ref CustomDomainName }
- !Sub
- https://${Api}.execute-api.${AWS::Region}.${AWS::URLSuffix}/${StageName}
- Api: !If
- UsePrivateVpcEndpoint
- !Sub
- '${restApiId}-${vpceId}'
- { restApiId: !Ref ApiGatewayApiWithPrivateVpcEndpoint, vpceId: !Ref VpcEndpointId }
- !Ref ApiGatewayApiWithoutCustomDomain
StageName: !FindInMap [ParallelCluster, Constants, Stage]
ParallelClusterApiUserRole:
Condition: CreateApiUserRoleCondition
Export:
Name: !Sub ${AWS::StackName}-ParallelClusterApiUserRole
Description: 'IAM Role with permissions to invoke the ParallelCluster API'
Value: !GetAtt ParallelClusterApiUserRole.Arn
ParallelClusterLambdaLogGroup:
Value: !Ref ParallelClusterFunctionLogGroup
Description: 'LogGroup for the Lambda function implementing ParallelCluster Api'