In this exercise, you will deploy the TravelBuddy website as a Single Page web Application (SPA) on S3. You will then implement a chatbot that registered users can use to have natural-language dialogue with your microservices in order to find information about flights.
The SPA implementation you have been provided has stubbed-out implementations of the three APIs we want to expose to our users. They have just enough implementation to not cause an error on the page when executed, but they do not provide any data. In order to ‘wire up’ our APIs to the SPA, we will need to implement the microservices, deploy them to AWS Lambda, create an API endpoint for each and generate the Javascript client SDKs that relate to these APIs. You completed this task in the previous module and it is not necessary for you to wire up all the microservices for this lab, but you could do so if you wish to practice the steps. If you do wire up all the microservices, then you will have a fully-working TravelBuddy website, complete with Flight Services, Hotel Services and Trip Services searching, and also a chat bot for natural language queries - ready to ship!
If you prefer to skip the creation of the microservices, skip ahead to Update the TravelBuddy SPA configuration.
In this step, you will use the AWS CLI and CloudFormation/SAM to deploy the microservices. By using CloudFormation/SAM, many of the manual steps will be taken care of for you, streamlining the deployment process. You will still have to manually trigger the process, but the actual deployment will be automated.
The HotelSpecials và FlightSpecials microservices need to access a MySQL database to retrieve the hotel specials data. The lab environment has automatically deployed and seeded a database for you, and the connection details are provided Cloudformation Outputs tab with instructions below on where to update the placeholder in the template you will use to deploy the microservice. The MySQL instance has been deployed using Amazon RDS and is not publicly-accessible since it is launched in a private subnet. Therefore, for the Lambda functions to be able to connect to the database, the Lambda functions will also need to be deployed into a private subnet by enabling VPC Integration. The template.yml file provided for both these services has all the required setup to do this, you just need to update the placeholders as per the below instructions.
mvn package shade:shade
aws cloudformation package --template template.yml --s3-bucket <S3BucketLambdaCode> --output-template template-export.yml --profile aws-lab-env --region us-east-1
Replace the with the value shown with the name S3 bucket already in module 6.
aws cloudformation deploy --template-file template-export.yml --stack-name <MICROSERVICE_NAME> --capabilities CAPABILITY_IAM --profile aws-lab-env
Thay thế <MICROSERVICE_NAME> bằng một tên phù hợp.
Be sure to repeat this process for both the HotelSpecials and FlightSpecials microservices.
mvn package shade:shade
aws cloudformation package --template template.yml --s3-bucket <S3BucketLambdaCode> --output-template template-export.yml --profile aws-lab-env --region us-east-1
Replace the with the value shown Cloudformation Outputs tab for the key S3BucketLambdaCodeBucketName. Do not include the < and > symbols.
aws cloudformation deploy --template-file template-export.yml --stack-name TripSearchAPI --capabilities CAPABILITY_IAM --profile aws-lab-env --region us-east-1
For each of the three APIs we have created, follow these instructions, using either the name TripSearch, HotelSpecials or FlightSpecials as appropriate. In the steps below, we refer to FlightSpecials - you need to use the right name for the API you are configuring:
apigClient_FlightSpecials.js
(or apigClient_HotelSpecials.js
/ apigClient_TripSearch.js
)apigClientFactory
with apigClientFactory_FlightSpecials
(or apigClientFactory_HotelSpecials
/ apigClientFactory_TripSearch
). There will be 2 occurrences to replace, both at the start of the file.In this exercise, you will update the configuration file for the TravelBuddy SPA, so that it can make use of the Cognito infrastructure that has been provisioned for you by the lab setup.
26.On your local filesystem, locate the file webapp-configuration.js into the scripts directory of the TravelBuddy web site bundle you have downloaded and exploded previously. This file has the following contents:
(function () {
"use strict";
angular
.module("app")
.constant(
"COGNITO_IDENTITY_POOL_ID",
"REPLACE_WITH_COGNITO_IDENTITY_POOL_ID"
)
.constant("COGNITO_USER_POOL", "REPLACE_WITH_COGNITO_USER_POOL")
.constant(
"COGNITO_USER_POOL_CLIENT_ID",
"REPLACE_WITH_COGNITO_USER_POOL_CLIENT_ID"
)
.constant("COGNITO_APP_WEB_DOMAIN", "REPLACE_WITH_S3_BUCKET_WWW")
.constant("LEX_BOT_NAME", "TravelBuddyChatBot")
.constant("AWS_REGION", "us-east-1")
.constant("APP_BANNER", "TravelBuddy");
})();
The SPA is implemented using the Angular framework, which allows you to define global constants that are used as configuration variables throughout your application. This file defines the values of the configuration variables that you need to set based on your AWS Account’s ARNs and Ids for the various Cognito resources. Open the webapp-configuration.js file in a text editor and change the values in the configuration file according to the table below. You can find the correct values for your lab account, Cloudformation Outputs tab in labs cloudformation:
Placeholder name | Value to replace with from lab setup |
---|---|
REPLACE_WITH_COGNITO_IDENTITY_POOL_ID | CognitoIdentityPoolId |
REPLACE_WITH_COGNITO_USER_POOL | CognitoUserPool |
REPLACE_WITH_COGNITO_USER_POOL_CLIENT_ID | CognitoUserPoolClientId |
REPLACE_WITH_S3_BUCKET_WWW | S3BucketWWW |
us-east-1 | YOUR REGION |
With the API SDKs in place and the application configured to use the Amazon Cognito infrastructure, you are now ready to deploy the SPA code to the Amazon S3 Bucket that will serve the website. The lab setup process has provisioned a suitable S3 bucket, with WebSite Hosting enabled. So you will only need to push all the files from your local machine to the S3 bucket to be able to test the application.
aws s3 sync . s3://<S3BucketWWW>/TravelBuddy --profile aws-lab-env
Replace with the S3Bucket name provided in CloudFormation Output of Moudule 6.
NThere is also a new option - Chat with us! This is the UI part of the chat bot that we will implement in the following exercises.