Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecr): error handling compatible with aws sdk v3 #26608

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "32.0.0",
"version": "33.0.0",
"files": {
"4e1cabe0539da013fb7dfcebb3d2e8a94f6b3b75dc2398a57be5b782f6f4b1a5": {
"20f3de8c0cdbf0de6a3098689c0c2307544d8710c022d6a716fd722dc885052b": {
"source": {
"path": "asset.4e1cabe0539da013fb7dfcebb3d2e8a94f6b3b75dc2398a57be5b782f6f4b1a5",
"path": "asset.20f3de8c0cdbf0de6a3098689c0c2307544d8710c022d6a716fd722dc885052b",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "4e1cabe0539da013fb7dfcebb3d2e8a94f6b3b75dc2398a57be5b782f6f4b1a5.zip",
"objectKey": "20f3de8c0cdbf0de6a3098689c0c2307544d8710c022d6a716fd722dc885052b.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"a7f050a84f8939feff8bafc96fd11fdaab143e12cfa66078e3b5f88eb4be72d3": {
"32b456cdb8ff646c98c4580ff6d88bd51e84e33af74af927bb882158a53a0d21": {
"source": {
"path": "aws-ecr-integ-stack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "a7f050a84f8939feff8bafc96fd11fdaab143e12cfa66078e3b5f88eb4be72d3.json",
"objectKey": "32b456cdb8ff646c98c4580ff6d88bd51e84e33af74af927bb882158a53a0d21.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "4e1cabe0539da013fb7dfcebb3d2e8a94f6b3b75dc2398a57be5b782f6f4b1a5.zip"
"S3Key": "20f3de8c0cdbf0de6a3098689c0c2307544d8710c022d6a716fd722dc885052b.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"32.0.0"}
{"version":"33.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "32.0.0",
"version": "33.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "32.0.0",
"version": "33.0.0",
"testCases": {
"cdk-integ-auto-delete-images/DefaultTest": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "32.0.0",
"version": "33.0.0",
"artifacts": {
"aws-ecr-integ-stack.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -17,7 +17,7 @@
"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}/a7f050a84f8939feff8bafc96fd11fdaab143e12cfa66078e3b5f88eb4be72d3.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/32b456cdb8ff646c98c4580ff6d88bd51e84e33af74af927bb882158a53a0d21.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"path": "cdk-integ-auto-delete-images/DefaultTest/Default",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"version": "10.2.69"
}
},
"DeployAssert": {
Expand Down Expand Up @@ -179,7 +179,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"version": "10.2.69"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { ECR, ImageIdentifier, ListImagesRequest } from '@aws-sdk/client-ecr';
import { ECR, ImageIdentifier, ListImagesRequest, RepositoryNotFoundException } from '@aws-sdk/client-ecr';
import { makeHandler } from '../../nodejs-entrypoint';

const AUTO_DELETE_IMAGES_TAG = 'aws-cdk:auto-delete-images';
Expand Down Expand Up @@ -94,7 +94,7 @@ async function onDelete(repositoryName: string) {
try {
await emptyRepository({ repositoryName });
} catch (e: any) {
if (e.name !== 'RepositoryNotFoundException') {
if (!(e instanceof RepositoryNotFoundException)) {
throw e;
}
// Repository doesn't exist. Ignoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ test('delete event where repo has many images does recurse appropriately', async

test('does nothing when the repository does not exist', async () => {
// GIVEN
mockECRClient.listImages.mockRejectedValue({ name: 'RepositoryNotFoundException' });
mockECRClient.listImages.mockImplementation(async () => {
const { RepositoryNotFoundException } = jest.requireActual('@aws-sdk/client-ecr');
return new RepositoryNotFoundException({ name: '', $metadata: {} });
});

mockECRClient.describeRepositories.mockReturnValue({
repositories: [
Expand Down