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

(aws-lambda): Allow referencing lambda container image by digest #15333

Closed
2 tasks
mrvisser opened this issue Jun 28, 2021 · 5 comments · Fixed by #19799
Closed
2 tasks

(aws-lambda): Allow referencing lambda container image by digest #15333

mrvisser opened this issue Jun 28, 2021 · 5 comments · Fixed by #19799
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@mrvisser
Copy link

At the moment it appears DockerImageCode.fromEcr type can only accept a tag as a reference to a container version. I think it would be helpful to also be able to reference a digest instead of a tag.

Use Case

Deploying a Lambda on a moving tag requires intervention outside the CDK to force the lambda to update its digest. In my workflow, I deploy a new container to latest, and get a digest from that update. I would like to just specify that digest in my lambda container to then force it to update to the latest version.

Proposed Solution

Taking into consideration how this issue was resolved: #5082 . Maybe we should have the ability to create a DockerImageCode instance from the full Repository URI, so we can say repository.repositoryUriForDigest in addition to repository.repositoryUriForTag.

Another option is to add a digest property in the options for DockerImageCode.fromEcr, however then that opens an invalid state, where you can specify both a tag and digest.

One other thought, in line with this comment: #5082 (comment), is to overload the tag property for digest, and check if it starts with sha256:.

Other

Resource handler returned message: "Source image 393233896464.dkr.ecr.us-east-2.amazonaws.com/my-image:@sha256:783e6c546ca12437893a8651759f93a642a55d368a238f04bf625859c3bdb25a is not valid. Provide a valid source image. (Service: Lambda, Status
Code: 400, Request ID: 2982d3fc-3741-4a5c-ae6b-e3d7f3b6b076, Extended Request ID: null)" (RequestToken: 3c72609b-e1fa-e34c-f15e-02134f8405d4, HandlerErrorCode: InvalidRequest)
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@mrvisser mrvisser added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 28, 2021
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jun 28, 2021
@nija-at
Copy link
Contributor

nija-at commented Jul 28, 2021

Thanks for filing this issue.

The EcrImageCode will need to be updated to use repositoryUriForDigest() here -

imageUri: this.repository.repositoryUriForTag(this.props?.tag ?? 'latest'),

and EcrImageCodeProps will need to be updated to accept a digest. property.

Marking as a feature request.

@nija-at nija-at added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2 and removed needs-triage This issue or PR still needs to be triaged. good first issue Related to contributions. See CONTRIBUTING.md labels Jul 28, 2021
@nija-at nija-at removed their assignment Jul 28, 2021
@mrvisser
Copy link
Author

For the specific use-case, you can also do this after you've deployed an updated image to ECR, and it forces the lambda to update its image reference to the latest digest:

aws lambda update-function-code \
  --function-name <function name> \
  --image-uri "$ECR_URL/my-image:prod"

In this scenario there are no stack updates to to the lambda container's digest necessary.

@adrian-baker
Copy link

A hacky-feeling workaround for this (using the Java SDK) is to concat the digest manually to the repository, and pass a blank tag (null doesn't work because it results in :latest being added).

DockerImageCode.fromEcr(Repository.fromRepositoryArn(this, "unused",
        "arn:aws:ecr:ap-southeast-2:11111111:repository/my-repo@sha256:570f120..."),
    EcrImageCodeProps.builder().tag("").build());

@huonw
Copy link
Contributor

huonw commented Apr 7, 2022

In #19799, I generalised the change from #13299 (fixes #5082) and used it in most places, including lambda.

@mergify mergify bot closed this as completed in #19799 Apr 13, 2022
mergify bot pushed a commit that referenced this issue Apr 13, 2022
…rywhere (#19799)

This generalises the fix of #13299 by creating a `IRepository.repositoryUriForTagOrDigest` function that detects whether something looks like a digest (starts with `sha256:`) or is a tag, and formats the URI with `@` or `:` as appropriate. This function is then used in most places that previously called `repositoryUriForTag`, meaning they can use image digests in addition to tags. The one remain real call is in aws-ecs's `TagParameterContainerImage`.

This includes aws-lambda's `EcrImageCode`, and thus closes #15333.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
…rywhere (aws#19799)

This generalises the fix of aws#13299 by creating a `IRepository.repositoryUriForTagOrDigest` function that detects whether something looks like a digest (starts with `sha256:`) or is a tag, and formats the URI with `@` or `:` as appropriate. This function is then used in most places that previously called `repositoryUriForTag`, meaning they can use image digests in addition to tags. The one remain real call is in aws-ecs's `TagParameterContainerImage`.

This includes aws-lambda's `EcrImageCode`, and thus closes aws#15333.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants