question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sam Package/Deploy --image-repository Behavior

See original GitHub issue

Many of the process I put in place for both open source and in company deploy pipelines take advantage of SAM CLI and the AWS CLI using conventions like AWS_PROFILE. I’ve been very happy that SAM CLI has followed these patterns. Today when working with the new container features I was surprised by this odd behavior of sam package when using the --image-repository option. Here is an example of my usage where the new image repo was added to my process.

sam package \
  --region ${AWS_DEFAULT_REGION} \
  --template-file ./.aws-sam/build/template.yaml \
  --output-template-file ./.aws-sam/build/packaged.yaml \
  --image-repository  "lambyc-starter" \
  --s3-bucket "${CLOUDFORMATION_BUCKET}" \
  --s3-prefix "lambyc-starter-${RAILS_ENV}"

These commands are run as either the default AWS_PROFILE or with specific ENV overrides. Given this was set and that the --region was set here, my expectation was this command was going to find and publish to the ECR repo within my AWS account. Instead, it tried to push to docker.io and failed with a user password. Digging into some guides and published SAM examples I can see what you expect folks to do is:

sam package \
  --region ${AWS_DEFAULT_REGION} \
  --template-file ./.aws-sam/build/template.yaml \
  --output-template-file ./.aws-sam/build/packaged.yaml \
  --image-repository  "123456789.dkr.ecr.us-east-1.amazonaws.com/lambyc-starter" \
  --s3-bucket "${CLOUDFORMATION_BUCKET}" \
  --s3-prefix "lambyc-starter-${RAILS_ENV}"

This feels like the wrong interface to me and against the grain of how the CLI operates given all my previous experiences. I can work around this if y’all disagree by adding more aws CLI commands to find the account ID and use the AWS_DEFAULT_REGION env and/or look that up as well. But it would cool if SAM did this. Thoughts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

12reactions
solarmosaic-kflorencecommented, Apr 13, 2021

I am confused by --image-repository as well. In some contexts, it seems like it should be optional (for example, when you are using sam deploy with a packaged template that already includes the full ImageUri to a tagged ECR image).

4reactions
PikaChokeMecommented, Jan 12, 2021

I found this issue after trying to make a docker image and being told I need to specify a --image-repository. I was hoping to be able to use something as simple as --resolve-image-repository similar to the --resolve-s3 option, but it seems to be much much more difficult than that.

I tried to make a script which does the following

aws ecr create-repository --repository-name "my-project" || true

AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
AWS_DEFAULT_REGION=us-west-2
IMAGE_REPOSITORY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/my-project"

and then specified --image-repository "$IMAGE_REPOSITORY", which only leaves me lost, confused, and frustrated with the following error

Error: Unable to upload artifact None referenced by ImageUri parameter of CustomLambdaFunction resource.
Image not found for ImageUri parameter of ManageOktaAppsLambdaFunction resource.

All I really have to add is that I agree that all the extra setup/requirements to get this all up and running seems very anti SAM. So far SAM has done an extremely good job at being easy for even a novice with limited AWS cloud formation knowledge like me to figure out. This is the first time I feel like SAM doesn’t just work, and it’s been very frustrating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam package - AWS Serverless Application Model
Packages an AWS SAM application. This command creates a .zip file of your code and dependencies, and uploads the file to Amazon Simple...
Read more >
Using container image support for AWS Lambda with ...
In the install phase, I downloaded and installed the latest sam cli from AWS. Under the pre_build section, we need to get the...
Read more >
aws-sam-cli Changelog
SAM CLI now supports running `sam package` without AWS CLI installed. This release also includes user experience improvements to interactive `sam init` command....
Read more >
origin
This is the source repository for OpenShift Origin - the best way to build, manage, and deploy applications in the cloud.
Read more >
Latest News
Each application includes an AWS SAM template that specifies the AWS ... Container Registry is a container image repository to manage Docker images, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found