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

feat(ecr): lookup existing repository #33662

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
update readme
  • Loading branch information
badmintoncryer committed Mar 3, 2025
commit 1ab4fb8486943ca1f70b736b9c5aa9afa2c50379
22 changes: 22 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/README.md
Original file line number Diff line number Diff line change
@@ -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`:
Loading
Oops, something went wrong.