Skip to content

Sam Package/Deploy --image-repository Behavior #2447

@metaskills

Description

@metaskills

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions