Skip to content

Commit

Permalink
Merge pull request #705 from aws-samples/development
Browse files Browse the repository at this point in the history
Version 0.20.4
  • Loading branch information
atjohns authored Jul 15, 2024
2 parents f44b371 + e0f7c50 commit cd9fc34
Show file tree
Hide file tree
Showing 31 changed files with 1,483 additions and 2,250 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.21.2] - 2024-06-27
## [0.21.4] - 2024-07-15
- The Lex Web UI can now act as a passthrough for Q Business, allowing users to converse directly with their Q Business application while inheriting all the features of the Web UI such as embedding, CSS customizations and more.
- Upgraded version of amazon-connect-chatjs

## [0.21.3] - 2024-06-27
- Dependency & documentation updates
- Fixed a bug that was causing builds on Windows machines to fail

Expand Down
72 changes: 72 additions & 0 deletions README-qbusiness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Amazon Q Business Integration

Amazon Q is a new generative AI-powered application that helps users get work done. Amazon Q can become your tailored business expert and let you discover content, brainstorm ideas, or create summaries using your company’s data safely and securely. For more information see: [Introducing Amazon Q, a new generative AI-powered assistant](https://aws.amazon.com/blogs/aws/introducing-amazon-q-a-new-generative-ai-powered-assistant-preview)

This feature of the Web UI lets you use Amazon Q's generative AI directly with the Web UI, using a deployed sample bot as a passthrough to the Q Business application. This allows your solution to take advantage of the native Web UI features - embedding, customization, etc - while still leveraging the answering capabilities of Amazon Q.

This feature supports integration with file attachments, enable both to allow QBusiness to read files uploaded via Lex Web UI. There's more information on this feature in the [File Upload README](https://github.com/aws-samples/aws-lex-web-ui/blob/master/README-file-upload.md).

**Note:*** - The default deployed solution will return a failure message if the user is not logged in or does not have a valid Q Business subscription. This can be customized in the Fulfilment Lambda that is deployed by the CloudFormation template.

### Prerequisites
1. An existing deployment of a Q Business application is required for this solution. Please reference the AWS docs for creating a new [Q Business application](https://docs.aws.amazon.com/amazonq/latest/qbusiness-ug/create-application.html)

### Deploy the Web UI
1. A deployment of the Lex Web UI with login enabled is required for Q Business integration. To launch a new

2. The other bot fields for both V1 & V2 bots must be empty for the template to create the Q Business integration bot, please ensure that `Lex V1 Bot Configuration Parameters` and `Lex V2 Bot Configuration Parameters` are blank.

3. To enable login, set `EnableCognitoLogin` to true. To force users to login to your bot, set `ForceCognitoLogin` to true. The ForceCognitoLogin setting will automatically redirect users to the login page if they are not logged in to the bot.

4. In the `Q Business Parameters` section of the template, provide the Amazon Q Application ID. For now, leave the 'IDCApplicationARN' field blank. This application must be created after Cognito is deployed by the initial Web UI deployment and the stack can be updated later to provide this value.

5. Deploy the stack.

6. When the stack is finished deploying (showing a CREATE_COMPLETE status) go the Outputs tab. You will need the following Outputs for setting up the Identity Center Application:
- CognitoUserPoolClientId
- CognitoUserPoolPubKey
- QBusinessLambdaRoleARN

### Creating an Trusted token issuer in Identity Center

1. The Cognito user pool created by the Web UI will need to be added as **Trusted token issuer** to Identity Center by doing the following steps. Note that if you are not an admin in your organization, an administrator with Identiy Center access might need to create the token issuer and application.
1. Go to Identity Center and click on `Settings`, click the `Authentication` tab and then scroll down and select `Create trusted token issuer`
2. The issuer URL will be the **CognitoUserPoolPubKey, but remove /.well-known/jwks.json from the end of the URL**, the issuer URL you supply shoudl be in the form of `https://cognito-idp.[region].amazonaws.com/[cognito-pool-id]`. The application also needs to be provided with attribute mapping between Identity Center and Cognito to recognize users, this should be a unique attribute for each user (the default is email address)
![Issuer](./img//token-issuer.PNG)
3. With a trusted token issuer in place, the custom application can now be created.

### Creating a Identity Center Application w/ Cognito trust

1. A custom application will need to be created in Identity Center to handle the connection between your Q Business application and your Cognito pool. Follow these steps to create the application.
1. Go to Identity Center and click on `Applications` then `Add application`
2. Select `I have an application I want to set up` and `OAuth 2.0` on the next page for Selecting Application type, then hit `Next`
3. For `Application URL`, provide the **Web experience URL** of your Q Business application. You can either opt to assign specific users/groups to this application or allow any Identity Center users/groups to access the application. Your Q Business subscriptions will still apply however so only users with a subscription can successfully chat with the application. Then hit `Next`.
4. Select the Trusted token issuer that was created in Step 2 of this guide, you will now need an aud claim so that the token issuer can identify the application. The aud claim is the **CognitoUserPoolClientId** output value from the Web UI stack. Take this value and paste it into the aud claim field, then select `Next`
![Claim](./img//aud-claim.PNG)
5. Under `Enter IAM roles`, take the role that was created by the Web UI stack for the QBusiness Lambda function. This is the **QBusinessLambdaRoleARN**. Paste this value into field and select `Next`.
6. Hit `Submit` to complete creation of the application.
7. The application is accessible under the `customer managed` tab of the Identity Center applications. Select the just created application to make changes.
8. Depending on the selection in step 3 above, users may still need to be assigned to the application. These will be the same users you have assigned to the Q Business application.
7. Finally, make Amazon Q a trusted application for identity propagation by selecting `Specify trusted applications` and finding QBusiness in the list of potential application for trust. When complete your app should appear similar to the below configuration
![IdentityPropagation](./img//identity-propagation.PNG)
8. Copy the `Application ARN` found on this page, it will be used to update the Lex Web UI stack.

### Adding users to Cognito

1. Any user who has a Q Business subscription will need a user account in Cognito, linked by the attribute mapping defined when the `Trusted token issuer` was created.
2. These users can be added manually or by integrating it via [SAML to a 3rd party provider](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-integrating-3rd-party-saml-providers.html).


### Update the Lex Web UI stack

1. Return to CloudFormation and click on the stack that was initially used to deploy the Web UI.
2. On the top-right menu, select `Update`
3. Leave the default of 'Use existing template' and hit `Next`
4. Under Q Business Parameters, find the **IDCApplicationARN** and paste the `Application ARN` copied at the end of the previous section.
5. Launch the update of the stack.

## Validate deployment

Your deployment of the Web UI should now talk directly to Amazon Q Business and return the same responses as the default web experience. In addition, by turning on upload capabilities you can ask Q Business questions about documents and get GenAI answers.

![QBusinessDemo](./img//QBusiness.gif)
46 changes: 16 additions & 30 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ VPATH := $(OUT)

# upload files to bootstrap bucket
# NOTE: files uploaded with public read permissions
upload: upload-templates upload-custom-resources-zip upload-src-zip \
upload-response-card-image upload-initiate-chat-lambda upload-streaming-lambda
upload: upload-templates upload-src-zip upload-response-card-image \
upload-initiate-chat-lambda upload-streaming-lambda upload-qbusiness-lambda
.PHONY: upload

# create the output directory for tracking dependencies
Expand All @@ -39,34 +39,6 @@ upload-templates: $(TEMPLATES) | $(OUT)
| tee "$(OUT)/$(@)"
@echo "[INFO] master template: https://s3.amazonaws.com/$(BOOTSTRAP_BUCKET_PATH)/templates/master.yaml"

# cfn custom resource lambda files are found under this directory
CUSTOM_RESOURCES_DIR := $(TEMPLATES_DIR)/custom-resources

# zip cfn custom resource lambda files
BOT_DEFINITION_FILE := $(CUSTOM_RESOURCES_DIR)/bot-definition.json
PY_MODULES := $(CUSTOM_RESOURCES_DIR)/py_modules
CUSTOM_RESOURCES_ZIP := custom-resources-$(VERSION).zip
CUSTOM_RESOURCES_FILES := $(wildcard $(CUSTOM_RESOURCES_DIR)/*.py)
CUSTOM_RESOURCES_FILES += $(BOT_DEFINITION_FILE)
CUSTOM_RESOURCES_FILES += $(PY_MODULES)
$(PY_MODULES):
pushd $(CUSTOM_RESOURCES_DIR) ; \
[ -f requirements.txt ] && \
python3 -m pip install --upgrade -r requirements.txt -t ./py_modules || true ; \
popd ;
$(CUSTOM_RESOURCES_ZIP): $(CUSTOM_RESOURCES_FILES) | $(OUT)
@echo "[INFO] Creating custom resource Lambda zip file"
zip -u -j "$(OUT)/$(@)" $(?) ; \
pushd $(CUSTOM_RESOURCES_DIR)/py_modules ; \
zip -r -q "../../../build/$(OUT)/$(@)" . ; \
popd ;
upload-custom-resources-zip: $(CUSTOM_RESOURCES_ZIP) | $(OUT)
@echo "[INFO] Uploading custom resources Lambda zip file"
aws s3 cp --acl public-read \
"$(OUT)/$(CUSTOM_RESOURCES_ZIP)" \
"s3://$(BOOTSTRAP_BUCKET_PATH)/$(CUSTOM_RESOURCES_ZIP)" \
| tee -a "$(OUT)/$(@)"

# initiate chat lambda function

INITIATE_CHAT_LAMBDA_DIR := $(SOURCE_DIR)/initiate-chat-lambda
Expand Down Expand Up @@ -99,6 +71,20 @@ upload-streaming-lambda:
"$(OUT)/$(STREAMING_LAMBDA_ZIP)" "s3://$(BOOTSTRAP_BUCKET_PATH)/$(STREAMING_LAMBDA_ZIP)" \
| tee -a "$(OUT)/$(@)"

QBUSINESS_LAMBDA_DIR := $(SOURCE_DIR)/qbusiness-lambda
QBUSINESS_LAMBDA_ZIP := qbusiness-lambda-$(VERSION).zip
QBUSINESS_LAMBDA_RESOURCES_FILES := $(wildcard $(QBUSINESS_LAMBDA_DIR)/*.py)

$(QBUSINESS_LAMBDA_ZIP): $(QBUSINESS_LAMBDA_DIR)/index.py
@echo "[INFO] Creating qbusiness Lambda zip file"
zip -r -j "$(OUT)/$(QBUSINESS_LAMBDA_ZIP)" $(QBUSINESS_LAMBDA_DIR) ;

upload-qbusiness-lambda:
@echo "[INFO] uploading qbusiness lambda"
aws s3 cp --acl public-read \
"$(OUT)/$(QBUSINESS_LAMBDA_ZIP)" "s3://$(BOOTSTRAP_BUCKET_PATH)/$(QBUSINESS_LAMBDA_ZIP)" \
| tee -a "$(OUT)/$(@)"

# files in this repo are bundled in a zip file to boostrap the codecommit repo
SRC_ZIP := src-$(VERSION).zip
SRC_FILES := $(shell git ls-files ..)
Expand Down
12 changes: 5 additions & 7 deletions build/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ case $unamestr in
"Darwin" | "FreeBSD")
sed -i '' -e "s/(v.*)/($VERSION)/g" \
-e "s/Timestamp:.*/Timestamp: $timestamp/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
../templates/master.yaml;

sed -i '' -e "s/(v.*)/($VERSION)/g" \
-e "s/Timestamp:.*/Timestamp: $timestamp/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
../templates/master-pipeline.yaml;;
Expand All @@ -25,15 +23,15 @@ sed -i -e "s/(v.*)/($VERSION)/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
-e "s/streaming-lambda-.*zip/streaming-lambda-$VERSION.zip/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/qbusiness-lambda-.*zip/qbusiness-lambda-$VERSION.zip/g" \
../templates/master.yaml;

sed -i -e "s/(v.*)/($VERSION)/g" \
-e "s/Timestamp:.*/Timestamp: $timestamp/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
-e "s/streaming-lambda-.*zip/streaming-lambda-$VERSION.zip/g" \
-e "s/streaming-lambda-.*zip/qbusiness-lambda-$VERSION.zip/g" \
../templates/master-pipeline.yaml;;

*)
Expand All @@ -42,15 +40,15 @@ sed -i -e "s/(v.*)/($VERSION)/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
-e "s/streaming-lambda-.*zip/streaming-lambda-$VERSION.zip/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/qbusiness-lambda-.*zip/qbusiness-lambda-$VERSION.zip/g" \
../templates/master.yaml;

sed -i -e "s/(v.*)/($VERSION)/g" \
-e "s/Timestamp:.*/Timestamp: $timestamp/g" \
-e "s/custom-resources-.*zip/custom-resources-$VERSION.zip/g" \
-e "s/src-.*zip/src-$VERSION.zip/g" \
-e "s/initiate-chat-lambda-.*zip/initiate-chat-lambda-$VERSION.zip/g" \
-e "s/streaming-lambda-.*zip/streaming-lambda-$VERSION.zip/g" \
-e "s/qbusiness-lambda-.*zip/qbusiness-lambda-$VERSION.zip/g" \
../templates/master-pipeline.yaml;;


Expand All @@ -61,9 +59,9 @@ npm run build-dist
cd ..
make
cd build
make "custom-resources-$VERSION.zip"
make "initiate-chat-lambda-$VERSION.zip"
make "streaming-lambda-$VERSION.zip"
make "qbusiness-lambda-$VERSION.zip"
cd ..
cd dist
make
Expand Down
9 changes: 6 additions & 3 deletions build/upload-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ popd
aws s3 cp out/src-$version.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/src-$version.zip"

aws s3 cp out/custom-resources-$version.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/custom-resources-$version.zip"

aws s3 cp out/initiate-chat-lambda-$version.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/initiate-chat-lambda-$version.zip"

aws s3 cp out/streaming-lambda-$version.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/streaming-lambda-$version.zip"

aws s3 cp out/qbusiness-lambda-$version.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/qbusiness-lambda-$version.zip"

aws s3 sync --exclude "*" --include "*.yaml" \
../templates "s3://${BOOTSTRAP_BUCKET_PATH}/templates/"

aws s3 cp ..templates/layers.zip \
"s3://${BOOTSTRAP_BUCKET_PATH}/layers.zip"

echo "[INFO] master template: https://s3.amazonaws.com/${BOOTSTRAP_BUCKET_PATH}/templates/master.yaml"
2 changes: 1 addition & 1 deletion dist/lex-web-ui-loader.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lex-web-ui-loader.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* lex-web-ui v0.21.3
* lex-web-ui v0.21.4
* (c) 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Released under the Amazon Software License.
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/lex-web-ui.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wav-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/wav-worker.min.js

Large diffs are not rendered by default.

Binary file added img/QBusiness.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/aud-claim.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/identity-propagation.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/token-issuer.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cd9fc34

Please sign in to comment.