sam package and deploy without packaged parameter file

876 views Asked by At

Our sam package command is -

sam package --template-file template.YML --output-template-file packaged-service.yml --s3-bucket $Template_Bucket_Name --s3-prefix service-build-$packagenumber

sam deploy command is -

sam deploy packaged-service.yml --stack-name service --capabilities CAPABILITY_NAMED_IAM --region us-east-1 --s3-bucket $Template_Bucket_Name --s3-prefix service-deploy-$packagenumber --template-file template.YML --parameter-overrides  "ParameterKey=EnvType,ParameterValue=ftest" --no-fail-on-empty-changeset

What is significance of packaged-service.yml file ? I can run deploy without it. So what purpose it fulfils ? Official package and deploy page are not clear about it. packaged-service.yml has a codeuri field points to s3 bucket. In the above example, probably the file has no use ? How to use metadata option during aws sam deploy command ?

1

There are 1 answers

1
JD D On

If you are using the latest version of the SAM CLI, then this package step is now implicitly performed when you do a deploy.

In earlier versions of SAM, the package step was needed if your lambda functions required dependencies to be packaged up into an archive. It wasn't 100% necessary as if your Lambda was a single python file then you could go straight to deploy. Since most SAM projects are more complex, the package helped by packaging your project into an archive, uploading your artifacts to S3 and then re-writing your SAM yaml to reference the new S3 location where the artifacts were uploaded.

I think the AWS team eventually saw that this package step was a little redundant and almost always performed before a deploy so they streamlined the process with an update made in November 2019 which made the process much simpler.

The package command is still included for backwards compatibility and to allow more flexibility if some teams still desire a multi-stage build and deploy process.