An independent guide to building modern software for serverless and native cloud

Performing an Initial Deployment

This lab references the code in the aws-connectedcar-dotnet-serverless repository. If you're new to this course, see the introduction for information about setting up your workstation and getting the sample code.

In this lab we’re going to run the scripts for the first time in order to deploy the sample code to AWS. Once this code is deployed, we’re going to see the results in CloudFormation, where we’ll review the parameters, outputs, and events for the created stack. We’ll also take a quick tour of the deployed resources to help you get familiar with the AWS console. We’ll continue to work with this deployment in the labs that follow for this section.

Before You Start

Since this is the first lab in the course, you should confirm that all the things you need are in place for your cloud accounts, your workstation setup, and that you have the sample code. If you haven't already, go through these "First Steps" lessons from the Introduction section of this course:

Configuring the Deployment Scripts

Step 1: Set the workspacePath and bucket variables in the config.zsh script

Before you run the deployment scripts, you need to assign values for the first two variables in the config.zsh script. Here’s the zsh version of this script, where the workspacePath and bucket variables, on lines 5-6, need values assigned. Open this script in the VS Code editor, and set these values based on your workstation setup and the bucket that you created for deployments:

Running the Deployment Scripts

Step 2: Open the CloudFormation stacks page in the console

Open the AWS console, navigate to the CloudFormation service, and select the “Stacks” menu on the left. Assuming you haven’t deployed anything else with CloudFormation in the selected region, the stacks page should look empty like this:

Step 3: Run the clean.zsh script in the terminal

Now we’re going to start the deployment process by first running the clean.zsh script. Besides deleting any files from the S3 bucket, running this script also validates your local AWS configuration, your network connectivity, and the values you just set for the config script variables.

Returning to the VS Code terminal, change to the appropriate SAM deployment scripts folder. Your VS Code terminal should look like this:

Next, run the clean.zsh script. There shouldn’t have been any files in the S3 bucket, so once this script executes, your terminal should look like this:

Step 4: Run the build.zsh script in the terminal

Now you’re ready to run the build.zsh script. This script will run the “dotnet lambda package” command which compiles the Lambda code and creates a zipped deployment file. The script will then upload this file to the target folder on the S3 bucket.

Run the script, and the initial VS Code terminal output for this script should look something like this:

Once complete, the terminal should show the successful upload of the Lambda deployment package to the S3 bucket, as shown below, at the bottom:

Step 5: Confirm the Lambda package upload in the console

Switch back to the AWS console, navigate to the S3 service and select your S3 deployment bucket. Then drill down into the folders, selecting the “ConnectedCar” folder, and then the “Dev” folder (assuming you’re using the default ServiceName and EnvironmentName values). You should now see the Lambda deployment package, with the VersionNumber appended to the file name, similar to what’s shown below:

Step 6: Run the deploy.zsh script in the terminal

Finally, run the deploy.zsh script. This script uploads the child template files to the S3 deployment bucket, and then run commands to create the CloudFormation stack, wait for completion, and write the stack outputs to the terminal. The initial terminal output should show the template file uploads followed by the create-stack command output, like this:

After a few minutes, CloudFormation should have fully deployed the stack. At that point the terminal should look like this, with the stack outputs displayed:

Checking the Results

Step 7: View the CloudFormation stacks in the console

Navigate back to the CloudFormation service in the AWS console and again select the “Stacks” menu on the left. You should now see the parent stack at the bottom, and the nested child stacks above it, as shown below. If you don’t see the nested stacks, turn on the “View nested” toggle at the top right of the page:

Click on the “ConnectedCarDev” stack, at the bottom, close the left-most panel to give yourself a bit more room, and then select the “Parameters” tab at the top right. You should see the parameters that were specified for the stack:

Next, click on the “Outputs” tab to see the same stack output names and values as you saw displayed in the VS Code terminal:

Lastly, click on the “Events” tab to see the steps that CloudFormation took to create the selected stack:

Step 8: View some of the stack resources in the console

While you’re in the console, take a quick tour of some of the resources you’ve just deployed. To start, navigate to the API Gateway service, where you should see the three newly created APIs like this:

Next, navigate to the Lambda service, where you should see several pages of newly created Lambdas:

Lastly, navigate to the DynamoDB service and select the “Tables” menu on the left: