Skip to content
On this page

Separation of concerns

Right now, we have our application code for Lex UI together with our Infrastructure-as-Code. While this may be ok for a small application, this may cause issues down the road. For example, you want to avoid unnecessarily triggering your Terraform pipelines because of updates to application code, etc.

Seperate Lex UI

Remove Lex UI source code from your Infrastructure-as-Code by running the following command:

rm -rf src/aws-lex-web-ui

Clone the repository to use for UI in another location on your machine:

git clone
git checkout lesson-1

cp config/example.env.js config/env.js

Obtain the poolId by running:

terraform console
  1. Update config/env.js


// ...
  AWS_REGION: '"us-east-1"',
  POOLID: '"us-east-1:746dx87b-0fac-4560-bba5-47c2a3467ff6"',
  BOT_NAME: '"Classifieds"',
// ...
  1. Install dependencies npm install

  2. Serve with hot reload at localhost:8080 npm run dev

Navigating to the dev URL, you will see your UI and will be able to interact with your chatbot.

lex ui

Terraform Output Values

Earlier, we used Terraform console to get the poolId. What if you want to get a bunch of resource properties at once? It would be tedious to run each one by one in the console. An alternative is to use Output values. Output values make information about your infrastructure available on the command line. Additionally, Output values can expose information for other Terraform configurations to use. Output values are similar to return values in a programming language.

Declare Output Values

To export Output values, they must be declared using an output block.

Create a file in the root of your Terraform project and add the following:

output "cognito_identity_pool_id" {
  value =


It's worth noting that Outputs will only be rendered when Terraform applies a plan. So running terraform plan will not render outputs.

Too see the outputs run terraform destroy first.

Then run terraform apply -auto-approve.

You should see the following, with cognito_identity_pool_id in the outputs.

aws_lex_bot.classifieds: Still creating... [10s elapsed]
aws_lex_bot.classifieds: Creation complete after 14s [id=Classifieds]

Apply complete! Resources: 20 added, 0 changed, 0 destroyed.


cognito_identity_pool_id = "us-east-1:ec1bbb2a-8345-4f3b-af99-dbdc607ac50d"