Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Update to version v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aassadza committed Apr 22, 2021
1 parent ba6ce5c commit 7b935b8
Show file tree
Hide file tree
Showing 198 changed files with 18,129 additions and 32,876 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
**/global-s3-assets
**/regional-s3-assets
**/tests-s3-assets
**/open-source
**/dist/
**/.env/
*.pyc
**/*.egg-info
*.bin
Expand All @@ -13,3 +15,16 @@ __pycache__/
.pytest_cache
geckodriver.log
.eslintcache

# Coverage directory used by tools like istanbul
coverage-reports/
coverage
*.lcov

# Temporary folders
tmp/
temp/

### IDE such as VS Code or PyCharm ###
.vscode
.idea
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.6.0] - 2021-4-8

### Updated

- Updated `aws-amplify` version to 3.3.17
- Updated `aws-cdk` version to 1.96.0

### Added

- Custom resource to configure weather forecast, order pizza, book appointment, and leave feedback functionalities in [Amazon Lex](https://aws.amazon.com/lexv2/).
- Lambda function to integrate with Amazon Lex which allows for validation and data exchange with [DynamoDB](https://aws.amazon.com/dynamodb/)

### Changed
- Architecture diagram depicting the structure of AWS services and their interactions with Amazon Lex.
- Implementation Guide document to provide context of different usecases for customers on using Amazon Lex.

### Removed
- Legacy module (B2.core) that built a custom machine learning model to function as the brain of the chatbot.
## [1.5.0] - 2021-2-8

### Added

- Implementation to use [Amazon Lex](https://aws.amazon.com/lex/) as the processing module of the chatbot.
- Implementation to use [Amazon Lex](https://aws.amazon.com/lexv2/) as the processing module of the chatbot.
- Parameter to choose between the existing custom ML model or Amazon Lex as the processing module of the chatbot.
- Sample interaction for the chatbot application when Amazon Lex is chosen.

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ The solution is deployed using a CloudFormation template with a lambda backed cu

## Source Code

**source/modules**
Contains a nodejs module named b2.core that is used in train-model lambda function and polly-service lambda function.
**source/infrastructure**
Includes AWS CDK code describing the architecture of the solution. This CDK code will be transpiled into Cloudformation template when running `build-s3-dist.sh`.

**source/samples**
Includes five components, three sample lambda functions, a custom resource and a front-end web client. This code can be extended to add different functionalities to the bot.
Includes three components, a lambda function that integrates with Amazon Lex, a custom resource, and a front-end web client. This code can be extended to add different functionalities to the bot.

**source/services**
Includes source code for three lambda functions, core, custom-resource, and polly-service.
Includes source code for three lambda functions, core, lex-bot, webclient-setup, and polly-service.

**source/services/custom-resource**
**source/services/solution-helper**
A Python Lambda function used as a CloudFormation custom resource for configuring Amazon S3 bucket notifications and to send anonymous metrics.

## Creating a custom build
Expand All @@ -50,6 +50,8 @@ To make changes to the solution, download or clone this repo, update the source

- [AWS Command Line Interface](https://aws.amazon.com/cli/)
- Node.js 12.x or later
- Python 3.8 or later
- [AWS CDK](https://aws.amazon.com/cdk/)
- (Optional) [AccuWeather](https://developer.accuweather.com/) or [OpenWeather](https://openweathermap.org/api) API keys

### 1. Create the deployment packages
Expand Down Expand Up @@ -91,7 +93,7 @@ aws s3 sync ./regional-s3-assets s3://$ARTIFACT_BUCKET-us-east-1/$SOLUTION_NAME/

## Known Behavior

When you choose Amazon Lex for the `BotBrain` parameter, updating the CloudFormation stack will not update the chatbot in Amazon Lex.
When using the 'Leave Feedback' intent, the bot only accepts one-word feedback.

---

Expand All @@ -107,4 +109,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.removed api and email
limitations under the License.removed api and email
Binary file modified deployment/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 18 additions & 33 deletions deployment/build-s3-dist.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

######################################################################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES #
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions #
# and limitations under the License. #
######################################################################################################################
# This assumes all of the OS-level configuration has been completed and git repo has already been cloned

# This script should be run from the repo's deployment directory
Expand All @@ -13,7 +24,7 @@
set -e

# Important: CDK global version number
cdk_version=1.84.0
cdk_version=1.96.0

# Check to see if input has been provided:
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
Expand Down Expand Up @@ -58,12 +69,6 @@ echo "--------------------------------------------------------------------------
cd $template_dir/cdk-solution-helper
npm ci --only=prod

echo "------------------------------------------------------------------------------"
echo "[Rebuild] Core Resource"
echo "------------------------------------------------------------------------------"
cd $source_dir/modules/b2.core
npm ci --only=prod
echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Core Service"
echo "------------------------------------------------------------------------------"
Expand All @@ -72,10 +77,10 @@ npm ci --only=prod

echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Custom Resource"
echo "[Packing] Webclient Setup"
echo "------------------------------------------------------------------------------"
cd $source_dir/services/custom-resource
python3 setup.py install
cd $source_dir/services/webclient-setup
pip3 install -r requirements.txt --target .

echo ""
echo "------------------------------------------------------------------------------"
Expand All @@ -84,12 +89,6 @@ echo "--------------------------------------------------------------------------
cd $source_dir/services/polly-service
npm ci --only=prod

echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Train Model"
echo "------------------------------------------------------------------------------"
cd $source_dir/services/train-model
npm ci --only=prod
echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Solution Helper"
Expand All @@ -102,27 +101,14 @@ echo "[Packing] Lex Bot"
echo "------------------------------------------------------------------------------"
cd $source_dir/services/lex-bot
pip3 install -r requirements.txt --target .
echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Order Pizza"
echo "------------------------------------------------------------------------------"
cd $source_dir/samples/order-pizza
npm ci --only=prod

echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Sample Bot Weather Forecast"
echo "[Packing] Sample Bot lex lambdas"
echo "------------------------------------------------------------------------------"
cd $source_dir/samples/bot-weather-forecast
python3 setup.py install
cd $source_dir/samples/lex-lambdas
pip3 install -r requirements.txt --target .

echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Sample Bot Leave Feedback"
echo "------------------------------------------------------------------------------"
cd $source_dir/samples/leave-feedback

echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Sample WebClient"
Expand All @@ -135,7 +121,6 @@ echo "--------------------------------------------------------------------------
echo "[Packing] Sample API To SSM Custom Resource"
echo "------------------------------------------------------------------------------"
cd $source_dir/samples/write-api-to-ssm-custom-resource
python3 setup.py install
pip3 install -r requirements.txt --target .

echo "------------------------------------------------------------------------------"
Expand Down
139 changes: 125 additions & 14 deletions deployment/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,134 @@
#!/bin/bash

######################################################################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES #
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions #
# and limitations under the License. #
######################################################################################################################
# This script should be run from the repo's deployment directory
# cd deployment
# ./run-unit-tests.sh

[ "$DEBUG" == 'true' ] && set -x
set -e

run_python_test() {
local component_path=$1
local component_name=$2

echo "------------------------------------------------------------------------------"
echo "[Test] Run python unit test with coverage"
echo "------------------------------------------------------------------------------"
echo "cd $component_path"
cd $component_path

# setup python environment and install dependencies
if [ -e ./setup.py ]; then
python3 setup.py install
fi
pip3 install -r requirements.txt --target .
pip3 install -r requirements-dev.txt

# setup coverage report path
mkdir -p $coverage_reports_top_path
coverage_report_path=$coverage_reports_top_path/$component_name.coverage.xml
echo "coverage report path set to $coverage_report_path"

# run unittests
coverage run -m unittest discover

# prepare coverage reports
coverage xml -o $coverage_report_path
coverage report

# The coverage with its parameters and .coveragerc generates a xml coverage report with `coverage/sources` list
# with absolute path for the source directories. To avoid dependencies of tools (such as SonarQube) on different
# absolute paths for source directories, this substitution is used to convert each absolute source directory
# path to the corresponding project relative path. The $source_dir holds the absolute path for source directory.
sed -i -e "s,<source>$source_dir,<source>source,g" $coverage_report_path

# Note: leaving behind the $coverage_reports_top_path directory to allow further processing of coverage reports
rm -rf .coverage
}

run_javascript_test() {
local component_path=$1
local component_name=$2

echo "------------------------------------------------------------------------------"
echo "[Test] Run javascript unit test with coverage"
echo "------------------------------------------------------------------------------"
echo "cd $component_path"
cd $component_path

# setup and install dependencies
npm ci

# run unittest
npm test

# prepare coverage reports
rm -fr coverage/lcov-report
mkdir -p $coverage_reports_top_path/jest
coverage_report_path=$coverage_reports_top_path/jest/$component_name
rm -fr $coverage_report_path
mv coverage $coverage_report_path
}

run_cdk_project_test() {
local component_path=$1
local component_name=solutions-constructs
echo "------------------------------------------------------------------------------"
echo "[Test] $component_name"
echo "------------------------------------------------------------------------------"
cd $component_path


[ "${CLEAN:-true}" = "true" ] && npm run clean
npm ci
npm run build

## Option to suppress the Override Warning messages while synthesizing using CDK
# export overrideWarningsEnabled=false

npm run test -- -u

[ "${CLEAN:-true}" = "true" ] && rm -rf coverage/lcov-report
mkdir -p $source_dir/test/coverage-reports/jest
coverage_report_path=$source_dir/test/coverage-reports/jest/$component_name
rm -fr $coverage_report_path
mv coverage $coverage_report_path
}

# Run unit tests
echo "Running unit tests"

# Get reference for source folder
source_dir="$PWD/../source"

echo "cd $source_dir/samples/bot-weather-forecast"
cd $source_dir/samples/bot-weather-forecast
python3 setup.py install
pip3 install -r requirements.txt --target .
pip3 install -r dev-requirements.txt
python3 test.py

echo "cd $source_dir/samples/order-pizza"
cd $source_dir/samples/order-pizza
npm ci
npm test
source_dir="$(cd $PWD/../source; pwd -P)"
coverage_reports_top_path=$source_dir/test/coverage-reports

#
# run unit tests
#

run_cdk_project_test $source_dir/infrastructure

run_python_test $source_dir/samples/lex-lambdas lex-lambdas

run_python_test $source_dir/samples/write-api-to-ssm-custom-resource write-api-to-ssm-custom-resource

run_javascript_test $source_dir/services/core services-core

run_javascript_test $source_dir/services/polly-service services-polly

run_python_test $source_dir/services/lex-bot services-lex-bot

run_python_test $source_dir/services/webclient-setup services-webclient

run_python_test $source_dir/services/solution-helper services-solutions-helper
40 changes: 40 additions & 0 deletions source/infrastructure/bin/aws-sdk-config-aspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*********************************************************************************************************************
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance *
* with the License. A copy of the License is located at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES *
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions *
* and limitations under the License. *
*********************************************************************************************************************/

import { Construct, IAspect, IConstruct } from '@aws-cdk/core';
import { Function, RuntimeFamily } from '@aws-cdk/aws-lambda';

export class AwsSdkConfig extends Construct implements IAspect {
private readonly solutionId: string;

constructor(scope: Construct, id: string, solutionId: string) {
super(scope, id);
this.solutionId = solutionId;
}

public visit(node: IConstruct): void {
let userAgent = '';

if (node instanceof Function) {
const runtimeFamily = node.runtime.family;

if (runtimeFamily == RuntimeFamily.NODEJS) {
userAgent = `{ "customUserAgent": "AwsSolution/${this.solutionId}/%%VERSION%%" }`;
} else if (runtimeFamily == RuntimeFamily.PYTHON) {
userAgent = `{ "user_agent_extra": "AwsSolution/${this.solutionId}/%%VERSION%%" }`;
}

node.addEnvironment('AWS_SDK_USER_AGENT', userAgent);
}
}
}
Loading

0 comments on commit 7b935b8

Please sign in to comment.