aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.72k stars 3.94k forks source link

[ecr] Lookup function for ECR repositories #8461

Open leandropadua opened 4 years ago

leandropadua commented 4 years ago

Implement fromLookup for aws-ecr in order to query the repository during synth time.

Use Case

Currently when using ECR, if we try to import a repository that doesn't exist using fromRepositoryArn, fromRepositoryAttributes or fromRepositoryName, it doesn't check if the repository actually exist and sometimes we will only find that out through runtime errors when trying to push to that repo.

Using a lookup, we could treat the error during synth and therefore, create a repo if it doesn't exist.

Proposed Solution

suggested method signature:

public static fromLookup(scope: Construct, id: string, options: EcrLookupOptions): IRepository

example of usage:

const myRepo = ecr.Repository.fromLookup(stack, 'MyRepository', {
  repositoryName: ...,
  repositoryArn: ...,
});

Other

Related stackoverflow issue using the CLI https://stackoverflow.com/questions/51028677/create-aws-ecr-repository-if-it-doesnt-exist


This is a :rocket: Feature Request

nohack commented 3 years ago

@MrArnoldPalmer created this pr.please let me know if it looks ok.

kierans commented 3 years ago

Another use case for this is repo replication. If I have an ECR repository in one region, and I want to replicate the images to another region I need to find lookup the source repo in the "main" region.

mrpackethead commented 3 years ago

The scope of this needs to be wider. There needs to be a standardised way of creating contexts for user-created lookups.. The users want to do ECR lookups, but for me, its other things.. You could solve the specific use-case here, but the other approach would be to provide a method to do arbitory lookups ( using sdk calls, which is what the 'built in lookups' do anyway, and cache them.

Kazpers commented 2 years ago

@mrpackethead I agree that would be nice, but I'd settle for solving it on a case-by-case basis over it not being solved at all... This would be a really nice feature but it's still not here after 2½ years.

@nohack Sadly it seems the PR died "on the vine" although it looked like it did exactly what was desired. How can we revive it?