aws-sam-cli
aws-sam-cli copied to clipboard
Feature request: Add --resolve-image-repos support for package command
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.
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.
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:
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-env
s 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.
Thanks for the detailed explanation on the use case!
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.
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!
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.
Also following this, can we please have an update?