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

cdk.lambda.DockerImageFunction: add ability to set image tag as parameter #26987

Open
2 tasks
mdvertola opened this issue Sep 2, 2023 · 1 comment
Open
2 tasks
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@mdvertola
Copy link

Describe the feature

On the lambda DockerImageFunction construct, it would be sweet if there was an ability to set the image tag.
for example:

const createKnowledgeIndexLambda = new lambda.DockerImageFunction(
      this,
      `CreateKnowledgeIndexLambda`,
      {
        code: lambda.DockerImageCode.fromImageAsset(
          "lambda/knowledge/create_knowledge_index"
        ),
        timeout: cdk.Duration.minutes(5),
        imageTag: "latest"
      }
    );

Use Case

When running several docker lambda functions in a stack or set of stacks, the amount of images starts to pile up in ECR because each image gets automatically tagged with a unique id.

Now I am aware that ECR retention policies can be created to automatically clear out old images but since these containers are tagged with unique IDs, it is difficult to create a policy that would, for example: clear out all images without a tag that are greater than 14 days old.

Proposed Solution

Add the ability to set the imageTag as a parameter of the dockerImageFunction construct to something static/developer-defined. During deployment, set the image tag to the parameter defined in the construct.

From my knowledge of ECR, I believe this is how the workflow would play out:

  • CDK deployment creates image with the tag defined in construct (eg latest)
  • if there is an existing image tagged latest, ECR should automatically just untag that image
  • This way we will be left with one image tagged latest and n images without a tag

I think that doing this would enable the ability to set a more straightforward ECR retention policy. Or hey honestly, it might just be easier/ better to just remove the old image if the new one builds successfully so this pile-up of images doesn't happen.

Other Information

Definitely just taking a stab here at something I found a little annoying when working on some projects so I'm not sure if this was abstracted away or done for a reason someone much smarter than myself has a solid design decision around but either way wanted to throw it out there to see if we could get this on the map.

Thanks!

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

latest

Environment details (OS name and version, etc.)

macOS 13.0

@mdvertola mdvertola added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Sep 2, 2023
@pahud
Copy link
Contributor

pahud commented Sep 5, 2023

CDK publishes the container image assets with its hash as the tag and does not allow users to specify a static image tag for the assets AFAIK.

I guess we'll need an external construct to create ECR lifecycle policies to remove unused images or layers.

I am leaving this a p2 feature request. Please help us with upvotes to prioritize.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 5, 2023
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/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants