Skip to content

Commit bffca94

Browse files
committed
Merge branch 'development' v0.9.0
2 parents 5642573 + 1ac170a commit bffca94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3765
-518
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist/*.js -diff
22
dist/*.css -diff
33
dist/*.map -diff
4+
dist/*.zip -diff

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build
2+
config
3+
img
4+
lex-web-ui
5+
Makefile

CHANGELOG.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,79 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.9.0] - 2017-08-04
8+
This release adds a couple of simplified deployment options:
9+
1. Simplfied CloudFormation stack without a deployment pipeline.
10+
It uses CodeBuild to create the config files and to deploy directly
11+
to S3.
12+
This mode is the new default of the CloudFormation setup so if
13+
you want to keep using the deployment pipeline setup (CodeCommit,
14+
CodeBuild, CodePipeline), you are going to need to explicitly set the
15+
`CreatePipeline` parameter to true.
16+
2. AWS Mobile Hub project file that deploys the Web UI to S3 fronted
17+
by a CloudFront distribution. The Mobile Hub project also creates the
18+
Cognito Identity Pool, Lex Bot and IAM Roles. This allows to deploy the
19+
application from a single file hosted in github.
20+
21+
**NOTE**: At this point, there is a Content-Type issue with the files
22+
deployed using the Mobile Hub project file. The Mobile Hub deployed
23+
files seem to have its content-type set to octect-stream which causes the
24+
browser to download the files instead of rendering. To work around this
25+
issue, you can re-upload the files using the S3 console or aws cli. The
26+
Makefile in the root dir can be used to upload the files with the right
27+
content type. Use the command: `make sync-website` (requires setting
28+
the bucket name with the `WEBAPP_BUCKET` environmental variable). This
29+
issue will be further investigated.
30+
31+
### Added
32+
- Added Mobile Hub deployment
33+
- Added new CloudFormation template `codebuild.yaml` used to deploy the
34+
application without a pipeline
35+
- Added `CreatePipeline` parameter to the master.yaml template to control
36+
whether the stack should create a deployment pipeline
37+
- Added build-time support to set web UI config fields that are commonly
38+
changed using environmental variables. This is in preparation to set
39+
these variables from CloudFormation parameters. The new variables include:
40+
* BOT_INITIAL_TEXT
41+
* BOT_INITIAL_SPEECH
42+
* UI_TOOLBAR_TITLE
43+
* UI_TOOLBAR_LOGO
44+
- Added a new `config` directory in the root of the repo that includes
45+
build configuration
46+
- Added a new `src` directory in the root of the repo to hold the
47+
website files. This includes a modified version of the iframe parent
48+
page and bot-loader that resides in the `lex-web-ui/static/iframe`
49+
directory. Eventualy, this new version should replace, somehow get
50+
merged with the other, or sourced in both places from a single file.
51+
- Added a `server.js` file for quick development and testing. It loads
52+
the sample page from the dist and source directories. It can be used
53+
with the command `npm start` from the root directory. You may need to put
54+
the right values in the config files under `src/config` to make it work.
55+
- Added CloudFormation format statement to all templates files
56+
- Added .npmignore file
57+
- Added sample code on how to use the Vue plugin for including the
58+
component into an existing Vue application
59+
60+
### Changed
61+
- **[BREAKING]** CloudFormation setup now defaults to not creating a
62+
development pipeline and just copy the prebuilt files to an S3 bucket.
63+
To use the pipeline, you now have to set the `CreatePipeline` parameter
64+
to true
65+
- Refactored the build scripts and Makefiles to have better separation
66+
of config and code. The config config used by the Makefiles now resides
67+
under: `config/env.mk`. Some of the names of the Makefile have changed so
68+
you may need to change your environment if you were using the Makefiles
69+
from other script.
70+
- The `update-lex-web-ui-config.js` build script now takes its config from
71+
a node js module in the `config` directory. The config is driven by the
72+
`BUILD_TYPE` environmental variable which controls whether the deployment
73+
is building the app from full source or using the dist dir. For this, the
74+
value of the `BUILD_TYPE` variable can be set to either `full` or `dist`.
75+
- Updated CodeBuild environment to node js v6.3.1 using ubuntu
76+
- Renamed iframe bot.css to bot-loader.css
77+
- Updated dependency versions
78+
- Clarified READMEs
79+
780
## [0.8.3] - 2017-07-29
881
### Changed
982
- Moved default icons from config to sample application

Makefile

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,101 @@
1-
# this Makefile is mainly meant to be called from CodeBuild
2-
# or to setup/run the local dev environment
3-
BUILD_DIR := build
1+
# This Makefile is used to configure and deploy the sample app.
2+
# It is used in CodeBuild by the CloudFormation stack.
3+
# It can also be run from a local dev environment.
4+
# It can either deploy a full build or use the prebuilt library in
5+
# in the dist directory
6+
7+
# environment file provides config parameters
8+
CONFIG_ENV := config/env.mk
9+
include $(CONFIG_ENV)
410

511
all: build
612
.PHONY: all
713

814
WEBAPP_DIR := ./lex-web-ui
9-
build: config
10-
@echo "[INFO] Building web app in dir [$(WEBAPP_DIR)]"
11-
cd $(WEBAPP_DIR) && npm run build
12-
.PHONY: build
13-
14-
dev: config
15-
@echo "[INFO] Running web app in dev mode"
16-
cd $(WEBAPP_DIR) && npm run dev
17-
.PHONY: dev
15+
BUILD_DIR := build
16+
DIST_DIR := dist
17+
SRC_DIR := src
18+
CONFIG_DIR := $(SRC_DIR)/config
19+
WEBSITE_DIR := $(SRC_DIR)/website
1820

19-
PACKAGE_JSON := $(WEBAPP_DIR)/package.json
20-
install-deps: $(PACKAGE_JSON)
21+
# this install all the npm dependencies needed to build from scratch
22+
install-deps:
2123
@echo "[INFO] Installing npm dependencies"
2224
cd $(WEBAPP_DIR) && npm install
23-
.PHONY: install
25+
.PHONY: install-deps
2426

27+
# BUILD_TYPE controls whether the configuration is done for a full build or
28+
# for using the prebuilt/dist libraries
29+
# Expected values: full || dist
30+
# If empty, probably this is being run locally or from an external script
31+
BUILD_TYPE ?= $()
32+
33+
# updates the config files with values from the environment
2534
UPDATE_CONFIG_SCRIPT := $(BUILD_DIR)/update-lex-web-ui-config.js
2635
export IFRAME_CONFIG ?= $(realpath $(WEBAPP_DIR)/static/iframe/config.json)
2736
export WEBAPP_CONFIG_PROD ?= $(realpath $(WEBAPP_DIR)/src/config/config.prod.json)
2837
export WEBAPP_CONFIG_DEV ?= $(realpath $(WEBAPP_DIR)/src/config/config.dev.json)
29-
CONFIG_FILES := $(IFRAME_CONFIG) $(WEBAPP_CONFIG_PROD) $(WEBAPP_CONFIG_DEV)
38+
export WEBAPP_CONFIG_PREBUILT ?= $(realpath $(SRC_DIR)/config/bot-config.json)
39+
export IFRAME_CONFIG_PREBUILT ?= $(realpath $(CONFIG_DIR)/bot-loader-config.json)
40+
CONFIG_FILES := $(IFRAME_CONFIG) $(WEBAPP_CONFIG_PROD) $(WEBAPP_CONFIG_DEV) \
41+
$(WEBAPP_CONFIG_PREBUILT) $(IFRAME_CONFIG_PREBUILT)
3042
config: $(UPDATE_CONFIG_SCRIPT) $(CONFIG_ENV) $(CONFIG_FILES)
3143
@echo "[INFO] Running config script: [$(<)]"
3244
node $(<)
3345
.PHONY: config
3446

35-
DIST_DIR := $(WEBAPP_DIR)/dist
36-
s3sync:
37-
@echo "[INFO] synching to S3 webapp bucket: [$(WEBAPP_BUCKET)]"
38-
aws s3 sync --acl public-read "$(DIST_DIR)" "s3://$(WEBAPP_BUCKET)/"
39-
.PHONY: s3sync
47+
build: config
48+
@echo "[INFO] Building web app in dir [$(WEBAPP_DIR)]"
49+
cd $(WEBAPP_DIR) && npm run build
50+
.PHONY: build
4051

41-
s3deploy:
52+
# used by the Pipeline deployment mode when building from scratch
53+
WEBAPP_DIST_DIR := $(WEBAPP_DIR)/dist
54+
CODEBUILD_BUILD_ID ?= none
55+
deploy-to-s3:
56+
@[ "$(WEBAPP_BUCKET)" ] || \
57+
(echo "[ERROR] WEBAPP_BUCKET env var not set" ; exit 1)
4258
@echo "[INFO] deploying to S3 webapp bucket: [$(WEBAPP_BUCKET)]"
4359
@echo "[INFO] copying build: [$(CODEBUILD_BUILD_ID)]"
44-
aws s3 cp --recursive "$(DIST_DIR)" \
60+
aws s3 cp --recursive "$(WEBAPP_DIST_DIR)" \
4561
"s3://$(WEBAPP_BUCKET)/builds/$(CODEBUILD_BUILD_ID)/"
4662
@echo "[INFO] copying new version"
4763
aws s3 cp --recursive --acl public-read \
4864
"s3://$(WEBAPP_BUCKET)/builds/$(CODEBUILD_BUILD_ID)/" \
4965
"s3://$(WEBAPP_BUCKET)/"
5066
@[ "$(PARENT_PAGE_BUCKET)" ] && \
5167
( echo "[INFO] synching parent page to bucket: [$(PARENT_PAGE_BUCKET)]" ; \
52-
aws s3 sync --acl public-read "$(DIST_DIR)/static/iframe" \
68+
aws s3 sync --acl public-read "$(WEBAPP_DIST_DIR)/static/iframe" \
5369
"s3://$(PARENT_PAGE_BUCKET)/static/iframe" ) || \
5470
echo "[INFO] no parent bucket to deploy"
5571
@echo "[INFO] all done deploying"
56-
.PHONY: s3deploy
72+
.PHONY: deploy-to-s3
73+
74+
# Run by CodeBuild deployment mode when which uses the prebuilt libraries
75+
# Can also be used to easily copy local changes to a bucket
76+
# (e.g. mobile hub created bucket)
77+
# It avoids overwriting the aws-config.js file when using outside of a build
78+
sync-website:
79+
@[ "$(WEBAPP_BUCKET)" ] || \
80+
(echo "[ERROR] WEBAPP_BUCKET variable not set" ; exit 1)
81+
@echo "[INFO] copying libary files"
82+
aws s3 sync --acl public-read \
83+
--exclude Makefile \
84+
--exclude lex-web-ui-mobile-hub.zip \
85+
$(DIST_DIR) s3://$(WEBAPP_BUCKET)
86+
@echo "[INFO] copying website files"
87+
aws s3 sync --acl public-read \
88+
$(WEBSITE_DIR) s3://$(WEBAPP_BUCKET)
89+
@echo "[INFO] copying config files"
90+
aws s3 sync --acl public-read \
91+
--exclude '*' \
92+
--include 'bot-*config.json' \
93+
$(CONFIG_DIR) s3://$(WEBAPP_BUCKET)
94+
@[ "$(BUILD_TYPE)" = 'dist' ] && \
95+
echo "[INFO] copying aws-config.js" ;\
96+
aws s3 sync --acl public-read \
97+
--exclude '*' \
98+
--include 'aws-config.js' \
99+
$(CONFIG_DIR) s3://$(WEBAPP_BUCKET)
100+
@echo "[INFO] all done deploying"
101+
.PHONY: sync-website

README.md

100644100755
Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,108 @@
33
> Sample Amazon Lex Web Interface
44
55
## Overview
6-
This repository provides a sample [Amazon Lex](https://aws.amazon.com/lex/)
7-
web interface that can be integrated in your website. This web interface
8-
allows to interact with a Lex bot directly from a browser using by text
9-
or voice (from a webRTC capable browser).
10-
Here is a screenshot of it:
6+
This is a sample [Amazon Lex](https://aws.amazon.com/lex/)
7+
web interface. It provides a chatbot UI component that can be integrated
8+
in your website. The interface allows to interact with a Lex bot directly
9+
from a browser using text or voice (on webRTC capable browsers).
1110

12-
<img src="./img/webapp-screenshot.png" width=480>
11+
## Quick Launch
12+
Click the button below to test drive this project using
13+
[AWS Mobile Hub](https://aws.amazon.com/mobile/).
14+
It will deploy the chatbot UI to
15+
[S3](https://aws.amazon.com/s3/) and
16+
[CloudFront](https://aws.amazon.com/cloudfront/). It also deploys
17+
the sample [Order Flowers Lex bot](http://docs.aws.amazon.com/lex/latest/dg/gs-bp-create-bot.html)
18+
automatically for you.
19+
20+
<p>
21+
<a target="_blank" href="https://console.aws.amazon.com/mobilehub/home?#/?config=https://github.com/awslabs/aws-lex-web-ui/blob/master/dist/lex-web-ui-mobile-hub.zip">
22+
<span>
23+
<img height="100%" src="https://s3.amazonaws.com/deploytomh/button-deploy-aws-mh.png"/>
24+
</span>
25+
</a>
26+
</p>
27+
28+
**NOTE**: If the Mobile Hub deployed site causes the browser to download
29+
the files instead of rendering it, you can re-upload the files to the
30+
S3 bucket using the S3 console or aws cli.
1331

1432
## Integrating into your Site
15-
You can consume this project as a library that renders the chatbot
16-
UI component in your site. The library can be included in your web
17-
application by importing it as a module in a
18-
[webpack](https://webpack.github.io/)
19-
based project or by directly sourcing it in an HTML `<script>` tag.
20-
Additionally, this project provides a set of
21-
[AWS CloudFormation](https://aws.amazon.com/cloudformation/) templates
22-
that can be used to automatically build and deploy the chatbot UI and
23-
related resources.
24-
25-
### Script Tag
26-
This project provides a pre-built version of the library under the
27-
[dist](dist) directory. You can copy the JavaScript and CSS files from
28-
that directory to your web server and use them to load the chatbot
29-
UI. Similarly, for quick testing, you could directly source the library
30-
and other dependencies from a CDN distribution.
31-
32-
You would need to pass required parameters such as the
33-
[Amazon Cognito Identity Pool](http://docs.aws.amazon.com/cognito/latest/developerguide/identity-pools.html) and Lex bot when you instantiate the
34-
component. See an example here: [index.html](dist/index.html).
33+
This project provides a sample page showing how to load the chatbot
34+
UI and related dependencies in a full page. There is also a sample
35+
page showing how to load the chatbot UI into an existing site
36+
using an iframe. These pages and their configuration can be
37+
automatically deployed using the Mobile Hub button above.
38+
39+
This project also provides a set of
40+
[AWS CloudFormation](https://aws.amazon.com/cloudformation/)
41+
templates that can be used to automatically build and deploy the chatbot
42+
UI and related resources. Additionally, you can consume this project as an
43+
[npm](https://www.npmjs.com/) package that provides a component library.
44+
45+
46+
### Full Page
47+
To display the chatbot UI as a full page, you can use the JavaScript
48+
and CSS files in the [dist](dist) directory. You can copy those files
49+
to your web server or host them in an S3 bucket. The JavaScript and CSS
50+
can be loaded in a web page by including them with `script` and `link`
51+
HTML tags.
52+
53+
<img src="./img/webapp-full.gif" width=600>
54+
55+
The chatbot UI component depends on libraries that should also be
56+
loaded in the page. For quick testing, you could directly source these
57+
dependencies from a CDN distribution. A sample page illustrating this
58+
setup is found in here: [index.html](src/website/index.html).
59+
60+
#### Configuration
61+
You need to pass the chatbot UI configuration including
62+
required parameters such as the [Amazon Cognito Identity
63+
Pool](http://docs.aws.amazon.com/cognito/latest/developerguide/identity-pools.html)
64+
and Lex bot name. The [index.html](src/website/index.html)
65+
sample page loads this configuration from the both the
66+
[bot-config.json](src/config/bot-config.json) and Mobile Hub AWS SDK
67+
[aws-config.js](src/config/aws-config.js) files. You can modify the values
68+
in those files to change the chatbot UI configuration. When deploying
69+
with Mobile Hub or with the CloudFormation templates described below,
70+
the configuration will be done automatically for you. For details about
71+
the component configuration, see the
72+
[Configuration and Customization](https://github.com/awslabs/aws-lex-web-ui/tree/master/lex-web-ui#configuration-and-customization)
73+
section of its README file.
74+
75+
#### Running Locally
76+
If you want to quickly test the [src/website](src/website) pages on
77+
your local host, modify the values in the `bot-config.json` and/or
78+
`aws-config.js` files under the `src/config` directory. Specifically,
79+
you would need to pass a Cognito Pool Id and Lex Bot name. If
80+
you deploy the site using Mobile Hub or CloudFormation, you can
81+
copy the configuration files from the S3 buckets automatically
82+
created in there. After you setup the configuration files in
83+
the `src/config` directory, issue the command: `npm start`. For
84+
a more advanced local host test, see the
85+
[Dependencies and Build Setup](https://github.com/awslabs/aws-lex-web-ui/tree/master/lex-web-ui#dependencies-and-build-setup)
86+
documentation of the component.
87+
88+
### Iframe
89+
You can embed the *Full Page* setup described above in an iframe to
90+
display it on your site as a chatbot widget. This project provides a
91+
sample page showing this setup here:
92+
[parent.html](src/website/parent.html). This includes a loader script
93+
that creates an API between the iframe and the parent page. For details,
94+
see its:
95+
[README](https://github.com/awslabs/aws-lex-web-ui/tree/master/lex-web-ui/static/iframe).
96+
97+
<img src="./img/webapp-iframe.gif" width=600>
3598

3699
### Npm Install
37100
You can use the [npm](https://docs.npmjs.com/)
38101
command to install this project. The npm install provides a library that
39-
you can import as a module into your JavaScript code.
102+
you can import as a module into your JavaScript code. The library can
103+
be npm installed in your web application and imported as a module in a
104+
[webpack](https://webpack.github.io/) based project. The component is
105+
built as a reusable [Vue.JS](https://vuejs.org/) plugin. The library
106+
bundle files are found under the [dist](dist) directory.
107+
40108

41109
Package installation using `npm`:
42110

@@ -55,6 +123,8 @@ You can then import the library in your project:
55123
import LexWebUi from 'aws-lex-web-ui';
56124
// or using require
57125
var LexWebUi = require('aws-lex-web-ui');
126+
// import the debug non-minimized version
127+
import LexWebUi from 'aws-lex-web-ui/dist/lex-web-ui';
58128
```
59129

60130
### CloudFormation Deployment
@@ -64,6 +134,7 @@ the accompanying [templates](templates) directory and its
64134

65135
## Details
66136
The source of the chatbot UI component resides under the
67-
[lex-web-ui](lex-web-ui) directory. The library provided here packages
68-
this component and distributes it as a pre-built library. For details
69-
about the chatbot UI component, see its [README](lex-web-ui/README.md)
137+
[lex-web-ui](lex-web-ui) directory. The library provided in the
138+
[dist](dist) directory packages this component and distributes it as
139+
a pre-built bundle. For details about the chatbot UI component and its
140+
configuration, see its [README](lex-web-ui/README.md) file.

build/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# This Makefile is used to update the bootstrap bucket containing
2+
# the project source and CloudFormation templates
3+
14
# environment file controls config parameters
2-
CONFIG_ENV := ./config.env
5+
CONFIG_ENV := ../config/env.mk
36
include $(CONFIG_ENV)
47

58
# cfn templates
@@ -31,6 +34,7 @@ upload-templates: $(TEMPLATES) | $(OUT)
3134
aws s3 sync --acl public-read --exclude "*" --include "*.yaml" \
3235
"$(TEMPLATES_DIR)" "s3://$(BOOTSTRAP_BUCKET_PATH)/templates/" \
3336
| tee "$(OUT)/$(@)"
37+
@echo "[INFO] master template: https://s3.amazonaws.com/$(BOOTSTRAP_BUCKET_PATH)/templates/master.yaml"
3438

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

0 commit comments

Comments
 (0)