cdk.lambda.DockerImageFunction: add ability to set image tag as parameter
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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
Contributor guide
Research direction
Start with the lambda.DockerImageFunction construct and DockerImageCode.fromImageAsset entry points, then inspect how the deployment image is tagged in ECR. Done means a developer-defined imageTag can be supplied and the resulting tag and replacement behavior are covered by the relevant implementation tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100