From 710a88edb23cbda053ecacaeaf45b842e162436c Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sat, 1 Mar 2025 14:23:00 +0900 Subject: [PATCH 01/17] feat: lookup ecr repository --- .../LookupStack.assets.json | 20 ++ .../LookupStack.template.json | 36 +++ .../Stack.assets.json | 34 +++ .../Stack.template.json | 165 +++++++++++++ .../index.js | 2 + .../cdk.out | 1 + ...efaultTestDeployAssert6B08011C.assets.json | 19 ++ ...aultTestDeployAssert6B08011C.template.json | 36 +++ .../integ.json | 13 + .../manifest.json | 218 +++++++++++++++++ .../tree.json | 224 ++++++++++++++++++ .../aws-ecr/test/integ.repository-lookup.ts | 36 +++ .../aws-cdk-lib/aws-ecr/lib/repository.ts | 55 +++++ 13 files changed, 859 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json new file mode 100644 index 0000000000000..58ee63fad0d7d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "40.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "LookupStack.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json new file mode 100644 index 0000000000000..679ff6d397010 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json @@ -0,0 +1,34 @@ +{ + "version": "40.0.0", + "files": { + "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { + "source": { + "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", + "packaging": "zip" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + }, + "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98": { + "source": { + "path": "Stack.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json new file mode 100644 index 0000000000000..4fc1e0708963e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json @@ -0,0 +1,165 @@ +{ + "Resources": { + "Repo02AC86CF": { + "Type": "AWS::ECR::Repository", + "Properties": { + "RepositoryName": "my-repo", + "Tags": [ + { + "Key": "aws-cdk:auto-delete-images", + "Value": "true" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "RepoAutoDeleteImagesCustomResource65201E29": { + "Type": "Custom::ECRAutoDeleteImages", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", + "Arn" + ] + }, + "RepositoryName": { + "Ref": "Repo02AC86CF" + } + }, + "DependsOn": [ + "Repo02AC86CF" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ecr:BatchDeleteImage", + "ecr:DescribeRepositories", + "ecr:ListImages", + "ecr:ListTagsForResource" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:test-region:12345678:repository/*" + ] + ] + } + ], + "Condition": { + "StringEquals": { + "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" + } + } + } + ] + } + } + ] + } + }, + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", + "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Description": { + "Fn::Join": [ + "", + [ + "Lambda function for auto-deleting images in ", + { + "Ref": "Repo02AC86CF" + }, + " repository." + ] + ] + } + }, + "DependsOn": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js new file mode 100644 index 0000000000000..eff0ff2826a48 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js @@ -0,0 +1,2 @@ +"use strict";var C=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var L=(e,o)=>{for(var t in o)c(e,t,{get:o[t],enumerable:!0})},d=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of S(o))!P.call(e,r)&&r!==t&&c(e,r,{get:()=>o[r],enumerable:!(s=w(o,r))||s.enumerable});return e};var l=(e,o,t)=>(t=e!=null?C(A(e)):{},d(o||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>d(c({},"__esModule",{value:!0}),e);var W={};L(W,{autoDeleteHandler:()=>I,handler:()=>k});module.exports=T(W);var h=require("@aws-sdk/client-ecr");var m=l(require("https")),R=l(require("url")),n={sendHttpRequest:x,log:N,includeStackTraces:!0,userHandlerIndex:"./index"},p="AWSCDK::CustomResourceProviderFramework::CREATE_FAILED",D="AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";function y(e){return async(o,t)=>{let s={...o,ResponseURL:"..."};if(n.log(JSON.stringify(s,void 0,2)),o.RequestType==="Delete"&&o.PhysicalResourceId===p){n.log("ignoring DELETE event caused by a failed CREATE event"),await u("SUCCESS",o);return}try{let r=await e(s,t),a=b(o,r);await u("SUCCESS",a)}catch(r){let a={...o,Reason:n.includeStackTraces?r.stack:r.message};a.PhysicalResourceId||(o.RequestType==="Create"?(n.log("CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored"),a.PhysicalResourceId=p):n.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(o)}`)),await u("FAILED",a)}}}function b(e,o={}){let t=o.PhysicalResourceId??e.PhysicalResourceId??e.RequestId;if(e.RequestType==="Delete"&&t!==e.PhysicalResourceId)throw new Error(`DELETE: cannot change the physical resource ID from "${e.PhysicalResourceId}" to "${o.PhysicalResourceId}" during deletion`);return{...e,...o,PhysicalResourceId:t}}async function u(e,o){let t={Status:e,Reason:o.Reason??e,StackId:o.StackId,RequestId:o.RequestId,PhysicalResourceId:o.PhysicalResourceId||D,LogicalResourceId:o.LogicalResourceId,NoEcho:o.NoEcho,Data:o.Data},s=R.parse(o.ResponseURL),r=`${s.protocol}//${s.hostname}/${s.pathname}?***`;n.log("submit response to cloudformation",r,t);let a=JSON.stringify(t),f={hostname:s.hostname,path:s.path,method:"PUT",headers:{"content-type":"","content-length":Buffer.byteLength(a,"utf8")}};await F({attempts:5,sleep:1e3},n.sendHttpRequest)(f,a)}async function x(e,o){return new Promise((t,s)=>{try{let r=m.request(e,a=>{a.resume(),!a.statusCode||a.statusCode>=400?s(new Error(`Unsuccessful HTTP response: ${a.statusCode}`)):t()});r.on("error",s),r.write(o),r.end()}catch(r){s(r)}})}function N(e,...o){console.log(e,...o)}function F(e,o){return async(...t)=>{let s=e.attempts,r=e.sleep;for(;;)try{return await o(...t)}catch(a){if(s--<=0)throw a;await H(Math.floor(Math.random()*r)),r*=2}}}async function H(e){return new Promise(o=>setTimeout(o,e))}var g="aws-cdk:auto-delete-images",i=new h.ECR({}),k=y(I);async function I(e){switch(e.RequestType){case"Create":break;case"Update":return{PhysicalResourceId:(await q(e)).PhysicalResourceId};case"Delete":return U(e.ResourceProperties?.RepositoryName)}}async function q(e){let o=e,t=o.OldResourceProperties?.RepositoryName;return{PhysicalResourceId:o.ResourceProperties?.RepositoryName??t}}async function E(e){let o=await i.listImages(e),t=[],s=[];(o.imageIds??[]).forEach(a=>{"imageTag"in a?s.push(a):t.push(a)});let r=o.nextToken??null;t.length===0&&s.length===0||(s.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:s}),t.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:t}),r&&await E({...e,nextToken:r}))}async function U(e){if(!e)throw new Error("No RepositoryName was provided.");let t=(await i.describeRepositories({repositoryNames:[e]})).repositories?.find(s=>s.repositoryName===e);if(!await _(t?.repositoryArn)){process.stdout.write(`Repository does not have '${g}' tag, skipping cleaning. +`);return}try{await E({repositoryName:e})}catch(s){if(s.name!=="RepositoryNotFoundException")throw s}}async function _(e){return(await i.listTagsForResource({resourceArn:e})).tags?.some(t=>t.Key===g&&t.Value==="true")}0&&(module.exports={autoDeleteHandler,handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1e02a2deb191b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"40.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json new file mode 100644 index 0000000000000..03e27a027c527 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json @@ -0,0 +1,19 @@ +{ + "version": "40.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json new file mode 100644 index 0000000000000..8b6bf4ae159a9 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "enableLookups": true, + "version": "40.0.0", + "testCases": { + "cdk-integ-auto-delete-images/DefaultTest": { + "stacks": [ + "Stack" + ], + "assertionStack": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", + "assertionStackName": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json new file mode 100644 index 0000000000000..7583c131cb8d3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json @@ -0,0 +1,218 @@ +{ + "version": "40.0.0", + "artifacts": { + "Stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "Stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "Stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://12345678/test-region", + "properties": { + "templateFile": "Stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "Stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "Stack.assets" + ], + "metadata": { + "/Stack/Repo": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/Stack/Repo/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Repo02AC86CF" + } + ], + "/Stack/Repo/AutoDeleteImagesCustomResource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/Stack/Repo/AutoDeleteImagesCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "RepoAutoDeleteImagesCustomResource65201E29" + } + ], + "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ + { + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true + } + ], + "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + } + ], + "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" + } + ], + "/Stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Stack" + }, + "LookupStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "LookupStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "LookupStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://12345678/test-region", + "properties": { + "templateFile": "LookupStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "LookupStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "LookupStack.assets" + ], + "metadata": { + "/LookupStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/LookupStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "LookupStack" + }, + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" + ], + "metadata": { + "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + }, + "missing": [ + { + "key": "cc-api-provider:account=12345678:exactIdentifier=my-repo:propertiesToReturn.0=Arn:region=test-region:typeName=AWS$:$:ECR$:$:Repository", + "provider": "cc-api-provider", + "props": { + "dummyValue": [ + { + "Arn": "arn:${Token[AWS.Partition.10]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" + } + ], + "account": "12345678", + "region": "test-region", + "typeName": "AWS::ECR::Repository", + "exactIdentifier": "my-repo", + "propertiesToReturn": [ + "Arn" + ], + "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" + } + } + ] +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json new file mode 100644 index 0000000000000..918262e8ba36a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json @@ -0,0 +1,224 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Stack": { + "id": "Stack", + "path": "Stack", + "children": { + "Repo": { + "id": "Repo", + "path": "Stack/Repo", + "children": { + "Resource": { + "id": "Resource", + "path": "Stack/Repo/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECR::Repository", + "aws:cdk:cloudformation:props": { + "repositoryName": "my-repo", + "tags": [ + { + "key": "aws-cdk:auto-delete-images", + "value": "true" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "AutoDeleteImagesCustomResource": { + "id": "AutoDeleteImagesCustomResource", + "path": "Stack/Repo/AutoDeleteImagesCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "Stack/Repo/AutoDeleteImagesCustomResource/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + }, + "Custom::ECRAutoDeleteImagesCustomResourceProvider": { + "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", + "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Role": { + "id": "Role", + "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Handler": { + "id": "Handler", + "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "Stack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "Stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "LookupStack": { + "id": "LookupStack", + "path": "LookupStack", + "children": { + "LookupRepo": { + "id": "LookupRepo", + "path": "LookupStack/LookupRepo", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [] + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "LookupStack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "LookupStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "cdk-integ-auto-delete-images": { + "id": "cdk-integ-auto-delete-images", + "path": "cdk-integ-auto-delete-images", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "cdk-integ-auto-delete-images/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "cdk-integ-auto-delete-images/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts new file mode 100644 index 0000000000000..60fd3a56ce216 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts @@ -0,0 +1,36 @@ + +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { App, RemovalPolicy, Stack } from 'aws-cdk-lib'; +import * as ecr from 'aws-cdk-lib/aws-ecr'; + +const app = new App(); +const repositoryName = 'my-repo'; + +const stack = new Stack(app, 'Stack', { + env: { + account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, + }, +}); + +new ecr.Repository(stack, 'Repo', { + repositoryName, + removalPolicy: RemovalPolicy.DESTROY, + autoDeleteImages: true, +}); + +const lookupStack = new Stack(app, 'LookupStack', { + env: { + account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, + }, +}); + +ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { + repositoryName, +}); + +new IntegTest(app, 'cdk-integ-auto-delete-images', { + enableLookups: true, + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index c1423f3e78634..79529bd83e4a6 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -5,6 +5,7 @@ import { LifecycleRule, TagStatus } from './lifecycle'; import * as events from '../../aws-events'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; +import * as cxschema from '../../cloud-assembly-schema'; import { Annotations, ArnFormat, @@ -18,6 +19,8 @@ import { TokenComparison, CustomResource, Aws, + ContextProvider, + Arn, } from '../../core'; import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource'; import { AutoDeleteImagesProvider } from '../../custom-resource-handlers/dist/aws-ecr/auto-delete-images-provider.generated'; @@ -599,6 +602,20 @@ export interface RepositoryProps { readonly emptyOnDelete?: boolean; } +/** + * Properties for looking up an existing Repository. + */ +export interface RepositoryLookupOptions { + /** + * The name of the repository. + */ + readonly repositoryName?: string; + /** + * The ARN of the repository. + */ + readonly repositoryArn?: string; +} + export interface RepositoryAttributes { readonly repositoryName: string; readonly repositoryArn: string; @@ -608,6 +625,44 @@ export interface RepositoryAttributes { * Define an ECR repository */ export class Repository extends RepositoryBase { + /** + * Lookup an existing repository + */ + public static fromLookup(scope: Construct, id: string, options: RepositoryLookupOptions): IRepository { + if (Token.isUnresolved(options.repositoryName) || Token.isUnresolved(options.repositoryArn)) { + throw new Error('Cannot look up a repository with a tokenized name or ARN.'); + } + + const response: {[key: string]: any}[] = ContextProvider.getValue(scope, { + provider: cxschema.ContextProvider.CC_API_PROVIDER, + props: { + typeName: 'AWS::ECR::Repository', + exactIdentifier: options.repositoryName, + propertiesToReturn: ['Arn'], + } as cxschema.CcApiContextQuery, + dummyValue: [ + { + Arn: Stack.of(scope).formatArn({ + service: 'ecr', + region: 'us-east-1', + account: '123456789012', + resource: 'repository', + resourceName: 'DUMMY_ARN', + }), + }, + ], + }).value; + + const repository = response[0]; + const lookupRepoName = Arn.split(repository.Arn, ArnFormat.SLASH_RESOURCE_NAME).resourceName; + + if (!lookupRepoName) { + throw new Error(`Unable to look up repository with name: ${options.repositoryArn} in account ${Aws.ACCOUNT_ID}`); + } + + return this.fromRepositoryName(scope, id, lookupRepoName); + } + /** * Import a repository */ From 121fd15c00ab277717653d1820d475c4c77920ff Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sat, 1 Mar 2025 14:34:06 +0900 Subject: [PATCH 02/17] add validation --- packages/aws-cdk-lib/aws-ecr/lib/repository.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 79529bd83e4a6..2b84cb3376a4d 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -633,6 +633,10 @@ export class Repository extends RepositoryBase { throw new Error('Cannot look up a repository with a tokenized name or ARN.'); } + if (!options.repositoryArn && !options.repositoryName) { + throw new Error('At least one of `repositoryName` or `repositoryArn` must be provided.'); + } + const response: {[key: string]: any}[] = ContextProvider.getValue(scope, { provider: cxschema.ContextProvider.CC_API_PROVIDER, props: { From b1df6672fd0adecb9c31bdae3f76058f91a76462 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sat, 1 Mar 2025 16:23:56 +0900 Subject: [PATCH 03/17] temp --- .../LookupStack.assets.json | 20 -- .../LookupStack.template.json | 36 --- .../Stack.assets.json | 34 --- .../Stack.template.json | 165 ------------- .../index.js | 2 - .../cdk.out | 1 - ...efaultTestDeployAssert6B08011C.assets.json | 19 -- ...aultTestDeployAssert6B08011C.template.json | 36 --- .../integ.json | 13 - .../manifest.json | 218 ----------------- .../tree.json | 224 ------------------ .../aws-ecr/test/integ.repository-lookup.ts | 23 +- 12 files changed, 15 insertions(+), 776 deletions(-) delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json deleted file mode 100644 index 58ee63fad0d7d..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.assets.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "40.0.0", - "files": { - "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { - "source": { - "path": "LookupStack.template.json", - "packaging": "file" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json deleted file mode 100644 index ad9d0fb73d1dd..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/LookupStack.template.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json deleted file mode 100644 index 679ff6d397010..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.assets.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "version": "40.0.0", - "files": { - "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { - "source": { - "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", - "packaging": "zip" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - }, - "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98": { - "source": { - "path": "Stack.template.json", - "packaging": "file" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json deleted file mode 100644 index 4fc1e0708963e..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/Stack.template.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "Resources": { - "Repo02AC86CF": { - "Type": "AWS::ECR::Repository", - "Properties": { - "RepositoryName": "my-repo", - "Tags": [ - { - "Key": "aws-cdk:auto-delete-images", - "Value": "true" - } - ] - }, - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "RepoAutoDeleteImagesCustomResource65201E29": { - "Type": "Custom::ECRAutoDeleteImages", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", - "Arn" - ] - }, - "RepositoryName": { - "Ref": "Repo02AC86CF" - } - }, - "DependsOn": [ - "Repo02AC86CF" - ], - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ] - }, - "ManagedPolicyArns": [ - { - "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - } - ], - "Policies": [ - { - "PolicyName": "Inline", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "ecr:BatchDeleteImage", - "ecr:DescribeRepositories", - "ecr:ListImages", - "ecr:ListTagsForResource" - ], - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:test-region:12345678:repository/*" - ] - ] - } - ], - "Condition": { - "StringEquals": { - "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" - } - } - } - ] - } - } - ] - } - }, - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", - "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" - }, - "Timeout": 900, - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", - "Arn" - ] - }, - "Runtime": "nodejs18.x", - "Description": { - "Fn::Join": [ - "", - [ - "Lambda function for auto-deleting images in ", - { - "Ref": "Repo02AC86CF" - }, - " repository." - ] - ] - } - }, - "DependsOn": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - ] - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js deleted file mode 100644 index eff0ff2826a48..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";var C=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var L=(e,o)=>{for(var t in o)c(e,t,{get:o[t],enumerable:!0})},d=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of S(o))!P.call(e,r)&&r!==t&&c(e,r,{get:()=>o[r],enumerable:!(s=w(o,r))||s.enumerable});return e};var l=(e,o,t)=>(t=e!=null?C(A(e)):{},d(o||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>d(c({},"__esModule",{value:!0}),e);var W={};L(W,{autoDeleteHandler:()=>I,handler:()=>k});module.exports=T(W);var h=require("@aws-sdk/client-ecr");var m=l(require("https")),R=l(require("url")),n={sendHttpRequest:x,log:N,includeStackTraces:!0,userHandlerIndex:"./index"},p="AWSCDK::CustomResourceProviderFramework::CREATE_FAILED",D="AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";function y(e){return async(o,t)=>{let s={...o,ResponseURL:"..."};if(n.log(JSON.stringify(s,void 0,2)),o.RequestType==="Delete"&&o.PhysicalResourceId===p){n.log("ignoring DELETE event caused by a failed CREATE event"),await u("SUCCESS",o);return}try{let r=await e(s,t),a=b(o,r);await u("SUCCESS",a)}catch(r){let a={...o,Reason:n.includeStackTraces?r.stack:r.message};a.PhysicalResourceId||(o.RequestType==="Create"?(n.log("CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored"),a.PhysicalResourceId=p):n.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(o)}`)),await u("FAILED",a)}}}function b(e,o={}){let t=o.PhysicalResourceId??e.PhysicalResourceId??e.RequestId;if(e.RequestType==="Delete"&&t!==e.PhysicalResourceId)throw new Error(`DELETE: cannot change the physical resource ID from "${e.PhysicalResourceId}" to "${o.PhysicalResourceId}" during deletion`);return{...e,...o,PhysicalResourceId:t}}async function u(e,o){let t={Status:e,Reason:o.Reason??e,StackId:o.StackId,RequestId:o.RequestId,PhysicalResourceId:o.PhysicalResourceId||D,LogicalResourceId:o.LogicalResourceId,NoEcho:o.NoEcho,Data:o.Data},s=R.parse(o.ResponseURL),r=`${s.protocol}//${s.hostname}/${s.pathname}?***`;n.log("submit response to cloudformation",r,t);let a=JSON.stringify(t),f={hostname:s.hostname,path:s.path,method:"PUT",headers:{"content-type":"","content-length":Buffer.byteLength(a,"utf8")}};await F({attempts:5,sleep:1e3},n.sendHttpRequest)(f,a)}async function x(e,o){return new Promise((t,s)=>{try{let r=m.request(e,a=>{a.resume(),!a.statusCode||a.statusCode>=400?s(new Error(`Unsuccessful HTTP response: ${a.statusCode}`)):t()});r.on("error",s),r.write(o),r.end()}catch(r){s(r)}})}function N(e,...o){console.log(e,...o)}function F(e,o){return async(...t)=>{let s=e.attempts,r=e.sleep;for(;;)try{return await o(...t)}catch(a){if(s--<=0)throw a;await H(Math.floor(Math.random()*r)),r*=2}}}async function H(e){return new Promise(o=>setTimeout(o,e))}var g="aws-cdk:auto-delete-images",i=new h.ECR({}),k=y(I);async function I(e){switch(e.RequestType){case"Create":break;case"Update":return{PhysicalResourceId:(await q(e)).PhysicalResourceId};case"Delete":return U(e.ResourceProperties?.RepositoryName)}}async function q(e){let o=e,t=o.OldResourceProperties?.RepositoryName;return{PhysicalResourceId:o.ResourceProperties?.RepositoryName??t}}async function E(e){let o=await i.listImages(e),t=[],s=[];(o.imageIds??[]).forEach(a=>{"imageTag"in a?s.push(a):t.push(a)});let r=o.nextToken??null;t.length===0&&s.length===0||(s.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:s}),t.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:t}),r&&await E({...e,nextToken:r}))}async function U(e){if(!e)throw new Error("No RepositoryName was provided.");let t=(await i.describeRepositories({repositoryNames:[e]})).repositories?.find(s=>s.repositoryName===e);if(!await _(t?.repositoryArn)){process.stdout.write(`Repository does not have '${g}' tag, skipping cleaning. -`);return}try{await E({repositoryName:e})}catch(s){if(s.name!=="RepositoryNotFoundException")throw s}}async function _(e){return(await i.listTagsForResource({resourceArn:e})).tags?.some(t=>t.Key===g&&t.Value==="true")}0&&(module.exports={autoDeleteHandler,handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out deleted file mode 100644 index 1e02a2deb191b..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out +++ /dev/null @@ -1 +0,0 @@ -{"version":"40.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json deleted file mode 100644 index 03e27a027c527..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "40.0.0", - "files": { - "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { - "source": { - "path": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", - "packaging": "file" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json deleted file mode 100644 index ad9d0fb73d1dd..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json deleted file mode 100644 index 8b6bf4ae159a9..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "enableLookups": true, - "version": "40.0.0", - "testCases": { - "cdk-integ-auto-delete-images/DefaultTest": { - "stacks": [ - "Stack" - ], - "assertionStack": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", - "assertionStackName": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json deleted file mode 100644 index 7583c131cb8d3..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json +++ /dev/null @@ -1,218 +0,0 @@ -{ - "version": "40.0.0", - "artifacts": { - "Stack.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "Stack.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "Stack": { - "type": "aws:cloudformation:stack", - "environment": "aws://12345678/test-region", - "properties": { - "templateFile": "Stack.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "Stack.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "Stack.assets" - ], - "metadata": { - "/Stack/Repo": [ - { - "type": "aws:cdk:analytics:construct", - "data": "*" - } - ], - "/Stack/Repo/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "Repo02AC86CF" - } - ], - "/Stack/Repo/AutoDeleteImagesCustomResource": [ - { - "type": "aws:cdk:analytics:construct", - "data": "*" - } - ], - "/Stack/Repo/AutoDeleteImagesCustomResource/Default": [ - { - "type": "aws:cdk:logicalId", - "data": "RepoAutoDeleteImagesCustomResource65201E29" - } - ], - "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ - { - "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", - "data": true - } - ], - "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - } - ], - "/Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" - } - ], - "/Stack/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/Stack/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "Stack" - }, - "LookupStack.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "LookupStack.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "LookupStack": { - "type": "aws:cloudformation:stack", - "environment": "aws://12345678/test-region", - "properties": { - "templateFile": "LookupStack.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "LookupStack.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "LookupStack.assets" - ], - "metadata": { - "/LookupStack/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/LookupStack/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "LookupStack" - }, - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C": { - "type": "aws:cloudformation:stack", - "environment": "aws://unknown-account/unknown-region", - "properties": { - "templateFile": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" - ], - "metadata": { - "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert" - }, - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - } - }, - "missing": [ - { - "key": "cc-api-provider:account=12345678:exactIdentifier=my-repo:propertiesToReturn.0=Arn:region=test-region:typeName=AWS$:$:ECR$:$:Repository", - "provider": "cc-api-provider", - "props": { - "dummyValue": [ - { - "Arn": "arn:${Token[AWS.Partition.10]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" - } - ], - "account": "12345678", - "region": "test-region", - "typeName": "AWS::ECR::Repository", - "exactIdentifier": "my-repo", - "propertiesToReturn": [ - "Arn" - ], - "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" - } - } - ] -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json deleted file mode 100644 index 918262e8ba36a..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "Stack": { - "id": "Stack", - "path": "Stack", - "children": { - "Repo": { - "id": "Repo", - "path": "Stack/Repo", - "children": { - "Resource": { - "id": "Resource", - "path": "Stack/Repo/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::ECR::Repository", - "aws:cdk:cloudformation:props": { - "repositoryName": "my-repo", - "tags": [ - { - "key": "aws-cdk:auto-delete-images", - "value": "true" - } - ] - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "AutoDeleteImagesCustomResource": { - "id": "AutoDeleteImagesCustomResource", - "path": "Stack/Repo/AutoDeleteImagesCustomResource", - "children": { - "Default": { - "id": "Default", - "path": "Stack/Repo/AutoDeleteImagesCustomResource/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - }, - "Custom::ECRAutoDeleteImagesCustomResourceProvider": { - "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", - "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider", - "children": { - "Staging": { - "id": "Staging", - "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "Role": { - "id": "Role", - "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "Handler": { - "id": "Handler", - "path": "Stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "Stack/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "Stack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "LookupStack": { - "id": "LookupStack", - "path": "LookupStack", - "children": { - "LookupRepo": { - "id": "LookupRepo", - "path": "LookupStack/LookupRepo", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [] - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "LookupStack/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "LookupStack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "cdk-integ-auto-delete-images": { - "id": "cdk-integ-auto-delete-images", - "path": "cdk-integ-auto-delete-images", - "children": { - "DefaultTest": { - "id": "DefaultTest", - "path": "cdk-integ-auto-delete-images/DefaultTest", - "children": { - "Default": { - "id": "Default", - "path": "cdk-integ-auto-delete-images/DefaultTest/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "DeployAssert": { - "id": "DeployAssert", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", - "children": { - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", - "version": "0.0.0" - } - }, - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts index 60fd3a56ce216..1af7115a1f605 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts @@ -1,36 +1,43 @@ import { IntegTest } from '@aws-cdk/integ-tests-alpha'; -import { App, RemovalPolicy, Stack } from 'aws-cdk-lib'; +import { App, CfnOutput, RemovalPolicy, Stack } from 'aws-cdk-lib'; import * as ecr from 'aws-cdk-lib/aws-ecr'; const app = new App(); const repositoryName = 'my-repo'; -const stack = new Stack(app, 'Stack', { +const setupStack = new Stack(app, 'EcrRepoStack', { env: { account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, }, }); -new ecr.Repository(stack, 'Repo', { +new ecr.Repository(setupStack, 'Repo', { repositoryName, removalPolicy: RemovalPolicy.DESTROY, autoDeleteImages: true, }); -const lookupStack = new Stack(app, 'LookupStack', { +const lookupStack = new Stack(app, 'EcrRepoLookupStack', { env: { account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, }, }); - -ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { +new ecr.Repository(lookupStack, 'TestRepo', { + repositoryName: 'test-repo', + removalPolicy: RemovalPolicy.DESTROY, + autoDeleteImages: true, +}); +const lookupRepo = ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { repositoryName, }); +new CfnOutput(lookupStack, 'RepositoryUri', { + value: lookupRepo.repositoryUri, +}); + new IntegTest(app, 'cdk-integ-auto-delete-images', { - enableLookups: true, - testCases: [stack], + testCases: [lookupStack], }); From af60a3cbcd99f4ea2006db6efa06c52b89cf0f35 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sat, 1 Mar 2025 16:50:08 +0900 Subject: [PATCH 04/17] update integ test --- .../EcrRepoLookupStack.assets.json | 34 ++ .../EcrRepoLookupStack.template.json | 181 ++++++++++ ...efaultTestDeployAssert7F088AF3.assets.json | 19 ++ ...aultTestDeployAssert7F088AF3.template.json | 36 ++ .../EcrRepoStack.assets.json | 34 ++ .../EcrRepoStack.template.json | 165 +++++++++ .../cdk.out | 1 + .../integ.json | 15 + .../manifest.json | 266 +++++++++++++++ .../tree.json | 320 ++++++++++++++++++ .../aws-ecr/test/integ.repository-lookup.ts | 15 +- 11 files changed, 1080 insertions(+), 6 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json new file mode 100644 index 0000000000000..062f4fa84b018 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json @@ -0,0 +1,34 @@ +{ + "version": "40.0.0", + "files": { + "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { + "source": { + "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", + "packaging": "zip" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + }, + "cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5": { + "source": { + "path": "EcrRepoLookupStack.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5.json", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json new file mode 100644 index 0000000000000..69fc4f6bde3b8 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json @@ -0,0 +1,181 @@ +{ + "Resources": { + "Repo02AC86CF": { + "Type": "AWS::ECR::Repository", + "Properties": { + "RepositoryName": "test-repo", + "Tags": [ + { + "Key": "aws-cdk:auto-delete-images", + "Value": "true" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "RepoAutoDeleteImagesCustomResource65201E29": { + "Type": "Custom::ECRAutoDeleteImages", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", + "Arn" + ] + }, + "RepositoryName": { + "Ref": "Repo02AC86CF" + } + }, + "DependsOn": [ + "Repo02AC86CF" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ecr:BatchDeleteImage", + "ecr:DescribeRepositories", + "ecr:ListImages", + "ecr:ListTagsForResource" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:test-region:12345678:repository/*" + ] + ] + } + ], + "Condition": { + "StringEquals": { + "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" + } + } + } + ] + } + } + ] + } + }, + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", + "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Description": { + "Fn::Join": [ + "", + [ + "Lambda function for auto-deleting images in ", + { + "Ref": "Repo02AC86CF" + }, + " repository." + ] + ] + } + }, + "DependsOn": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + ] + } + }, + "Outputs": { + "RepositoryUri": { + "Value": { + "Fn::Join": [ + "", + [ + "12345678.dkr.ecr.test-region.", + { + "Ref": "AWS::URLSuffix" + }, + "/DUMMY_ARN" + ] + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets.json new file mode 100644 index 0000000000000..6c5f894f4afdb --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets.json @@ -0,0 +1,19 @@ +{ + "version": "40.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json new file mode 100644 index 0000000000000..552effb094f8c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json @@ -0,0 +1,34 @@ +{ + "version": "40.0.0", + "files": { + "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { + "source": { + "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", + "packaging": "zip" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + }, + "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98": { + "source": { + "path": "EcrRepoStack.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json new file mode 100644 index 0000000000000..4fc1e0708963e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json @@ -0,0 +1,165 @@ +{ + "Resources": { + "Repo02AC86CF": { + "Type": "AWS::ECR::Repository", + "Properties": { + "RepositoryName": "my-repo", + "Tags": [ + { + "Key": "aws-cdk:auto-delete-images", + "Value": "true" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "RepoAutoDeleteImagesCustomResource65201E29": { + "Type": "Custom::ECRAutoDeleteImages", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", + "Arn" + ] + }, + "RepositoryName": { + "Ref": "Repo02AC86CF" + } + }, + "DependsOn": [ + "Repo02AC86CF" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ecr:BatchDeleteImage", + "ecr:DescribeRepositories", + "ecr:ListImages", + "ecr:ListTagsForResource" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:test-region:12345678:repository/*" + ] + ] + } + ], + "Condition": { + "StringEquals": { + "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" + } + } + } + ] + } + } + ] + } + }, + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", + "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Description": { + "Fn::Join": [ + "", + [ + "Lambda function for auto-deleting images in ", + { + "Ref": "Repo02AC86CF" + }, + " repository." + ] + ] + } + }, + "DependsOn": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1e02a2deb191b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"40.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json new file mode 100644 index 0000000000000..77d4358f27355 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json @@ -0,0 +1,15 @@ +{ + "enableLookups": true, + "version": "40.0.0", + "testCases": { + "EcrRepoLookupTest/DefaultTest": { + "stacks": [ + "EcrRepoStack", + "EcrRepoLookupStack" + ], + "stackUpdateWorkflow": false, + "assertionStack": "EcrRepoLookupTest/DefaultTest/DeployAssert", + "assertionStackName": "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json new file mode 100644 index 0000000000000..1e88c0c2d001c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json @@ -0,0 +1,266 @@ +{ + "version": "40.0.0", + "artifacts": { + "EcrRepoStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "EcrRepoStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "EcrRepoStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://12345678/test-region", + "properties": { + "templateFile": "EcrRepoStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "EcrRepoStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "EcrRepoStack.assets" + ], + "metadata": { + "/EcrRepoStack/Repo": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/EcrRepoStack/Repo/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Repo02AC86CF" + } + ], + "/EcrRepoStack/Repo/AutoDeleteImagesCustomResource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/EcrRepoStack/Repo/AutoDeleteImagesCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "RepoAutoDeleteImagesCustomResource65201E29" + } + ], + "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ + { + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true + } + ], + "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + } + ], + "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" + } + ], + "/EcrRepoStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/EcrRepoStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "EcrRepoStack" + }, + "EcrRepoLookupStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "EcrRepoLookupStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "EcrRepoLookupStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://12345678/test-region", + "properties": { + "templateFile": "EcrRepoLookupStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "EcrRepoLookupStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "EcrRepoLookupStack.assets" + ], + "metadata": { + "/EcrRepoLookupStack/Repo": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/EcrRepoLookupStack/Repo/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Repo02AC86CF" + } + ], + "/EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "RepoAutoDeleteImagesCustomResource65201E29" + } + ], + "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ + { + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true + } + ], + "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + } + ], + "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" + } + ], + "/EcrRepoLookupStack/RepositoryUri": [ + { + "type": "aws:cdk:logicalId", + "data": "RepositoryUri" + } + ], + "/EcrRepoLookupStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/EcrRepoLookupStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "EcrRepoLookupStack" + }, + "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3.assets" + ], + "metadata": { + "/EcrRepoLookupTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/EcrRepoLookupTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "EcrRepoLookupTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + }, + "missing": [ + { + "key": "cc-api-provider:account=12345678:exactIdentifier=my-repo:propertiesToReturn.0=Arn:region=test-region:typeName=AWS$:$:ECR$:$:Repository", + "provider": "cc-api-provider", + "props": { + "dummyValue": [ + { + "Arn": "arn:${Token[AWS.Partition.3]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" + } + ], + "account": "12345678", + "region": "test-region", + "typeName": "AWS::ECR::Repository", + "exactIdentifier": "my-repo", + "propertiesToReturn": [ + "Arn" + ], + "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" + } + } + ] +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json new file mode 100644 index 0000000000000..645179f00c4ec --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json @@ -0,0 +1,320 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "EcrRepoStack": { + "id": "EcrRepoStack", + "path": "EcrRepoStack", + "children": { + "Repo": { + "id": "Repo", + "path": "EcrRepoStack/Repo", + "children": { + "Resource": { + "id": "Resource", + "path": "EcrRepoStack/Repo/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECR::Repository", + "aws:cdk:cloudformation:props": { + "repositoryName": "my-repo", + "tags": [ + { + "key": "aws-cdk:auto-delete-images", + "value": "true" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "AutoDeleteImagesCustomResource": { + "id": "AutoDeleteImagesCustomResource", + "path": "EcrRepoStack/Repo/AutoDeleteImagesCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "EcrRepoStack/Repo/AutoDeleteImagesCustomResource/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + }, + "Custom::ECRAutoDeleteImagesCustomResourceProvider": { + "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", + "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Role": { + "id": "Role", + "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Handler": { + "id": "Handler", + "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "EcrRepoStack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "EcrRepoStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "EcrRepoLookupStack": { + "id": "EcrRepoLookupStack", + "path": "EcrRepoLookupStack", + "children": { + "LookupRepo": { + "id": "LookupRepo", + "path": "EcrRepoLookupStack/LookupRepo", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [] + } + }, + "Repo": { + "id": "Repo", + "path": "EcrRepoLookupStack/Repo", + "children": { + "Resource": { + "id": "Resource", + "path": "EcrRepoLookupStack/Repo/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECR::Repository", + "aws:cdk:cloudformation:props": { + "repositoryName": "test-repo", + "tags": [ + { + "key": "aws-cdk:auto-delete-images", + "value": "true" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "AutoDeleteImagesCustomResource": { + "id": "AutoDeleteImagesCustomResource", + "path": "EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + }, + "Custom::ECRAutoDeleteImagesCustomResourceProvider": { + "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", + "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Role": { + "id": "Role", + "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Handler": { + "id": "Handler", + "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "RepositoryUri": { + "id": "RepositoryUri", + "path": "EcrRepoLookupStack/RepositoryUri", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "EcrRepoLookupStack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "EcrRepoLookupStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "EcrRepoLookupTest": { + "id": "EcrRepoLookupTest", + "path": "EcrRepoLookupTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "EcrRepoLookupTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "EcrRepoLookupTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "EcrRepoLookupTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "EcrRepoLookupTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "EcrRepoLookupTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts index 1af7115a1f605..60af34a06c075 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts @@ -25,19 +25,22 @@ const lookupStack = new Stack(app, 'EcrRepoLookupStack', { region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, }, }); -new ecr.Repository(lookupStack, 'TestRepo', { +const lookupRepo = ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { + repositoryName, +}); +new ecr.Repository(lookupStack, 'Repo', { repositoryName: 'test-repo', removalPolicy: RemovalPolicy.DESTROY, autoDeleteImages: true, }); -const lookupRepo = ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { - repositoryName, -}); new CfnOutput(lookupStack, 'RepositoryUri', { value: lookupRepo.repositoryUri, }); +// lookupStack.addDependency(setupStack); -new IntegTest(app, 'cdk-integ-auto-delete-images', { - testCases: [lookupStack], +new IntegTest(app, 'EcrRepoLookupTest', { + enableLookups: true, + stackUpdateWorkflow: false, + testCases: [setupStack, lookupStack], }); From b31a51a1f3ffc714da1d0df538c69e0e9fac928f Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sun, 2 Mar 2025 09:40:52 +0900 Subject: [PATCH 05/17] update integ --- .../index.js | 2 - .../aws-ecr-integ-stack.assets.json | 32 -- .../aws-ecr-integ-stack.template.json | 359 ------------------ .../cdk.out | 1 - ...efaultTestDeployAssert6B08011C.assets.json | 19 - ...aultTestDeployAssert6B08011C.template.json | 36 -- .../integ.json | 13 - .../manifest.json | 143 ------- .../tree.json | 199 ---------- .../EcrRepoLookupStack.assets.json | 18 +- .../EcrRepoLookupStack.template.json | 143 +++---- .../EcrRepoStack.assets.json | 34 -- .../EcrRepoStack.template.json | 165 -------- .../integ.json | 9 +- .../manifest.json | 140 ++----- .../tree.json | 312 +++++++-------- .../aws-ecr/test/integ.repository-lookup.ts | 33 +- 17 files changed, 247 insertions(+), 1411 deletions(-) delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json delete mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js deleted file mode 100644 index eff0ff2826a48..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";var C=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var L=(e,o)=>{for(var t in o)c(e,t,{get:o[t],enumerable:!0})},d=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of S(o))!P.call(e,r)&&r!==t&&c(e,r,{get:()=>o[r],enumerable:!(s=w(o,r))||s.enumerable});return e};var l=(e,o,t)=>(t=e!=null?C(A(e)):{},d(o||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>d(c({},"__esModule",{value:!0}),e);var W={};L(W,{autoDeleteHandler:()=>I,handler:()=>k});module.exports=T(W);var h=require("@aws-sdk/client-ecr");var m=l(require("https")),R=l(require("url")),n={sendHttpRequest:x,log:N,includeStackTraces:!0,userHandlerIndex:"./index"},p="AWSCDK::CustomResourceProviderFramework::CREATE_FAILED",D="AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";function y(e){return async(o,t)=>{let s={...o,ResponseURL:"..."};if(n.log(JSON.stringify(s,void 0,2)),o.RequestType==="Delete"&&o.PhysicalResourceId===p){n.log("ignoring DELETE event caused by a failed CREATE event"),await u("SUCCESS",o);return}try{let r=await e(s,t),a=b(o,r);await u("SUCCESS",a)}catch(r){let a={...o,Reason:n.includeStackTraces?r.stack:r.message};a.PhysicalResourceId||(o.RequestType==="Create"?(n.log("CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored"),a.PhysicalResourceId=p):n.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(o)}`)),await u("FAILED",a)}}}function b(e,o={}){let t=o.PhysicalResourceId??e.PhysicalResourceId??e.RequestId;if(e.RequestType==="Delete"&&t!==e.PhysicalResourceId)throw new Error(`DELETE: cannot change the physical resource ID from "${e.PhysicalResourceId}" to "${o.PhysicalResourceId}" during deletion`);return{...e,...o,PhysicalResourceId:t}}async function u(e,o){let t={Status:e,Reason:o.Reason??e,StackId:o.StackId,RequestId:o.RequestId,PhysicalResourceId:o.PhysicalResourceId||D,LogicalResourceId:o.LogicalResourceId,NoEcho:o.NoEcho,Data:o.Data},s=R.parse(o.ResponseURL),r=`${s.protocol}//${s.hostname}/${s.pathname}?***`;n.log("submit response to cloudformation",r,t);let a=JSON.stringify(t),f={hostname:s.hostname,path:s.path,method:"PUT",headers:{"content-type":"","content-length":Buffer.byteLength(a,"utf8")}};await F({attempts:5,sleep:1e3},n.sendHttpRequest)(f,a)}async function x(e,o){return new Promise((t,s)=>{try{let r=m.request(e,a=>{a.resume(),!a.statusCode||a.statusCode>=400?s(new Error(`Unsuccessful HTTP response: ${a.statusCode}`)):t()});r.on("error",s),r.write(o),r.end()}catch(r){s(r)}})}function N(e,...o){console.log(e,...o)}function F(e,o){return async(...t)=>{let s=e.attempts,r=e.sleep;for(;;)try{return await o(...t)}catch(a){if(s--<=0)throw a;await H(Math.floor(Math.random()*r)),r*=2}}}async function H(e){return new Promise(o=>setTimeout(o,e))}var g="aws-cdk:auto-delete-images",i=new h.ECR({}),k=y(I);async function I(e){switch(e.RequestType){case"Create":break;case"Update":return{PhysicalResourceId:(await q(e)).PhysicalResourceId};case"Delete":return U(e.ResourceProperties?.RepositoryName)}}async function q(e){let o=e,t=o.OldResourceProperties?.RepositoryName;return{PhysicalResourceId:o.ResourceProperties?.RepositoryName??t}}async function E(e){let o=await i.listImages(e),t=[],s=[];(o.imageIds??[]).forEach(a=>{"imageTag"in a?s.push(a):t.push(a)});let r=o.nextToken??null;t.length===0&&s.length===0||(s.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:s}),t.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:t}),r&&await E({...e,nextToken:r}))}async function U(e){if(!e)throw new Error("No RepositoryName was provided.");let t=(await i.describeRepositories({repositoryNames:[e]})).repositories?.find(s=>s.repositoryName===e);if(!await _(t?.repositoryArn)){process.stdout.write(`Repository does not have '${g}' tag, skipping cleaning. -`);return}try{await E({repositoryName:e})}catch(s){if(s.name!=="RepositoryNotFoundException")throw s}}async function _(e){return(await i.listTagsForResource({resourceArn:e})).tags?.some(t=>t.Key===g&&t.Value==="true")}0&&(module.exports={autoDeleteHandler,handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json deleted file mode 100644 index ae9d8d30b71c2..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "36.0.0", - "files": { - "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { - "source": { - "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", - "packaging": "zip" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - }, - "d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46": { - "source": { - "path": "aws-ecr-integ-stack.template.json", - "packaging": "file" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46.json", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json deleted file mode 100644 index ea03b3bb73383..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json +++ /dev/null @@ -1,359 +0,0 @@ -{ - "Resources": { - "Repo02AC86CF": { - "Type": "AWS::ECR::Repository", - "Properties": { - "RepositoryName": "delete-even-if-containing-images", - "Tags": [ - { - "Key": "aws-cdk:auto-delete-images", - "Value": "true" - } - ] - }, - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "RepoAutoDeleteImagesCustomResource65201E29": { - "Type": "Custom::ECRAutoDeleteImages", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", - "Arn" - ] - }, - "RepositoryName": { - "Ref": "Repo02AC86CF" - } - }, - "DependsOn": [ - "Repo02AC86CF" - ], - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ] - }, - "ManagedPolicyArns": [ - { - "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - } - ], - "Policies": [ - { - "PolicyName": "Inline", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "ecr:BatchDeleteImage", - "ecr:DescribeRepositories", - "ecr:ListImages", - "ecr:ListTagsForResource" - ], - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":repository/*" - ] - ] - } - ], - "Condition": { - "StringEquals": { - "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" - } - } - } - ] - } - } - ] - } - }, - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" - }, - "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" - }, - "Timeout": 900, - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", - "Arn" - ] - }, - "Runtime": { - "Fn::FindInMap": [ - "LatestNodeRuntimeMap", - { - "Ref": "AWS::Region" - }, - "value" - ] - }, - "Description": { - "Fn::Join": [ - "", - [ - "Lambda function for auto-deleting images in ", - { - "Ref": "Repo02AC86CF" - }, - " repository." - ] - ] - } - }, - "DependsOn": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - ] - } - }, - "Mappings": { - "LatestNodeRuntimeMap": { - "af-south-1": { - "value": "nodejs20.x" - }, - "ap-east-1": { - "value": "nodejs20.x" - }, - "ap-northeast-1": { - "value": "nodejs20.x" - }, - "ap-northeast-2": { - "value": "nodejs20.x" - }, - "ap-northeast-3": { - "value": "nodejs20.x" - }, - "ap-south-1": { - "value": "nodejs20.x" - }, - "ap-south-2": { - "value": "nodejs20.x" - }, - "ap-southeast-1": { - "value": "nodejs20.x" - }, - "ap-southeast-2": { - "value": "nodejs20.x" - }, - "ap-southeast-3": { - "value": "nodejs20.x" - }, - "ap-southeast-4": { - "value": "nodejs20.x" - }, - "ap-southeast-5": { - "value": "nodejs20.x" - }, - "ap-southeast-7": { - "value": "nodejs20.x" - }, - "ca-central-1": { - "value": "nodejs20.x" - }, - "ca-west-1": { - "value": "nodejs20.x" - }, - "cn-north-1": { - "value": "nodejs20.x" - }, - "cn-northwest-1": { - "value": "nodejs20.x" - }, - "eu-central-1": { - "value": "nodejs20.x" - }, - "eu-central-2": { - "value": "nodejs20.x" - }, - "eu-isoe-west-1": { - "value": "nodejs18.x" - }, - "eu-north-1": { - "value": "nodejs20.x" - }, - "eu-south-1": { - "value": "nodejs20.x" - }, - "eu-south-2": { - "value": "nodejs20.x" - }, - "eu-west-1": { - "value": "nodejs20.x" - }, - "eu-west-2": { - "value": "nodejs20.x" - }, - "eu-west-3": { - "value": "nodejs20.x" - }, - "il-central-1": { - "value": "nodejs20.x" - }, - "me-central-1": { - "value": "nodejs20.x" - }, - "me-south-1": { - "value": "nodejs20.x" - }, - "mx-central-1": { - "value": "nodejs20.x" - }, - "sa-east-1": { - "value": "nodejs20.x" - }, - "us-east-1": { - "value": "nodejs20.x" - }, - "us-east-2": { - "value": "nodejs20.x" - }, - "us-gov-east-1": { - "value": "nodejs20.x" - }, - "us-gov-west-1": { - "value": "nodejs20.x" - }, - "us-iso-east-1": { - "value": "nodejs18.x" - }, - "us-iso-west-1": { - "value": "nodejs18.x" - }, - "us-isob-east-1": { - "value": "nodejs18.x" - }, - "us-west-1": { - "value": "nodejs20.x" - }, - "us-west-2": { - "value": "nodejs20.x" - } - } - }, - "Outputs": { - "RepositoryURI": { - "Value": { - "Fn::Join": [ - "", - [ - { - "Fn::Select": [ - 4, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "Repo02AC86CF", - "Arn" - ] - } - ] - } - ] - }, - ".dkr.ecr.", - { - "Fn::Select": [ - 3, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "Repo02AC86CF", - "Arn" - ] - } - ] - } - ] - }, - ".", - { - "Ref": "AWS::URLSuffix" - }, - "/", - { - "Ref": "Repo02AC86CF" - } - ] - ] - } - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out deleted file mode 100644 index 1f0068d32659a..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out +++ /dev/null @@ -1 +0,0 @@ -{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json deleted file mode 100644 index b0b910be05e51..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "36.0.0", - "files": { - "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { - "source": { - "path": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", - "packaging": "file" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json deleted file mode 100644 index ad9d0fb73d1dd..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json deleted file mode 100644 index 95645734bb0da..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "36.0.0", - "testCases": { - "cdk-integ-auto-delete-images/DefaultTest": { - "stacks": [ - "aws-ecr-integ-stack" - ], - "diffAssets": true, - "assertionStack": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", - "assertionStackName": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json deleted file mode 100644 index b80619df53977..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "version": "36.0.0", - "artifacts": { - "aws-ecr-integ-stack.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "aws-ecr-integ-stack.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "aws-ecr-integ-stack": { - "type": "aws:cloudformation:stack", - "environment": "aws://unknown-account/unknown-region", - "properties": { - "templateFile": "aws-ecr-integ-stack.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "aws-ecr-integ-stack.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "aws-ecr-integ-stack.assets" - ], - "metadata": { - "/aws-ecr-integ-stack/Repo/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "Repo02AC86CF" - } - ], - "/aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource/Default": [ - { - "type": "aws:cdk:logicalId", - "data": "RepoAutoDeleteImagesCustomResource65201E29" - } - ], - "/aws-ecr-integ-stack/LatestNodeRuntimeMap": [ - { - "type": "aws:cdk:logicalId", - "data": "LatestNodeRuntimeMap" - } - ], - "/aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - } - ], - "/aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" - } - ], - "/aws-ecr-integ-stack/RepositoryURI": [ - { - "type": "aws:cdk:logicalId", - "data": "RepositoryURI" - } - ], - "/aws-ecr-integ-stack/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/aws-ecr-integ-stack/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "aws-ecr-integ-stack" - }, - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C": { - "type": "aws:cloudformation:stack", - "environment": "aws://unknown-account/unknown-region", - "properties": { - "templateFile": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" - ], - "metadata": { - "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert" - }, - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json deleted file mode 100644 index 784e2913b4a39..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json +++ /dev/null @@ -1,199 +0,0 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "aws-ecr-integ-stack": { - "id": "aws-ecr-integ-stack", - "path": "aws-ecr-integ-stack", - "children": { - "Repo": { - "id": "Repo", - "path": "aws-ecr-integ-stack/Repo", - "children": { - "Resource": { - "id": "Resource", - "path": "aws-ecr-integ-stack/Repo/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::ECR::Repository", - "aws:cdk:cloudformation:props": { - "repositoryName": "delete-even-if-containing-images", - "tags": [ - { - "key": "aws-cdk:auto-delete-images", - "value": "true" - } - ] - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecr.CfnRepository", - "version": "0.0.0" - } - }, - "AutoDeleteImagesCustomResource": { - "id": "AutoDeleteImagesCustomResource", - "path": "aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource", - "children": { - "Default": { - "id": "Default", - "path": "aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource/Default", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnResource", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.CustomResource", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecr.Repository", - "version": "0.0.0" - } - }, - "LatestNodeRuntimeMap": { - "id": "LatestNodeRuntimeMap", - "path": "aws-ecr-integ-stack/LatestNodeRuntimeMap", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnMapping", - "version": "0.0.0" - } - }, - "Custom::ECRAutoDeleteImagesCustomResourceProvider": { - "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", - "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider", - "children": { - "Staging": { - "id": "Staging", - "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", - "constructInfo": { - "fqn": "aws-cdk-lib.AssetStaging", - "version": "0.0.0" - } - }, - "Role": { - "id": "Role", - "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnResource", - "version": "0.0.0" - } - }, - "Handler": { - "id": "Handler", - "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnResource", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.CustomResourceProviderBase", - "version": "0.0.0" - } - }, - "RepositoryURI": { - "id": "RepositoryURI", - "path": "aws-ecr-integ-stack/RepositoryURI", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "aws-ecr-integ-stack/BootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "aws-ecr-integ-stack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" - } - }, - "cdk-integ-auto-delete-images": { - "id": "cdk-integ-auto-delete-images", - "path": "cdk-integ-auto-delete-images", - "children": { - "DefaultTest": { - "id": "DefaultTest", - "path": "cdk-integ-auto-delete-images/DefaultTest", - "children": { - "Default": { - "id": "Default", - "path": "cdk-integ-auto-delete-images/DefaultTest/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0" - } - }, - "DeployAssert": { - "id": "DeployAssert", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", - "children": { - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", - "version": "0.0.0" - } - }, - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json index 062f4fa84b018..6a2cd9f16e379 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json @@ -1,21 +1,7 @@ { "version": "40.0.0", "files": { - "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { - "source": { - "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", - "packaging": "zip" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - }, - "cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5": { + "4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b": { "source": { "path": "EcrRepoLookupStack.template.json", "packaging": "file" @@ -23,7 +9,7 @@ "destinations": { "12345678-test-region": { "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5.json", + "objectKey": "4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b.json", "region": "test-region", "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json index 69fc4f6bde3b8..b247c7d6df6ae 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json @@ -1,43 +1,9 @@ { "Resources": { - "Repo02AC86CF": { - "Type": "AWS::ECR::Repository", - "Properties": { - "RepositoryName": "test-repo", - "Tags": [ - { - "Key": "aws-cdk:auto-delete-images", - "Value": "true" - } - ] - }, - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "RepoAutoDeleteImagesCustomResource65201E29": { - "Type": "Custom::ECRAutoDeleteImages", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", - "Arn" - ] - }, - "RepositoryName": { - "Ref": "Repo02AC86CF" - } - }, - "DependsOn": [ - "Repo02AC86CF" - ], - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { + "LambdaServiceRoleA8ED4D3B": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sts:AssumeRole", @@ -46,85 +12,78 @@ "Service": "lambda.amazonaws.com" } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ { - "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - } - ], - "Policies": [ - { - "PolicyName": "Inline", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Fn::Join": [ + "", + [ + "arn:", { - "Effect": "Allow", - "Action": [ - "ecr:BatchDeleteImage", - "ecr:DescribeRepositories", - "ecr:ListImages", - "ecr:ListTagsForResource" - ], - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:test-region:12345678:repository/*" - ] - ] - } - ], - "Condition": { - "StringEquals": { - "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" - } - } - } + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ] + ] + } + ] + } + }, + "LambdaServiceRoleDefaultPolicyDAE46E21": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ecr:DescribeImages", + "ecr:DescribeRepositories" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:test-region:12345678:repository/DUMMY_ARN" + ] + ] + } } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LambdaServiceRoleDefaultPolicyDAE46E21", + "Roles": [ + { + "Ref": "LambdaServiceRoleA8ED4D3B" } ] } }, - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { + "LambdaD247545B": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", - "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" + "ZipFile": "exports.handler = async function(event, context) { return \"Hello, World!\"; }" }, - "Timeout": 900, - "MemorySize": 128, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", + "LambdaServiceRoleA8ED4D3B", "Arn" ] }, - "Runtime": "nodejs18.x", - "Description": { - "Fn::Join": [ - "", - [ - "Lambda function for auto-deleting images in ", - { - "Ref": "Repo02AC86CF" - }, - " repository." - ] - ] - } + "Runtime": "nodejs20.x" }, "DependsOn": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + "LambdaServiceRoleDefaultPolicyDAE46E21", + "LambdaServiceRoleA8ED4D3B" ] } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json deleted file mode 100644 index 552effb094f8c..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.assets.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "version": "40.0.0", - "files": { - "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { - "source": { - "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", - "packaging": "zip" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - }, - "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98": { - "source": { - "path": "EcrRepoStack.template.json", - "packaging": "file" - }, - "destinations": { - "12345678-test-region": { - "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", - "region": "test-region", - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json deleted file mode 100644 index 4fc1e0708963e..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoStack.template.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "Resources": { - "Repo02AC86CF": { - "Type": "AWS::ECR::Repository", - "Properties": { - "RepositoryName": "my-repo", - "Tags": [ - { - "Key": "aws-cdk:auto-delete-images", - "Value": "true" - } - ] - }, - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "RepoAutoDeleteImagesCustomResource65201E29": { - "Type": "Custom::ECRAutoDeleteImages", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", - "Arn" - ] - }, - "RepositoryName": { - "Ref": "Repo02AC86CF" - } - }, - "DependsOn": [ - "Repo02AC86CF" - ], - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ] - }, - "ManagedPolicyArns": [ - { - "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - } - ], - "Policies": [ - { - "PolicyName": "Inline", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "ecr:BatchDeleteImage", - "ecr:DescribeRepositories", - "ecr:ListImages", - "ecr:ListTagsForResource" - ], - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:test-region:12345678:repository/*" - ] - ] - } - ], - "Condition": { - "StringEquals": { - "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" - } - } - } - ] - } - } - ] - } - }, - "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "cdk-hnb659fds-assets-12345678-test-region", - "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" - }, - "Timeout": 900, - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", - "Arn" - ] - }, - "Runtime": "nodejs18.x", - "Description": { - "Fn::Join": [ - "", - [ - "Lambda function for auto-deleting images in ", - { - "Ref": "Repo02AC86CF" - }, - " repository." - ] - ] - } - }, - "DependsOn": [ - "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - ] - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json index 77d4358f27355..d7ae2c83ea6d2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/integ.json @@ -4,9 +4,16 @@ "testCases": { "EcrRepoLookupTest/DefaultTest": { "stacks": [ - "EcrRepoStack", "EcrRepoLookupStack" ], + "hooks": { + "preDeploy": [ + "aws ecr create-repository --repository-name my-repo" + ], + "postDeploy": [ + "aws ecr delete-repository --repository-name my-repo --force" + ] + }, "stackUpdateWorkflow": false, "assertionStack": "EcrRepoLookupTest/DefaultTest/DeployAssert", "assertionStackName": "EcrRepoLookupTestDefaultTestDeployAssert7F088AF3" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json index 1e88c0c2d001c..e6b5ccfef515e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json @@ -1,28 +1,28 @@ { "version": "40.0.0", "artifacts": { - "EcrRepoStack.assets": { + "EcrRepoLookupStack.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "EcrRepoStack.assets.json", + "file": "EcrRepoLookupStack.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "EcrRepoStack": { + "EcrRepoLookupStack": { "type": "aws:cloudformation:stack", "environment": "aws://12345678/test-region", "properties": { - "templateFile": "EcrRepoStack.template.json", + "templateFile": "EcrRepoLookupStack.template.json", "terminationProtection": false, "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/93b6be9cf97c17c486acf50de7631d19c095f37f5fbb99f332bd36f187858a98.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "EcrRepoStack.assets" + "EcrRepoLookupStack.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", @@ -31,139 +31,73 @@ } }, "dependencies": [ - "EcrRepoStack.assets" + "EcrRepoLookupStack.assets" ], "metadata": { - "/EcrRepoStack/Repo": [ + "/EcrRepoLookupStack/Lambda": [ { "type": "aws:cdk:analytics:construct", "data": "*" } ], - "/EcrRepoStack/Repo/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "Repo02AC86CF" - } - ], - "/EcrRepoStack/Repo/AutoDeleteImagesCustomResource": [ + "/EcrRepoLookupStack/Lambda/ServiceRole": [ { "type": "aws:cdk:analytics:construct", "data": "*" - } - ], - "/EcrRepoStack/Repo/AutoDeleteImagesCustomResource/Default": [ - { - "type": "aws:cdk:logicalId", - "data": "RepoAutoDeleteImagesCustomResource65201E29" - } - ], - "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ + }, { - "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", - "data": true - } - ], - "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" - } - ], - "/EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ - { - "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" - } - ], - "/EcrRepoStack/BootstrapVersion": [ + "type": "aws:cdk:analytics:method", + "data": "*" + }, { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/EcrRepoStack/CheckBootstrapVersion": [ + "type": "aws:cdk:analytics:method", + "data": "*" + }, { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" + "type": "aws:cdk:analytics:method", + "data": "*" } - ] - }, - "displayName": "EcrRepoStack" - }, - "EcrRepoLookupStack.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "EcrRepoLookupStack.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "EcrRepoLookupStack": { - "type": "aws:cloudformation:stack", - "environment": "aws://12345678/test-region", - "properties": { - "templateFile": "EcrRepoLookupStack.template.json", - "terminationProtection": false, - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/cd1f89eebd54c908a25074d88f331c245b1f023c0b66b3f1533b244e7bf7d5d5.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "EcrRepoLookupStack.assets" ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "EcrRepoLookupStack.assets" - ], - "metadata": { - "/EcrRepoLookupStack/Repo": [ + "/EcrRepoLookupStack/Lambda/ServiceRole/ImportServiceRole": [ { "type": "aws:cdk:analytics:construct", "data": "*" } ], - "/EcrRepoLookupStack/Repo/Resource": [ + "/EcrRepoLookupStack/Lambda/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", - "data": "Repo02AC86CF" + "data": "LambdaServiceRoleA8ED4D3B" } ], - "/EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource": [ + "/EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy": [ { "type": "aws:cdk:analytics:construct", "data": "*" - } - ], - "/EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource/Default": [ + }, { - "type": "aws:cdk:logicalId", - "data": "RepoAutoDeleteImagesCustomResource65201E29" - } - ], - "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider": [ + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, { - "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", - "data": true + "type": "aws:cdk:analytics:method", + "data": "*" } ], - "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ + "/EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy/Resource": [ { "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + "data": "LambdaServiceRoleDefaultPolicyDAE46E21" } ], - "/EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ + "/EcrRepoLookupStack/Lambda/Resource": [ { "type": "aws:cdk:logicalId", - "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" + "data": "LambdaD247545B" } ], "/EcrRepoLookupStack/RepositoryUri": [ @@ -249,7 +183,7 @@ "props": { "dummyValue": [ { - "Arn": "arn:${Token[AWS.Partition.3]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" + "Arn": "arn:${Token[AWS.Partition.6]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" } ], "account": "12345678", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json index 645179f00c4ec..f95bb08eec1fe 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json @@ -4,120 +4,6 @@ "id": "App", "path": "", "children": { - "EcrRepoStack": { - "id": "EcrRepoStack", - "path": "EcrRepoStack", - "children": { - "Repo": { - "id": "Repo", - "path": "EcrRepoStack/Repo", - "children": { - "Resource": { - "id": "Resource", - "path": "EcrRepoStack/Repo/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::ECR::Repository", - "aws:cdk:cloudformation:props": { - "repositoryName": "my-repo", - "tags": [ - { - "key": "aws-cdk:auto-delete-images", - "value": "true" - } - ] - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "AutoDeleteImagesCustomResource": { - "id": "AutoDeleteImagesCustomResource", - "path": "EcrRepoStack/Repo/AutoDeleteImagesCustomResource", - "children": { - "Default": { - "id": "Default", - "path": "EcrRepoStack/Repo/AutoDeleteImagesCustomResource/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - }, - "Custom::ECRAutoDeleteImagesCustomResourceProvider": { - "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", - "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider", - "children": { - "Staging": { - "id": "Staging", - "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "Role": { - "id": "Role", - "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "Handler": { - "id": "Handler", - "path": "EcrRepoStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "EcrRepoStack/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "EcrRepoStack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, "EcrRepoLookupStack": { "id": "EcrRepoLookupStack", "path": "EcrRepoLookupStack", @@ -131,83 +17,154 @@ "metadata": [] } }, - "Repo": { - "id": "Repo", - "path": "EcrRepoLookupStack/Repo", + "Lambda": { + "id": "Lambda", + "path": "EcrRepoLookupStack/Lambda", "children": { - "Resource": { - "id": "Resource", - "path": "EcrRepoLookupStack/Repo/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::ECR::Repository", - "aws:cdk:cloudformation:props": { - "repositoryName": "test-repo", - "tags": [ - { - "key": "aws-cdk:auto-delete-images", - "value": "true" - } - ] - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "AutoDeleteImagesCustomResource": { - "id": "AutoDeleteImagesCustomResource", - "path": "EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource", + "ServiceRole": { + "id": "ServiceRole", + "path": "EcrRepoLookupStack/Lambda/ServiceRole", "children": { - "Default": { - "id": "Default", - "path": "EcrRepoLookupStack/Repo/AutoDeleteImagesCustomResource/Default", + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "EcrRepoLookupStack/Lambda/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*" + ] + } + }, + "Resource": { + "id": "Resource", + "path": "EcrRepoLookupStack/Lambda/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.4.2" } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "ecr:DescribeImages", + "ecr:DescribeRepositories" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:test-region:12345678:repository/DUMMY_ARN" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "LambdaServiceRoleDefaultPolicyDAE46E21", + "roles": [ + { + "Ref": "LambdaServiceRoleA8ED4D3B" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2", + "metadata": [ + "*", + "*", + "*", + "*" + ] + } } }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.4.2", "metadata": [ + "*", + "*", + "*", "*" ] } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - }, - "Custom::ECRAutoDeleteImagesCustomResourceProvider": { - "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", - "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider", - "children": { - "Staging": { - "id": "Staging", - "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } }, - "Role": { - "id": "Role", - "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "Handler": { - "id": "Handler", - "path": "EcrRepoLookupStack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", + "Resource": { + "id": "Resource", + "path": "EcrRepoLookupStack/Lambda/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = async function(event, context) { return \"Hello, World!\"; }" + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "LambdaServiceRoleA8ED4D3B", + "Arn" + ] + }, + "runtime": "nodejs20.x" + } + }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.4.2" @@ -216,7 +173,10 @@ }, "constructInfo": { "fqn": "constructs.Construct", - "version": "10.4.2" + "version": "10.4.2", + "metadata": [ + "*" + ] } }, "RepositoryUri": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts index 60af34a06c075..825ecfeedfb41 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.ts @@ -1,24 +1,12 @@ import { IntegTest } from '@aws-cdk/integ-tests-alpha'; -import { App, CfnOutput, RemovalPolicy, Stack } from 'aws-cdk-lib'; +import { App, CfnOutput, Stack } from 'aws-cdk-lib'; import * as ecr from 'aws-cdk-lib/aws-ecr'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; const app = new App(); const repositoryName = 'my-repo'; -const setupStack = new Stack(app, 'EcrRepoStack', { - env: { - account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, - region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION, - }, -}); - -new ecr.Repository(setupStack, 'Repo', { - repositoryName, - removalPolicy: RemovalPolicy.DESTROY, - autoDeleteImages: true, -}); - const lookupStack = new Stack(app, 'EcrRepoLookupStack', { env: { account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT, @@ -28,19 +16,24 @@ const lookupStack = new Stack(app, 'EcrRepoLookupStack', { const lookupRepo = ecr.Repository.fromLookup(lookupStack, 'LookupRepo', { repositoryName, }); -new ecr.Repository(lookupStack, 'Repo', { - repositoryName: 'test-repo', - removalPolicy: RemovalPolicy.DESTROY, - autoDeleteImages: true, +const testFunction = new lambda.Function(lookupStack, 'Lambda', { + runtime: lambda.Runtime.NODEJS_20_X, + handler: 'index.handler', + code: lambda.Code.fromInline('exports.handler = async function(event, context) { return "Hello, World!"; }'), }); +lookupRepo.grantRead(testFunction); new CfnOutput(lookupStack, 'RepositoryUri', { value: lookupRepo.repositoryUri, }); -// lookupStack.addDependency(setupStack); new IntegTest(app, 'EcrRepoLookupTest', { enableLookups: true, stackUpdateWorkflow: false, - testCases: [setupStack, lookupStack], + testCases: [lookupStack], + // create a repository before the test and delete it after + hooks: { + preDeploy: [`aws ecr create-repository --repository-name ${repositoryName}`], + postDeploy: [`aws ecr delete-repository --repository-name ${repositoryName} --force`], + }, }); From 08b9fbc78e2abe7376a5bafb1d75cee923b2e5f9 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sun, 2 Mar 2025 09:44:45 +0900 Subject: [PATCH 06/17] restore --- .../index.js | 2 + .../aws-ecr-integ-stack.assets.json | 32 ++ .../aws-ecr-integ-stack.template.json | 359 ++++++++++++++++++ .../cdk.out | 1 + ...efaultTestDeployAssert6B08011C.assets.json | 19 + ...aultTestDeployAssert6B08011C.template.json | 36 ++ .../integ.json | 13 + .../manifest.json | 143 +++++++ .../tree.json | 199 ++++++++++ 9 files changed, 804 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js new file mode 100644 index 0000000000000..eff0ff2826a48 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160/index.js @@ -0,0 +1,2 @@ +"use strict";var C=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var L=(e,o)=>{for(var t in o)c(e,t,{get:o[t],enumerable:!0})},d=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of S(o))!P.call(e,r)&&r!==t&&c(e,r,{get:()=>o[r],enumerable:!(s=w(o,r))||s.enumerable});return e};var l=(e,o,t)=>(t=e!=null?C(A(e)):{},d(o||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>d(c({},"__esModule",{value:!0}),e);var W={};L(W,{autoDeleteHandler:()=>I,handler:()=>k});module.exports=T(W);var h=require("@aws-sdk/client-ecr");var m=l(require("https")),R=l(require("url")),n={sendHttpRequest:x,log:N,includeStackTraces:!0,userHandlerIndex:"./index"},p="AWSCDK::CustomResourceProviderFramework::CREATE_FAILED",D="AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";function y(e){return async(o,t)=>{let s={...o,ResponseURL:"..."};if(n.log(JSON.stringify(s,void 0,2)),o.RequestType==="Delete"&&o.PhysicalResourceId===p){n.log("ignoring DELETE event caused by a failed CREATE event"),await u("SUCCESS",o);return}try{let r=await e(s,t),a=b(o,r);await u("SUCCESS",a)}catch(r){let a={...o,Reason:n.includeStackTraces?r.stack:r.message};a.PhysicalResourceId||(o.RequestType==="Create"?(n.log("CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored"),a.PhysicalResourceId=p):n.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(o)}`)),await u("FAILED",a)}}}function b(e,o={}){let t=o.PhysicalResourceId??e.PhysicalResourceId??e.RequestId;if(e.RequestType==="Delete"&&t!==e.PhysicalResourceId)throw new Error(`DELETE: cannot change the physical resource ID from "${e.PhysicalResourceId}" to "${o.PhysicalResourceId}" during deletion`);return{...e,...o,PhysicalResourceId:t}}async function u(e,o){let t={Status:e,Reason:o.Reason??e,StackId:o.StackId,RequestId:o.RequestId,PhysicalResourceId:o.PhysicalResourceId||D,LogicalResourceId:o.LogicalResourceId,NoEcho:o.NoEcho,Data:o.Data},s=R.parse(o.ResponseURL),r=`${s.protocol}//${s.hostname}/${s.pathname}?***`;n.log("submit response to cloudformation",r,t);let a=JSON.stringify(t),f={hostname:s.hostname,path:s.path,method:"PUT",headers:{"content-type":"","content-length":Buffer.byteLength(a,"utf8")}};await F({attempts:5,sleep:1e3},n.sendHttpRequest)(f,a)}async function x(e,o){return new Promise((t,s)=>{try{let r=m.request(e,a=>{a.resume(),!a.statusCode||a.statusCode>=400?s(new Error(`Unsuccessful HTTP response: ${a.statusCode}`)):t()});r.on("error",s),r.write(o),r.end()}catch(r){s(r)}})}function N(e,...o){console.log(e,...o)}function F(e,o){return async(...t)=>{let s=e.attempts,r=e.sleep;for(;;)try{return await o(...t)}catch(a){if(s--<=0)throw a;await H(Math.floor(Math.random()*r)),r*=2}}}async function H(e){return new Promise(o=>setTimeout(o,e))}var g="aws-cdk:auto-delete-images",i=new h.ECR({}),k=y(I);async function I(e){switch(e.RequestType){case"Create":break;case"Update":return{PhysicalResourceId:(await q(e)).PhysicalResourceId};case"Delete":return U(e.ResourceProperties?.RepositoryName)}}async function q(e){let o=e,t=o.OldResourceProperties?.RepositoryName;return{PhysicalResourceId:o.ResourceProperties?.RepositoryName??t}}async function E(e){let o=await i.listImages(e),t=[],s=[];(o.imageIds??[]).forEach(a=>{"imageTag"in a?s.push(a):t.push(a)});let r=o.nextToken??null;t.length===0&&s.length===0||(s.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:s}),t.length!==0&&await i.batchDeleteImage({repositoryName:e.repositoryName,imageIds:t}),r&&await E({...e,nextToken:r}))}async function U(e){if(!e)throw new Error("No RepositoryName was provided.");let t=(await i.describeRepositories({repositoryNames:[e]})).repositories?.find(s=>s.repositoryName===e);if(!await _(t?.repositoryArn)){process.stdout.write(`Repository does not have '${g}' tag, skipping cleaning. +`);return}try{await E({repositoryName:e})}catch(s){if(s.name!=="RepositoryNotFoundException")throw s}}async function _(e){return(await i.listTagsForResource({resourceArn:e})).tags?.some(t=>t.Key===g&&t.Value==="true")}0&&(module.exports={autoDeleteHandler,handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json new file mode 100644 index 0000000000000..ae9d8d30b71c2 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.assets.json @@ -0,0 +1,32 @@ +{ + "version": "36.0.0", + "files": { + "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160": { + "source": { + "path": "asset.3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160", + "packaging": "zip" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46": { + "source": { + "path": "aws-ecr-integ-stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json new file mode 100644 index 0000000000000..ea03b3bb73383 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/aws-ecr-integ-stack.template.json @@ -0,0 +1,359 @@ +{ + "Resources": { + "Repo02AC86CF": { + "Type": "AWS::ECR::Repository", + "Properties": { + "RepositoryName": "delete-even-if-containing-images", + "Tags": [ + { + "Key": "aws-cdk:auto-delete-images", + "Value": "true" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "RepoAutoDeleteImagesCustomResource65201E29": { + "Type": "Custom::ECRAutoDeleteImages", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030", + "Arn" + ] + }, + "RepositoryName": { + "Ref": "Repo02AC86CF" + } + }, + "DependsOn": [ + "Repo02AC86CF" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ecr:BatchDeleteImage", + "ecr:DescribeRepositories", + "ecr:ListImages", + "ecr:ListTagsForResource" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":repository/*" + ] + ] + } + ], + "Condition": { + "StringEquals": { + "ecr:ResourceTag/aws-cdk:auto-delete-images": "true" + } + } + } + ] + } + } + ] + } + }, + "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "S3Key": "3bbaa4a6ad9dab22284496cb250a9e77fb2f26bc181f35610877275058a4f160.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773", + "Arn" + ] + }, + "Runtime": { + "Fn::FindInMap": [ + "LatestNodeRuntimeMap", + { + "Ref": "AWS::Region" + }, + "value" + ] + }, + "Description": { + "Fn::Join": [ + "", + [ + "Lambda function for auto-deleting images in ", + { + "Ref": "Repo02AC86CF" + }, + " repository." + ] + ] + } + }, + "DependsOn": [ + "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + ] + } + }, + "Mappings": { + "LatestNodeRuntimeMap": { + "af-south-1": { + "value": "nodejs20.x" + }, + "ap-east-1": { + "value": "nodejs20.x" + }, + "ap-northeast-1": { + "value": "nodejs20.x" + }, + "ap-northeast-2": { + "value": "nodejs20.x" + }, + "ap-northeast-3": { + "value": "nodejs20.x" + }, + "ap-south-1": { + "value": "nodejs20.x" + }, + "ap-south-2": { + "value": "nodejs20.x" + }, + "ap-southeast-1": { + "value": "nodejs20.x" + }, + "ap-southeast-2": { + "value": "nodejs20.x" + }, + "ap-southeast-3": { + "value": "nodejs20.x" + }, + "ap-southeast-4": { + "value": "nodejs20.x" + }, + "ap-southeast-5": { + "value": "nodejs20.x" + }, + "ap-southeast-7": { + "value": "nodejs20.x" + }, + "ca-central-1": { + "value": "nodejs20.x" + }, + "ca-west-1": { + "value": "nodejs20.x" + }, + "cn-north-1": { + "value": "nodejs20.x" + }, + "cn-northwest-1": { + "value": "nodejs20.x" + }, + "eu-central-1": { + "value": "nodejs20.x" + }, + "eu-central-2": { + "value": "nodejs20.x" + }, + "eu-isoe-west-1": { + "value": "nodejs18.x" + }, + "eu-north-1": { + "value": "nodejs20.x" + }, + "eu-south-1": { + "value": "nodejs20.x" + }, + "eu-south-2": { + "value": "nodejs20.x" + }, + "eu-west-1": { + "value": "nodejs20.x" + }, + "eu-west-2": { + "value": "nodejs20.x" + }, + "eu-west-3": { + "value": "nodejs20.x" + }, + "il-central-1": { + "value": "nodejs20.x" + }, + "me-central-1": { + "value": "nodejs20.x" + }, + "me-south-1": { + "value": "nodejs20.x" + }, + "mx-central-1": { + "value": "nodejs20.x" + }, + "sa-east-1": { + "value": "nodejs20.x" + }, + "us-east-1": { + "value": "nodejs20.x" + }, + "us-east-2": { + "value": "nodejs20.x" + }, + "us-gov-east-1": { + "value": "nodejs20.x" + }, + "us-gov-west-1": { + "value": "nodejs20.x" + }, + "us-iso-east-1": { + "value": "nodejs18.x" + }, + "us-iso-west-1": { + "value": "nodejs18.x" + }, + "us-isob-east-1": { + "value": "nodejs18.x" + }, + "us-west-1": { + "value": "nodejs20.x" + }, + "us-west-2": { + "value": "nodejs20.x" + } + } + }, + "Outputs": { + "RepositoryURI": { + "Value": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 4, + { + "Fn::Split": [ + ":", + { + "Fn::GetAtt": [ + "Repo02AC86CF", + "Arn" + ] + } + ] + } + ] + }, + ".dkr.ecr.", + { + "Fn::Select": [ + 3, + { + "Fn::Split": [ + ":", + { + "Fn::GetAtt": [ + "Repo02AC86CF", + "Arn" + ] + } + ] + } + ] + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "Repo02AC86CF" + } + ] + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json new file mode 100644 index 0000000000000..b0b910be05e51 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json new file mode 100644 index 0000000000000..95645734bb0da --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "36.0.0", + "testCases": { + "cdk-integ-auto-delete-images/DefaultTest": { + "stacks": [ + "aws-ecr-integ-stack" + ], + "diffAssets": true, + "assertionStack": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", + "assertionStackName": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json new file mode 100644 index 0000000000000..b80619df53977 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/manifest.json @@ -0,0 +1,143 @@ +{ + "version": "36.0.0", + "artifacts": { + "aws-ecr-integ-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-ecr-integ-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-ecr-integ-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-ecr-integ-stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d1e9fd700ef2d0c24c2e7a8e6e4ccdbbac0688375b6a419c2b58648e2dab3f46.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-ecr-integ-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-ecr-integ-stack.assets" + ], + "metadata": { + "/aws-ecr-integ-stack/Repo/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Repo02AC86CF" + } + ], + "/aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "RepoAutoDeleteImagesCustomResource65201E29" + } + ], + "/aws-ecr-integ-stack/LatestNodeRuntimeMap": [ + { + "type": "aws:cdk:logicalId", + "data": "LatestNodeRuntimeMap" + } + ], + "/aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773" + } + ], + "/aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomECRAutoDeleteImagesCustomResourceProviderHandler8D89C030" + } + ], + "/aws-ecr-integ-stack/RepositoryURI": [ + { + "type": "aws:cdk:logicalId", + "data": "RepositoryURI" + } + ], + "/aws-ecr-integ-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-ecr-integ-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-ecr-integ-stack" + }, + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "cdkintegautodeleteimagesDefaultTestDeployAssert6B08011C.assets" + ], + "metadata": { + "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json new file mode 100644 index 0000000000000..784e2913b4a39 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-auto-delete-images.js.snapshot/tree.json @@ -0,0 +1,199 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-ecr-integ-stack": { + "id": "aws-ecr-integ-stack", + "path": "aws-ecr-integ-stack", + "children": { + "Repo": { + "id": "Repo", + "path": "aws-ecr-integ-stack/Repo", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecr-integ-stack/Repo/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECR::Repository", + "aws:cdk:cloudformation:props": { + "repositoryName": "delete-even-if-containing-images", + "tags": [ + { + "key": "aws-cdk:auto-delete-images", + "value": "true" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecr.CfnRepository", + "version": "0.0.0" + } + }, + "AutoDeleteImagesCustomResource": { + "id": "AutoDeleteImagesCustomResource", + "path": "aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "aws-ecr-integ-stack/Repo/AutoDeleteImagesCustomResource/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecr.Repository", + "version": "0.0.0" + } + }, + "LatestNodeRuntimeMap": { + "id": "LatestNodeRuntimeMap", + "path": "aws-ecr-integ-stack/LatestNodeRuntimeMap", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnMapping", + "version": "0.0.0" + } + }, + "Custom::ECRAutoDeleteImagesCustomResourceProvider": { + "id": "Custom::ECRAutoDeleteImagesCustomResourceProvider", + "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "Role": { + "id": "Role", + "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Role", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Handler": { + "id": "Handler", + "path": "aws-ecr-integ-stack/Custom::ECRAutoDeleteImagesCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResourceProviderBase", + "version": "0.0.0" + } + }, + "RepositoryURI": { + "id": "RepositoryURI", + "path": "aws-ecr-integ-stack/RepositoryURI", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-ecr-integ-stack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-ecr-integ-stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "cdk-integ-auto-delete-images": { + "id": "cdk-integ-auto-delete-images", + "path": "cdk-integ-auto-delete-images", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "cdk-integ-auto-delete-images/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "cdk-integ-auto-delete-images/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-auto-delete-images/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file From 97edbbbae20c9f1951c0c37f20ed1cb489067ae4 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sun, 2 Mar 2025 20:03:46 +0900 Subject: [PATCH 07/17] update jsdoc --- packages/aws-cdk-lib/aws-ecr/lib/repository.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 2b84cb3376a4d..9aca37fb99b63 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -608,10 +608,14 @@ export interface RepositoryProps { export interface RepositoryLookupOptions { /** * The name of the repository. + * + * @default - Do not filter on repository name */ readonly repositoryName?: string; /** * The ARN of the repository. + * + * @default - Do not filter on repository ARN */ readonly repositoryArn?: string; } From 1aae54992f5844142950a0b73e86db719154f4a9 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Mon, 3 Mar 2025 22:16:20 +0900 Subject: [PATCH 08/17] add unit test --- .../aws-cdk-lib/aws-ecr/lib/repository.ts | 9 +- .../aws-ecr/test/repository.test.ts | 103 ++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 9aca37fb99b63..348deba725b47 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -641,11 +641,18 @@ export class Repository extends RepositoryBase { throw new Error('At least one of `repositoryName` or `repositoryArn` must be provided.'); } + const identifier = options.repositoryName ?? + (options.repositoryArn ? Arn.split(options.repositoryArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName : undefined); + + if (!identifier) { + throw new Error('Could not determine repository identifier from provided options.'); + } + const response: {[key: string]: any}[] = ContextProvider.getValue(scope, { provider: cxschema.ContextProvider.CC_API_PROVIDER, props: { typeName: 'AWS::ECR::Repository', - exactIdentifier: options.repositoryName, + exactIdentifier: identifier, propertiesToReturn: ['Arn'], } as cxschema.CcApiContextQuery, dummyValue: [ diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 766a6d86bb6a4..9e76f6ae887d6 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -3,11 +3,114 @@ import { Annotations, Template } from '../../assertions'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as cdk from '../../core'; +import * as cxschema from '../../cloud-assembly-schema'; import * as ecr from '../lib'; +import { ContextProvider } from '../../core'; /* eslint-disable quote-props */ describe('repository', () => { + describe('lookup', () => { + test('return correct repository info by name', () => { + // GIVEN + const resultObjs = [ + { + 'Arn': 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo', + }, + ]; + const value = { + value: resultObjs, + }; + const mock = jest.spyOn(ContextProvider, 'getValue').mockReturnValue(value); + + // WHEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + const repo = ecr.Repository.fromLookup(stack, 'MyRepo', { + repositoryName: 'my-repo', + }); + + // THEN + expect(repo.repositoryName).toEqual('my-repo'); + expect(repo.repositoryArn).toEqual(ecr.Repository.arnForLocalRepository('my-repo', stack)); + expect(mock).toHaveBeenCalledWith(stack, { + provider: cxschema.ContextProvider.CC_API_PROVIDER, + props: { + typeName: 'AWS::ECR::Repository', + exactIdentifier: 'my-repo', + propertiesToReturn: [ + 'Arn', + ], + } as cxschema.CcApiContextQuery, + dummyValue: [ + { + 'Arn': ecr.Repository.arnForLocalRepository('DUMMY_ARN', stack), + }, + ], + }); + + mock.mockRestore(); + }); + + test('return correct repository info by arn', () => { + const repoArn = 'arn:aws:ecr::123456789012:repository/my-repo'; + // GIVEN + const resultObjs = [ + { + 'Arn': repoArn, + }, + ]; + const value = { + value: resultObjs, + }; + const mock = jest.spyOn(ContextProvider, 'getValue').mockReturnValue(value); + + // WHEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + const repo = ecr.Repository.fromLookup(stack, 'MyRepo', { + repositoryArn: repoArn, + }); + + // THEN + expect(repo.repositoryName).toEqual('my-repo'); + expect(repo.repositoryArn).toEqual(ecr.Repository.arnForLocalRepository('my-repo', stack)); + expect(mock).toHaveBeenCalledWith(stack, { + provider: cxschema.ContextProvider.CC_API_PROVIDER, + props: { + typeName: 'AWS::ECR::Repository', + exactIdentifier: 'my-repo', + propertiesToReturn: [ + 'Arn', + ], + } as cxschema.CcApiContextQuery, + dummyValue: [ + { + 'Arn': ecr.Repository.arnForLocalRepository('DUMMY_ARN', stack), + }, + ], + }); + + mock.mockRestore(); + }); + + test('throw error if repository name is a token', () => { + // GIVEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + const tokenName = new cdk.CfnParameter(stack, 'RepoName'); + expect(() => ecr.Repository.fromLookup(stack, 'MyRepository', { + repositoryName: tokenName.valueAsString, + })).toThrow('Cannot look up a repository with a tokenized name or ARN.'); + }); + + test('throw error if repository arn is a token', () => { + // GIVEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + const tokenName = new cdk.CfnParameter(stack, 'RepoArn'); + expect(() => ecr.Repository.fromLookup(stack, 'MyRepository', { + repositoryArn: tokenName.valueAsString, + })).toThrow('Cannot look up a repository with a tokenized name or ARN.'); + }); + }); + test('construct repository', () => { // GIVEN const stack = new cdk.Stack(); From 1ab4fb8486943ca1f70b736b9c5aa9afa2c50379 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Mon, 3 Mar 2025 22:22:36 +0900 Subject: [PATCH 09/17] update readme --- packages/aws-cdk-lib/aws-ecr/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecr/README.md b/packages/aws-cdk-lib/aws-ecr/README.md index d0ff9fc16cc35..44cacb2f5f3eb 100644 --- a/packages/aws-cdk-lib/aws-ecr/README.md +++ b/packages/aws-cdk-lib/aws-ecr/README.md @@ -209,6 +209,28 @@ repository.addToResourcePolicy(new iam.PolicyStatement({ })); ``` +## import existing repository + +You can import an existing repository into your CDK app using the `Repository.fromRepositoryArn`, `Repository.fromRepositoryName` or `Repository.fromLookup` method. +These methods take the ARN or the name of the repository and returns an `IRepository` object. + +```ts +declare const scope: cdk.Construct; + +// import using repository name +const repositoryFromName = ecr.Repository.fromRepositoryName(scope, 'ImportedRepoByName', 'my-repo-name'); + +// import using repository ARN +const repositoryFromArn = ecr.Repository.fromRepositoryArn(scope, 'ImportedRepoByArn', 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo-name'); + +// import using repository lookup +// You have to provide either `repositoryArn` or `repositoryName` to lookup the repository +const repositoryFromLookup = ecr.Repository.fromLookup(scope, 'ImportedRepoByLookup', { + repositoryArn: 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo-name', + repositoryName: 'my-repo-name', +}); +``` + ## CloudWatch event rules You can publish repository events to a CloudWatch event rule with `onEvent`: From 473f690b5e3db340070dc66abe32338addf2bc5c Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Mon, 3 Mar 2025 22:28:05 +0900 Subject: [PATCH 10/17] fix import order --- packages/aws-cdk-lib/aws-ecr/test/repository.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 9e76f6ae887d6..79c484341a1a4 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -2,11 +2,9 @@ import { EOL } from 'os'; import { Annotations, Template } from '../../assertions'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; -import * as cdk from '../../core'; import * as cxschema from '../../cloud-assembly-schema'; +import * as cdk from '../../core'; import * as ecr from '../lib'; -import { ContextProvider } from '../../core'; - /* eslint-disable quote-props */ describe('repository', () => { @@ -21,7 +19,7 @@ describe('repository', () => { const value = { value: resultObjs, }; - const mock = jest.spyOn(ContextProvider, 'getValue').mockReturnValue(value); + const mock = jest.spyOn(cdk.ContextProvider, 'getValue').mockReturnValue(value); // WHEN const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); @@ -62,7 +60,7 @@ describe('repository', () => { const value = { value: resultObjs, }; - const mock = jest.spyOn(ContextProvider, 'getValue').mockReturnValue(value); + const mock = jest.spyOn(cdk.ContextProvider, 'getValue').mockReturnValue(value); // WHEN const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); From e7d5229f591bd17cc3823fb5d098c74d2e5e6090 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Mon, 3 Mar 2025 22:31:46 +0900 Subject: [PATCH 11/17] test: add unit test --- packages/aws-cdk-lib/aws-ecr/test/repository.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 79c484341a1a4..98b78be7a4f8c 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -107,6 +107,12 @@ describe('repository', () => { repositoryArn: tokenName.valueAsString, })).toThrow('Cannot look up a repository with a tokenized name or ARN.'); }); + + test('throw error if neither repository name nor arn is provided', () => { + // GIVEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + expect(() => ecr.Repository.fromLookup(stack, 'MyRepository', {})).toThrow('At least one of `repositoryName` or `repositoryArn` must be provided.'); + }); }); test('construct repository', () => { From 6ef18676ac1ae4e901a399cdcbe193093089ea04 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Tue, 4 Mar 2025 21:56:55 +0900 Subject: [PATCH 12/17] fix readme --- packages/aws-cdk-lib/aws-ecr/README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecr/README.md b/packages/aws-cdk-lib/aws-ecr/README.md index 44cacb2f5f3eb..dcbbedf879b17 100644 --- a/packages/aws-cdk-lib/aws-ecr/README.md +++ b/packages/aws-cdk-lib/aws-ecr/README.md @@ -215,17 +215,15 @@ You can import an existing repository into your CDK app using the `Repository.fr These methods take the ARN or the name of the repository and returns an `IRepository` object. ```ts -declare const scope: cdk.Construct; - // import using repository name -const repositoryFromName = ecr.Repository.fromRepositoryName(scope, 'ImportedRepoByName', 'my-repo-name'); +const repositoryFromName = ecr.Repository.fromRepositoryName(this, 'ImportedRepoByName', 'my-repo-name'); // import using repository ARN -const repositoryFromArn = ecr.Repository.fromRepositoryArn(scope, 'ImportedRepoByArn', 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo-name'); +const repositoryFromArn = ecr.Repository.fromRepositoryArn(this, 'ImportedRepoByArn', 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo-name'); // import using repository lookup // You have to provide either `repositoryArn` or `repositoryName` to lookup the repository -const repositoryFromLookup = ecr.Repository.fromLookup(scope, 'ImportedRepoByLookup', { +const repositoryFromLookup = ecr.Repository.fromLookup(this, 'ImportedRepoByLookup', { repositoryArn: 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo-name', repositoryName: 'my-repo-name', }); From 86f77779c61e2c10abc139df024cac392da16d6c Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Wed, 12 Mar 2025 21:03:58 +0900 Subject: [PATCH 13/17] add unit test --- .../aws-cdk-lib/aws-ecr/test/repository.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 98b78be7a4f8c..30f12ca6deb61 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -90,6 +90,23 @@ describe('repository', () => { mock.mockRestore(); }); + test.each([ + { + repositoryArn: 'arn:aws:ecr::123456789012:repository/does-not-exist-repo', + }, + { + repositoryName: 'does-not-exist-repo', + }, + ])('return dummy repository info if not found', (config) => { + // WHEN + const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); + const repo = ecr.Repository.fromLookup(stack, 'MyRepo', config); + + // THEN + expect(repo.repositoryName).toEqual('DUMMY_ARN'); + expect(repo.repositoryArn).toEqual(ecr.Repository.arnForLocalRepository('DUMMY_ARN', stack)); + }); + test('throw error if repository name is a token', () => { // GIVEN const stack = new cdk.Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } }); From c7b3a01e41fa4051cf73f5e277939ba8f8a0dd4f Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sun, 23 Mar 2025 00:16:40 +0900 Subject: [PATCH 14/17] use typed errors --- packages/aws-cdk-lib/aws-ecr/lib/repository.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 31158d9ce6515..59ff401558da6 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -636,18 +636,18 @@ export class Repository extends RepositoryBase { */ public static fromLookup(scope: Construct, id: string, options: RepositoryLookupOptions): IRepository { if (Token.isUnresolved(options.repositoryName) || Token.isUnresolved(options.repositoryArn)) { - throw new Error('Cannot look up a repository with a tokenized name or ARN.'); + throw new UnscopedValidationError('Cannot look up a repository with a tokenized name or ARN.'); } if (!options.repositoryArn && !options.repositoryName) { - throw new Error('At least one of `repositoryName` or `repositoryArn` must be provided.'); + throw new UnscopedValidationError('At least one of `repositoryName` or `repositoryArn` must be provided.'); } const identifier = options.repositoryName ?? (options.repositoryArn ? Arn.split(options.repositoryArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName : undefined); if (!identifier) { - throw new Error('Could not determine repository identifier from provided options.'); + throw new UnscopedValidationError('Could not determine repository identifier from provided options.'); } const response: {[key: string]: any}[] = ContextProvider.getValue(scope, { @@ -674,7 +674,7 @@ export class Repository extends RepositoryBase { const lookupRepoName = Arn.split(repository.Arn, ArnFormat.SLASH_RESOURCE_NAME).resourceName; if (!lookupRepoName) { - throw new Error(`Unable to look up repository with name: ${options.repositoryArn} in account ${Aws.ACCOUNT_ID}`); + throw new UnscopedValidationError(`Unable to look up repository with name: ${options.repositoryArn} in account ${Aws.ACCOUNT_ID}`); } return this.fromRepositoryName(scope, id, lookupRepoName); From 3880a8e561c0e1189e18255af875026280f6a287 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Wed, 26 Mar 2025 23:34:37 +0900 Subject: [PATCH 15/17] use fromAttributes --- .../EcrRepoLookupStack.assets.json | 4 +- .../EcrRepoLookupStack.template.json | 4 +- .../manifest.json | 4 +- .../tree.json | 281 +----------------- .../aws-cdk-lib/aws-ecr/lib/repository.ts | 5 +- .../aws-ecr/test/repository.test.ts | 18 +- 6 files changed, 25 insertions(+), 291 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json index 6a2cd9f16e379..47f968ddcf5c6 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.assets.json @@ -1,7 +1,7 @@ { "version": "40.0.0", "files": { - "4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b": { + "694b1f59a97a2cabd43348095c6983d394ce506020298a3a62f3067ae6ce7e18": { "source": { "path": "EcrRepoLookupStack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "12345678-test-region": { "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b.json", + "objectKey": "694b1f59a97a2cabd43348095c6983d394ce506020298a3a62f3067ae6ce7e18.json", "region": "test-region", "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json index b247c7d6df6ae..b65cf5070c986 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/EcrRepoLookupStack.template.json @@ -50,7 +50,7 @@ { "Ref": "AWS::Partition" }, - ":ecr:test-region:12345678:repository/DUMMY_ARN" + ":ecr:us-east-1:123456789012:repository/DUMMY_ARN" ] ] } @@ -93,7 +93,7 @@ "Fn::Join": [ "", [ - "12345678.dkr.ecr.test-region.", + "123456789012.dkr.ecr.us-east-1.", { "Ref": "AWS::URLSuffix" }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json index e6b5ccfef515e..b81823774aa1a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/4a11e4e3b3e92167c4c041810158f5c28c8e3b16c12750fcb9e25dc0d8c8113b.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/694b1f59a97a2cabd43348095c6983d394ce506020298a3a62f3067ae6ce7e18.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -183,7 +183,7 @@ "props": { "dummyValue": [ { - "Arn": "arn:${Token[AWS.Partition.6]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" + "Arn": "arn:${Token[AWS.Partition.3]}:ecr:us-east-1:123456789012:repository/DUMMY_ARN" } ], "account": "12345678", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json index f95bb08eec1fe..721995796f38d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.repository-lookup.js.snapshot/tree.json @@ -1,280 +1 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "EcrRepoLookupStack": { - "id": "EcrRepoLookupStack", - "path": "EcrRepoLookupStack", - "children": { - "LookupRepo": { - "id": "LookupRepo", - "path": "EcrRepoLookupStack/LookupRepo", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [] - } - }, - "Lambda": { - "id": "Lambda", - "path": "EcrRepoLookupStack/Lambda", - "children": { - "ServiceRole": { - "id": "ServiceRole", - "path": "EcrRepoLookupStack/Lambda/ServiceRole", - "children": { - "ImportServiceRole": { - "id": "ImportServiceRole", - "path": "EcrRepoLookupStack/Lambda/ServiceRole/ImportServiceRole", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - }, - "Resource": { - "id": "Resource", - "path": "EcrRepoLookupStack/Lambda/ServiceRole/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::IAM::Role", - "aws:cdk:cloudformation:props": { - "assumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - }, - "managedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - ] - } - ] - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "DefaultPolicy": { - "id": "DefaultPolicy", - "path": "EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy", - "children": { - "Resource": { - "id": "Resource", - "path": "EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::IAM::Policy", - "aws:cdk:cloudformation:props": { - "policyDocument": { - "Statement": [ - { - "Action": [ - "ecr:DescribeImages", - "ecr:DescribeRepositories" - ], - "Effect": "Allow", - "Resource": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:test-region:12345678:repository/DUMMY_ARN" - ] - ] - } - } - ], - "Version": "2012-10-17" - }, - "policyName": "LambdaServiceRoleDefaultPolicyDAE46E21", - "roles": [ - { - "Ref": "LambdaServiceRoleA8ED4D3B" - } - ] - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*", - "*", - "*", - "*" - ] - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*", - "*", - "*", - "*" - ] - } - }, - "Resource": { - "id": "Resource", - "path": "EcrRepoLookupStack/Lambda/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::Lambda::Function", - "aws:cdk:cloudformation:props": { - "code": { - "zipFile": "exports.handler = async function(event, context) { return \"Hello, World!\"; }" - }, - "handler": "index.handler", - "role": { - "Fn::GetAtt": [ - "LambdaServiceRoleA8ED4D3B", - "Arn" - ] - }, - "runtime": "nodejs20.x" - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2", - "metadata": [ - "*" - ] - } - }, - "RepositoryUri": { - "id": "RepositoryUri", - "path": "EcrRepoLookupStack/RepositoryUri", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "EcrRepoLookupStack/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "EcrRepoLookupStack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "EcrRepoLookupTest": { - "id": "EcrRepoLookupTest", - "path": "EcrRepoLookupTest", - "children": { - "DefaultTest": { - "id": "DefaultTest", - "path": "EcrRepoLookupTest/DefaultTest", - "children": { - "Default": { - "id": "Default", - "path": "EcrRepoLookupTest/DefaultTest/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "DeployAssert": { - "id": "DeployAssert", - "path": "EcrRepoLookupTest/DefaultTest/DeployAssert", - "children": { - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "EcrRepoLookupTest/DefaultTest/DeployAssert/BootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "EcrRepoLookupTest/DefaultTest/DeployAssert/CheckBootstrapVersion", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", - "version": "0.0.0" - } - }, - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } - }, - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.4.2" - } - } -} \ No newline at end of file +{"version":"tree-0.1","tree":{"id":"App","path":"","children":{"EcrRepoLookupStack":{"id":"EcrRepoLookupStack","path":"EcrRepoLookupStack","children":{"LookupRepo":{"id":"LookupRepo","path":"EcrRepoLookupStack/LookupRepo","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":[]}},"Lambda":{"id":"Lambda","path":"EcrRepoLookupStack/Lambda","children":{"ServiceRole":{"id":"ServiceRole","path":"EcrRepoLookupStack/Lambda/ServiceRole","children":{"ImportServiceRole":{"id":"ImportServiceRole","path":"EcrRepoLookupStack/Lambda/ServiceRole/ImportServiceRole","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*"]}},"Resource":{"id":"Resource","path":"EcrRepoLookupStack/Lambda/ServiceRole/Resource","attributes":{"aws:cdk:cloudformation:type":"AWS::IAM::Role","aws:cdk:cloudformation:props":{"assumeRolePolicyDocument":{"Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"}}],"Version":"2012-10-17"},"managedPolicyArns":[{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"]]}]}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"DefaultPolicy":{"id":"DefaultPolicy","path":"EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy","children":{"Resource":{"id":"Resource","path":"EcrRepoLookupStack/Lambda/ServiceRole/DefaultPolicy/Resource","attributes":{"aws:cdk:cloudformation:type":"AWS::IAM::Policy","aws:cdk:cloudformation:props":{"policyDocument":{"Statement":[{"Action":["ecr:DescribeImages","ecr:DescribeRepositories"],"Effect":"Allow","Resource":{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":ecr:us-east-1:123456789012:repository/DUMMY_ARN"]]}}],"Version":"2012-10-17"},"policyName":"LambdaServiceRoleDefaultPolicyDAE46E21","roles":[{"Ref":"LambdaServiceRoleA8ED4D3B"}]}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*","*","*","*"]}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*","*","*","*"]}},"Resource":{"id":"Resource","path":"EcrRepoLookupStack/Lambda/Resource","attributes":{"aws:cdk:cloudformation:type":"AWS::Lambda::Function","aws:cdk:cloudformation:props":{"code":{"zipFile":"exports.handler = async function(event, context) { return \"Hello, World!\"; }"},"handler":"index.handler","role":{"Fn::GetAtt":["LambdaServiceRoleA8ED4D3B","Arn"]},"runtime":"nodejs20.x"}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*"]}},"RepositoryUri":{"id":"RepositoryUri","path":"EcrRepoLookupStack/RepositoryUri","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"BootstrapVersion":{"id":"BootstrapVersion","path":"EcrRepoLookupStack/BootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"EcrRepoLookupStack/CheckBootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"EcrRepoLookupTest":{"id":"EcrRepoLookupTest","path":"EcrRepoLookupTest","children":{"DefaultTest":{"id":"DefaultTest","path":"EcrRepoLookupTest/DefaultTest","children":{"Default":{"id":"Default","path":"EcrRepoLookupTest/DefaultTest/Default","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"DeployAssert":{"id":"DeployAssert","path":"EcrRepoLookupTest/DefaultTest/DeployAssert","children":{"BootstrapVersion":{"id":"BootstrapVersion","path":"EcrRepoLookupTest/DefaultTest/DeployAssert/BootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"EcrRepoLookupTest/DefaultTest/DeployAssert/CheckBootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTestCase","version":"0.0.0"}}},"constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTest","version":"0.0.0"}},"Tree":{"id":"Tree","path":"Tree","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}},"constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}} \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 59ff401558da6..b71392e8c245b 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -677,7 +677,10 @@ export class Repository extends RepositoryBase { throw new UnscopedValidationError(`Unable to look up repository with name: ${options.repositoryArn} in account ${Aws.ACCOUNT_ID}`); } - return this.fromRepositoryName(scope, id, lookupRepoName); + return this.fromRepositoryAttributes(scope, id, { + repositoryName: lookupRepoName, + repositoryArn: repository.Arn, + }); } /** diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 30f12ca6deb61..4647b92696121 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -29,7 +29,12 @@ describe('repository', () => { // THEN expect(repo.repositoryName).toEqual('my-repo'); - expect(repo.repositoryArn).toEqual(ecr.Repository.arnForLocalRepository('my-repo', stack)); + expect(repo.repositoryArn).toEqual(cdk.Stack.of(repo).formatArn({ + service: 'ecr', + partition: 'aws', + resource: 'repository', + resourceName: 'my-repo', + })); expect(mock).toHaveBeenCalledWith(stack, { provider: cxschema.ContextProvider.CC_API_PROVIDER, props: { @@ -50,7 +55,7 @@ describe('repository', () => { }); test('return correct repository info by arn', () => { - const repoArn = 'arn:aws:ecr::123456789012:repository/my-repo'; + const repoArn = 'arn:aws:ecr:us-east-1:123456789012:repository/my-repo'; // GIVEN const resultObjs = [ { @@ -70,7 +75,12 @@ describe('repository', () => { // THEN expect(repo.repositoryName).toEqual('my-repo'); - expect(repo.repositoryArn).toEqual(ecr.Repository.arnForLocalRepository('my-repo', stack)); + expect(repo.repositoryArn).toEqual(cdk.Stack.of(repo).formatArn({ + service: 'ecr', + partition: 'aws', + resource: 'repository', + resourceName: 'my-repo', + })); expect(mock).toHaveBeenCalledWith(stack, { provider: cxschema.ContextProvider.CC_API_PROVIDER, props: { @@ -92,7 +102,7 @@ describe('repository', () => { test.each([ { - repositoryArn: 'arn:aws:ecr::123456789012:repository/does-not-exist-repo', + repositoryArn: 'arn:aws:ecr:us-east-1:123456789012:repository/does-not-exist-repo', }, { repositoryName: 'does-not-exist-repo', From c02b0b9554aeaba1919653611db8b1eeeb5a2075 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Thu, 27 Mar 2025 12:58:26 +0900 Subject: [PATCH 16/17] use fromRepositoryArn --- packages/aws-cdk-lib/aws-ecr/lib/repository.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index b71392e8c245b..a3c79db5a1f88 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -671,16 +671,8 @@ export class Repository extends RepositoryBase { }).value; const repository = response[0]; - const lookupRepoName = Arn.split(repository.Arn, ArnFormat.SLASH_RESOURCE_NAME).resourceName; - if (!lookupRepoName) { - throw new UnscopedValidationError(`Unable to look up repository with name: ${options.repositoryArn} in account ${Aws.ACCOUNT_ID}`); - } - - return this.fromRepositoryAttributes(scope, id, { - repositoryName: lookupRepoName, - repositoryArn: repository.Arn, - }); + return this.fromRepositoryArn(scope, id, repository.Arn); } /** From 7a545fb6eac5d49e294f8de729ba566b049e5266 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Thu, 27 Mar 2025 13:01:50 +0900 Subject: [PATCH 17/17] use Arn.extractResourceName --- packages/aws-cdk-lib/aws-ecr/lib/repository.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index a3c79db5a1f88..bdec659547ecc 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -671,8 +671,12 @@ export class Repository extends RepositoryBase { }).value; const repository = response[0]; + const repositoryName = Arn.extractResourceName(repository.Arn, 'repository'); - return this.fromRepositoryArn(scope, id, repository.Arn); + return this.fromRepositoryAttributes(scope, id, { + repositoryName: repositoryName, + repositoryArn: repository.Arn, + }); } /**