Deploying the Code
Quick Start Guide
This is the third of four Quick Start Guides for the Java Serverless variant of the Connected Car solution. In this document we'll go through the steps to build and deploy the code that you've previously cloned on your workstation. If you haven't yet gone through the previous two Quick Start Guides, then follow the links at the bottom of this page for the "Getting the Code" and "Exploring the Code" guides.
Setting up your Accounts
When you cloned the code on your workstation, you only needed VS Code and GIT as pre-requisites. But now, to build and deploy the code to AWS, there are additional account and workstation setup tasks to work through. To start, follow the steps in these two documents to make sure you have set up your AWS and Github accounts as required:
Setting up your Github Account
Setting up your Workstation
Once your accounts are ready, follow the steps in one of these two workstation setup documents, depending on your platform:
Setting up your MacOS Workstation
Setting up your Windows Workstation
Creating a Deployment Bucket
Once your accounts and workstation are all ready, the next task is to use one of the scripts in the common repository to create an S3 deployment bucket in AWS. This will also validate the installation and configuration of the AWS CLI on your workstation.
Note that this command will create the bucket in the default region that you configured for your AWS CLI.
In VS Code, open the common repository and navigate to the /scripts/setup/zsh folder. There you should see the create-deployment-bucket.zsh script (note that there's an equivalent PowerShell script in an adjacent folder, if you are a Windows user). From the terminal, set execution privileges and run this script. Assuming your AWS CLI is working as expected, you should see an output like below, with a bucket name (highlighted) that you can copy and save for a following step:
Building the Code
Once you've created the deployment bucket, you can move on to building and deploying the code. We'll start by doing a simple build in VS Code. This will validate your workstation's Maven configuration and its access to the Github packages.
To perform this build, open the serverless repository in VS Code, press Cmd-P (or Ctrl-P for Windows) and type "task" plus a space. As shown below, this should display the build options in the tasks.json file, one of which is "build":
Click on the "build" option, which will run the Maven build. Assuming everything is set up properly, you should ultimately see a successful build output in the terminal, as shown below.
Deploying the Code
Now we're ready to run the command-line scripts that deploy the code to AWS. The first step is to open the config.zsh script in the /deployment/sam/scripts/zsh folder and update the "workspacePath" and "bucket" variable values, as highlighted below:
The "workspacePath" value will depend on where you opted to clone the repository on your workstation. The bucket value will be the name of the S3 bucket that you created previously.
Once the config.zsh script is updated, you can run the three deployment scripts in sequence, starting with the clean.zsh script. This script deletes any files that have been uploaded to the deployment bucket, so it isn't necessary at this stage, but running it will validate the config.zsh settings. Following this, run the build.zsh script. This will compile the code, generate a deployment package for the Lambdas, and upload this as a zip file to the deployment bucket in AWS.
Lastly, run the deploy.zsh script. This will upload the CloudFormation templates for the solution to the deployment bucket, and then run the command to create a CloudFormation stack, which kicks off the deployment process in AWS. After a few minutes, if successful, you should see the CloudFormation stack outputs written to the console in the terminal, as shown below.
Note that this command, as with the create bucket command ran previously, will deploy the code to the default region that you configured for your AWS CLI.
To view the results of the CloudFormation deployment in AWS, open the console and navigate to CloudFormation. Click on the "Stacks" menu on the left, and provided you are looking at the same region to which you deployed the code, you should see a list of stacks as shown below:
At this point the code is deployed, so you're ready to follow the link below to the "Testing the Code" page.