@@ -290,6 +290,13 @@ internal PipelineStack(
290
290
}
291
291
} ) ;
292
292
293
+ var smokeTestsLambdaFunctionRole = new Role ( this , "SmokeTestsLambdaFunctionRole" , new RoleProps
294
+ {
295
+ RoleName = $ "image-function-tests-{ Guid . NewGuid ( ) } ",
296
+ ManagedPolicies = new IManagedPolicy [ ] { ManagedPolicy . FromAwsManagedPolicyName ( "service-role/AWSLambdaBasicExecutionRole" ) } ,
297
+ AssumedBy = new ServicePrincipal ( "lambda.amazonaws.com" )
298
+ } ) ;
299
+
293
300
// Smoke test AMD64 image
294
301
var amd64SmokeTests = new Project ( this , "SmokeTests-amd64" , new ProjectProps
295
302
{
@@ -314,24 +321,82 @@ internal PipelineStack(
314
321
{ "AWS_LAMBDA_DOTNET_FRAMEWORK_VERSION" , new BuildEnvironmentVariable { Value = framework } } ,
315
322
{ "AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL" , new BuildEnvironmentVariable { Value = channel } } ,
316
323
{ "AWS_LAMBDA_DOTNET_BUILD_IMAGE" , new BuildEnvironmentVariable { Value = dockerBuildImage } } ,
317
- { "AWS_LAMBDA_DOTNET_SDK_VERSION" , new BuildEnvironmentVariable { Value = configuration . DotnetSdkVersions . ContainsKey ( framework ) ? configuration . DotnetSdkVersions [ framework ] : string . Empty } }
318
- }
324
+ { "AWS_LAMBDA_DOTNET_SDK_VERSION" , new BuildEnvironmentVariable { Value = configuration . DotnetSdkVersions . ContainsKey ( framework ) ? configuration . DotnetSdkVersions [ framework ] : string . Empty } } ,
325
+ { "AWS_LAMBDA_SMOKETESTS_LAMBDA_ROLE" , new BuildEnvironmentVariable { Value = smokeTestsLambdaFunctionRole . RoleArn } }
326
+ } ,
319
327
} ) ;
320
328
321
- var smokeTestsPolicy = new PolicyStatement ( new PolicyStatementProps
329
+ var smokeTestsPolicies = new List < PolicyStatement > ( ) ;
330
+
331
+ // ECR Policies
332
+ smokeTestsPolicies . Add ( new PolicyStatement ( new PolicyStatementProps
322
333
{
323
334
Effect = Effect . ALLOW ,
324
335
Actions = new [ ]
325
336
{
326
- "sts:*" ,
327
- "iam:*" ,
328
- "ecr:*" ,
329
- "lambda:*"
337
+ "ecr:BatchCheckLayerAvailability" ,
338
+ "ecr:BatchDeleteImage" ,
339
+ "ecr:BatchGetImage" ,
340
+ "ecr:CompleteLayerUpload" ,
341
+ "ecr:CreateRepository" ,
342
+ "ecr:DescribeRepositories" ,
343
+ "ecr:GetAuthorizationToken" ,
344
+ "ecr:GetDownloadUrlForLayer" ,
345
+ "ecr:InitiateLayerUpload" ,
346
+ "ecr:PutImage" ,
347
+ "ecr:UploadLayerPart"
348
+ } ,
349
+ Resources = new [ ] {
350
+ $ "arn:aws:ecr:{ configuration . Region } :{ configuration . AccountId } :repository/image-function-tests",
351
+ $ "arn:aws:ecr:{ configuration . Region } :{ configuration . AccountId } :repository/{ ecrRepositoryName } "
352
+ }
353
+ } ) ) ;
354
+
355
+ // The following ECR policy needs to specify * as the resource since that is what is explicitly stated by the following error:
356
+ // An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation:
357
+ // User: *** is not authorized to perform: ecr:GetAuthorizationToken on resource: * because no identity-based policy
358
+ // allows the ecr:GetAuthorizationToken action
359
+ smokeTestsPolicies . Add ( new PolicyStatement ( new PolicyStatementProps
360
+ {
361
+ Effect = Effect . ALLOW ,
362
+ Actions = new [ ]
363
+ {
364
+ "ecr:GetAuthorizationToken"
330
365
} ,
331
366
Resources = new [ ] { "*" }
332
- } ) ;
367
+ } ) ) ;
333
368
334
- amd64SmokeTests . AddToRolePolicy ( smokeTestsPolicy ) ;
369
+ // IAM Policies
370
+ smokeTestsPolicies . Add ( new PolicyStatement ( new PolicyStatementProps
371
+ {
372
+ Effect = Effect . ALLOW ,
373
+ Actions = new [ ]
374
+ {
375
+ "iam:PassRole"
376
+ } ,
377
+ Resources = new [ ] { smokeTestsLambdaFunctionRole . RoleArn }
378
+ } ) ) ;
379
+
380
+ // Lambda Policies
381
+ smokeTestsPolicies . Add ( new PolicyStatement ( new PolicyStatementProps
382
+ {
383
+ Effect = Effect . ALLOW ,
384
+ Actions = new [ ]
385
+ {
386
+ "lambda:CreateFunction" ,
387
+ "lambda:DeleteFunction" ,
388
+ "lambda:GetFunction" ,
389
+ "lambda:GetFunctionConfiguration" ,
390
+ "lambda:InvokeFunction" ,
391
+ "lambda:UpdateFunctionConfiguration"
392
+ } ,
393
+ Resources = new [ ] {
394
+ $ "arn:aws:lambda:{ configuration . Region } :{ configuration . AccountId } :function:image-function-tests-*"
395
+ }
396
+ } ) ) ;
397
+
398
+ foreach ( var policy in smokeTestsPolicies )
399
+ amd64SmokeTests . AddToRolePolicy ( policy ) ;
335
400
336
401
var smokeTestsActions = new List < Action > ( ) ;
337
402
smokeTestsActions . Add ( new CodeBuildAction ( new CodeBuildActionProps
@@ -367,11 +432,13 @@ internal PipelineStack(
367
432
{ "AWS_LAMBDA_DOTNET_FRAMEWORK_VERSION" , new BuildEnvironmentVariable { Value = framework } } ,
368
433
{ "AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL" , new BuildEnvironmentVariable { Value = channel } } ,
369
434
{ "AWS_LAMBDA_DOTNET_BUILD_IMAGE" , new BuildEnvironmentVariable { Value = dockerBuildImage } } ,
370
- { "AWS_LAMBDA_DOTNET_SDK_VERSION" , new BuildEnvironmentVariable { Value = configuration . DotnetSdkVersions . ContainsKey ( framework ) ? configuration . DotnetSdkVersions [ framework ] : string . Empty } }
435
+ { "AWS_LAMBDA_DOTNET_SDK_VERSION" , new BuildEnvironmentVariable { Value = configuration . DotnetSdkVersions . ContainsKey ( framework ) ? configuration . DotnetSdkVersions [ framework ] : string . Empty } } ,
436
+ { "AWS_LAMBDA_SMOKETESTS_LAMBDA_ROLE" , new BuildEnvironmentVariable { Value = smokeTestsLambdaFunctionRole . RoleArn } }
371
437
}
372
438
} ) ;
373
439
374
- arm64SmokeTests . AddToRolePolicy ( smokeTestsPolicy ) ;
440
+ foreach ( var policy in smokeTestsPolicies )
441
+ arm64SmokeTests . AddToRolePolicy ( policy ) ;
375
442
376
443
smokeTestsActions . Add ( new CodeBuildAction ( new CodeBuildActionProps
377
444
{
0 commit comments