aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Feature request: Add --resolve-image-repos support for package command

Open mluypaert opened this issue 2 years ago • 8 comments

Description

Currently sam deploy supports the --resolve-image-repos argument to automatically create and delete ECR repositories as needed, which works great! However, the sam package command does not seem to support this argument yet, as when I try to run sam package --resolve-s3 --resolve-image-repos it throws me

Usage: sam package [OPTIONS]
Try 'sam package -h' for help.

Error: no such option: --resolve-image-repos

but then when I leave away the --resolve-image-repos argument, it throws me:

Usage: sam package [OPTIONS]
Try 'sam package -h' for help.

Error: Missing option '--image-repository', '--image-repositories', or '--resolve-image-repos'

Proposal

Please add support for the --resolve-image-repos argument to the package command.

mluypaert avatar May 18 '22 18:05 mluypaert

Thanks for the feature request! We have a roadmap here, but we also try to take in popular feature requests based on 👍 from the community. We will be adding this to our intake for prioritization.

torresxb1 avatar May 20 '22 23:05 torresxb1

A common usecase for this (and the reason I'm requesting it) would be to enable the use of AWS-managed ECR repos for serverless applications being built and deployed to multiple environments, through CI/CD tools like github actions.

In github actions, the docker image being built locally in one job through sam build --use-container is not accessible in other, consecutive jobs. As I want to build and upload my container image once, and then deploy it to multiple environments in parallel, I do not want to create the same image multiple times by running sam build in multiple parallel jobs, and I cannot let sam deploy handle the image upload of that same image multiple times in parallel, as that would either result in a multiplied cost for storing multiple copies of the same image, or potential problems caused by multiple concurrent uploads to the same image repositories using the same tag. In order to fix this, I build (sam build) and upload (sam package) the image in one job, store and pass the output-template-file of this job on to the next ones, which then go on to deploy using the packaged template file to multiple environments in parallel. This looks something like this: image

where the build-sam job runs sam build and sam package, and the three deploy-* jobs all run sam deploy with the packaged template file received from the build-sam job (but using different config-envs from the samconfig.toml file). However, the use of the sam package command in this workflow currently prevents me from using an AWS-managed ECR repository, as that requires the --resolve-image-repos to be supported by the aws package command.

mluypaert avatar Jun 10 '22 11:06 mluypaert

Thanks for the detailed explanation on the use case!

qingchm avatar Jul 22 '22 04:07 qingchm

I was slightly inconvenienced by the error message since it suggests that --resolve-image-repos is an option that can be used with sam package. If this feature isn't going to be added in the near future, it might be prudent to at least update the error message to be more consistent with what is actually valid.

john-holden-1 avatar Jul 29 '22 17:07 john-holden-1

Sorry I believe this is a generic error message shared by package and deploy command, therefore causing the confusion here. Adding resolve image repos option for package command is a community welcomed contribution, we will also mark this as a good first issue for team to pick up!

qingchm avatar Dec 19 '22 00:12 qingchm

Following up on this. It would be really convenient to add the --resolve-image-repos option for the sam package command. My CI/CD deployments are blocked because package and deploy actions are separate and sam package does not support this option. If I manually create ecr image repository, then I get into the permissions mess, when I am managing multiple environments and accounts. It would be ideal if sam package automatically creates ecr repositories on the fly as needed with the --resolve-image-repos option.

svadrevu avatar Feb 09 '23 00:02 svadrevu

I am also facing the same issue as mentioned by mluypaert.

Is there any update on this?

DineshPrathap93 avatar Jun 08 '23 19:06 DineshPrathap93

Also following this, can we please have an update?

mirceaadam avatar Jun 15 '23 08:06 mirceaadam