21

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.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Ordep81
  • 967
  • 4
  • 13
  • 18

2 Answers2

42

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).

Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54
2

I normally do only sam build and deploy by sam deploy

  1. sam build is to build the application locally by combine SAM Template (YAML) + Application Code together.
  2. Transform the combination to Cloud Formation Template (YAML) + Application Code
  3. Followed by sam package is to package the application to zip file and upload to S3 Bucket.
  4. Lastly, Deploy the application to CloudFormation by sam deploy to create/execute change.