Amazon Lex Migration Utility
Deprecation notice
2022-03-28
This project is no longer supported. AWS has announced Lex V2 with a new set of APIs and new functionality.
Purpose
The Amazon Lex Migration Utility allows you to easily migrate Amazon Lex Chatbots between accounts.
The Lex Migration Utility consists of a Python script that exports Lex definitions to an AWS CloudFormation template and three custom resources to create bots, Intents, and slots
Installation
Install the Serverless Application Model
Install AWS CloudFormation custom resources in the target account
sam build -t custom_resource_template.yml
sam package --output-template-file custom-resources-sam-template.yml --resolve-s3
sam deploy --template-file custom-resources-sam-template.yml --stack-name lex-custom-resources --capabilities "CAPABILITY_NAMED_IAM"
Usage
Create a configuration file
{
"ResourceFilters":
{
"SlotTypes":["FlowerType","PickupDate","PickupTime"],
"Intents":["OrderFlowers"],
"Bots":["OrderFlowers"]
},
"Output":{
"Filename": "order-flowers-template.json",
"TemplateDescription":"Creates resources needed for the OrderFlowers Sample "
}
}
ResourceFilters
allow you to choose which bots, intents, and slots get exported. Any resources which contain the specified values as part of their name will be exported.
Output
Filename
the name of the exported template
TemplateDescription
Populates the Description
field of the CloudFormation template
Export Lex definitions from the source account
Prerequisites
Python 3.x and Node 12.x
The Amazon Lex Migration Utility requires Python 3.x and Node 12.x
Configure the AWS CLI with a profile for the source account
The easiest method to export the definition is to create a named profile for the source_account:
aws configure --profile <source_account>
Install dependencies
pip install --requirements requirements.txt #installs dependencies. This only needs to be run the first time.
Export resources
Then from the destination account:
python3 ./lex_exporter/create_lex_template.py --config-file <configuration file> [--profile <source account>]
Deploy to the destination account
sam deploy --template-file <output template> --stack-name <stack name> --resolve-s3 --capabilities "CAPABILITY_NAMED_IAM"
Custom Resources created
Each custom resource wraps the corresponding API.
- CFNBot - Creates an Amazon Lex Bot
- CFNIntentLex - Creates a Lex Intent
- CFNSlotLex - Creates a Lex Slot
- CFNBotLexAlias - Creates a Lex Alias
- CFNConnectAssociateLex - Associates a Lex Bot to am Amazon Connect instance.
Sample configuration file and template
The sample configuration file and the order-flowers-template.json
corresponds to the Amazon Lex bots created when you install
Lex Web UI.
After installing Lex Web UI, you can export the LexBots by running:
python3 ./lex_exporter/create_lex_template.py --config-file ./lex_exporter/example-configuration.json
Known Issues
- Deleting a stack with custom Lex resources does not always delete cleanly. If the custom resource returns a "Conflict Exception". Keep trying to delete the stack. The lex exporter scripts works around this by adding a DependsOn constraint to each resource to force CloudFormation to create and delete synchronously instead of in parallel.
Acknowledgements
The Lex bot, intent, and slot custom resources used by the Amazon Lex Migration Utility are slightly modified forks of work done by Andrew Templeton