Deploy the app

The sam deploy command deploys your application by launching a CloudFormation stack. This command now comes with a guided interactive mode, which you can enable by specifying the –guided parameter. It walks you through the parameters required for deployment, provides default options, and saves these options in a configuration file in your project folder.

Run the following command in the same directory level where the packaged.yaml is located:

sam deploy --guided

It will ask for certain input parameters, like so:


Confirm deployment

At some point, SAM will ask for deployment confirmation. This is possible because it first creates a CloudFormation ChangeSet, and then it asks for confirmation to execute it. This is kind of like a dry run deployment and is a best practice when doing deployments via CloudFormation. Type y to confirm.


Deployment completed

This command might take a few minutes to finish because it is creating the resources (Lambda function, API Gateway and IAM roles) on the AWS account. When it completes successfully, you should see an output similar to the following:


What just happened?

The guided deployment does few things for you. Let’s take a quick look at what happened under the hood during the guided deployment to understand this process better.

1) Your codebase gets packaged in a zip file.
2) SAM creates an S3 bucket in your account, if it doesn’t already exist.
3) Zip file is uploaded to the S3 bucket.
4) SAM creates the packaged template that references the location of the zip file on S3.
5) This template is also uploaded to the S3 bucket.
6) SAM starts the deployment via CloudFormation ChangeSets.

The first time you do a guided deployment, a new file samconfig.toml is created in the root of your project with your specified deployment parameters, this is so that the next time you execute sam deploy, it uses the same parameters without having you to enter them again.


If you want to learn more about guided deployments and the samconfig.toml file, here is a good Blog Post: