sam deploy command deploys your application by launching a CloudFormation stack. This command has a guided interactive mode, which you enable by specifying the –guided parameter. It is recommended to deploy with guided mode for the first time as it will capture the configuration for future deployments.
Run the following command in the same directory level where the
template.yaml is located:
sam deploy --guided
It will ask for certain input parameters, like so:
Y for options that require
Besides, our region is
ap-southeast-1, so please change the region from default
When the build finishes successfully, you should see a new directory created in the root of the project named
.aws-sam. It is a hidden folder, so if you want to see it in the IDE, make sure you enable Show hidden files in Cloud9 to see it.
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.
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:
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.
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.