I'm building some serverless apps and trying to use SAM. I've been going through some tutorials and some use sam build
, while others use sam package
.
What are the differences between these commands? It seems like sam package is more difficult to use.
AWS SAM CLI lets you locally build, test, and debug serverless applications defined by SAM templates. Using the sam build command, you can easily create deployment artifacts that target AWS Lambda's execution environment. This enables the functions you build locally to run in a similar environment in the cloud.
Packages an AWS SAM application. This command creates a . zip file of your code and dependencies, and uploads the file to Amazon Simple Storage Service (Amazon S3). AWS SAM enables encryption for all files stored in Amazon S3.
Builds a serverless application and prepares it for subsequent steps in your workflow, like locally testing the application or deploying it to the AWS Cloud.
SAM templates are a superset of Cloudformation. Any Cloudformation template can be run through SAM unchanged, and it will work. SAM supports all the types available in Cloudformation templates, so you can think of SAM as "CloudFormation++".
You may see some older tutorials where they were using sam package
but the task that this command is/was performing is now built into sam deploy
command so you don't need to perform it manually anymore.
The common order of calls today is init
-> build
-> deploy
.
As for the differences between those 2, build
preprocesses your project files locally while package
used to zip your project, push it to S3 bucket and returned a processed template (replacing code references) that you would subsequently deploy (this zipping, pushing to s3 and deploying is now handled by deploy
command).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With