Package Type: Image not writing cloud formation template to S3 Bucket? Should it? If not, why not?
Description:
For some reason the sam cli, package type = Image, does not write the modified template file (that contains the actual docker image name) to the S3 bucket. Although the code is no longer needed to be placed S3 bucket as it's a docker image uploaded to the ECR, I assumed the output template would still be needed in the S3 bucket.
Please advise on if I have misguided expectations.
Steps to reproduce:
- Create a lambda function with package type Image (e.g.
sam init --no-interactive --package-type Image --base-image amazon/nodejs14.x-base --dependency-manager npm --name test-service) - Run sam package command with S3 bucket specified.
Observed result:
Image published to ECR - Expected Nothing published to S3 bucket - Not as expected.
If I run a similar thing with the cloud formation API, the template is uploaded to S3 bucket and the image to ECR.
Expected result:
Similar behavior as cloud formation API. The s3 bucket will have the modified template with correct ImageUrl and ECR will have the image. This is what cloudformation API does.
aws cloudformation package --template-file template.yaml --s3-bucket $AWS_S3_BUCKET --s3-prefix $AWS_S3_PREFIX --output-template-file package.yaml
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOS Big Sur
sam --version: 1.36.0- AWS region: us-west-2
Add --debug flag to command you are running
Hi!
Thanks for asking this question. The expectation is that it will not publish to S3 bucket for images.
Please check the following doc:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html
When you specify this flag, the sam deploy command zips your application artifacts, uploads them either to Amazon Simple Storage Service (Amazon S3) (for .zip file archives) or to Amazon Elastic Container Registry (Amazon ECR) (for contain images).
Is there a reason that you'd like to have images published to S3 buckets?
Hi, thank you for your reply.
I probably didn't ask the question clearly. I wasn't expecting the image to be posted to the s3 bucket, I understand that is handled by ECR. I was wondering about the cloud formation template file that is generated to be put in the s3 bucket.
I may be misunderstanding a usage pattern.
I am under the impression that it is still valid to want to package first and deploy later vs just sam deploy. In that case, the template files would be kept somewhere to be pulled in by a separate deployment step.
And what would be the use case for a template file store in S3 bucket when you have a ready-to-use image in ECR?
Thanks for the reply. I was trying to understand how to work use sam package and sam deploy in a multi-stage process where we keep the artifacts for deployment in the future. My initial thought was that the output of the sam package would be to store the template generate in the S3 bucket. I could be mistaken on this use case.
Since posting, I have gone with an approach of storing the output of the sam package in another repository for manual deployment in multiple stages of the deployment (test, staging, production) over time.
Not sure if this is what is expected instead.
Hi @lb-pf, uploading modified CloudFormation template to S3 is not an expected behavior of sam package, regardless of the package types of the functions within. sam package only uploads packaged function codes or push image to ECR depending on package type. Instead of uploading the template to S3, sam package only writes the template to a specified location (using --output-template-file) or writes to console if --out-template-file is not specified.
The modified template is uploaded to S3 if you run sam deploy, which implicitly runs sam package, uploads the modified template, and deploys it.
For your use case, would it be possible to use sam deploy for each stage? I'd suggest you take a look at the Deploying section in our docs to check if sam pipeline would be useful as well.
I'm closing this issue for now. But feel free to open a new issue for a feature request.