

End of support notice: On September 15, 2025, AWS will discontinue support for Amazon Lex V1. After September 15, 2025, you will no longer be able to access the Amazon Lex V1 console or Amazon Lex V1 resources. If you are using Amazon Lex V2, refer to the [Amazon Lex V2 guide](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html) instead. . 

# Exercise 4: Publish a Version (AWS CLI)
<a name="gs-cli-publish"></a>

Now, create a version of the bot that you created in Exercise 1. A *version* is a snapshot of the bot. After you create a version, you can’t change it. The only version of a bot that you can update is the `$LATEST` version. For more information about versions, see [Versioning and Aliases](versioning-aliases.md). 

Before you can publish a version of a bot, you must publish the intents that is uses. Likewise, you must publish the slot types that those intents refer to. In general, to publish a version of a bot, you do the following:

1. Publish a version of a slot type with the [CreateSlotTypeVersion](API_CreateSlotTypeVersion.md) operation.

1. Publish a version of an intent with the [CreateIntentVersion](API_CreateIntentVersion.md) operation.

1. Publish a version of a bot with the [CreateBotVersion](API_CreateBotVersion.md) operation .

To run the commands in this exercise, you need to know the region where the commands will be run. For a list of regions, see [Model Building Quotas](gl-limits.md#gl-limits-model-building).

**Topics**
+ [Step 1: Publish the Slot Type (AWS CLI)](gs-cli-publish-slot-type.md)
+ [Step 2: Publish the Intent (AWS CLI)](gs-cli-publish-intent.md)
+ [Step 3: Publish the Bot (AWS CLI)](gs-cli-publish-bot.md)

# Step 1: Publish the Slot Type (AWS CLI)
<a name="gs-cli-publish-slot-type"></a>

Before you can publish a version of any intents that use a slot type, you must publish a version of that slot type. In this case, you publish the `FlowerTypes` slot type. 

**Note**  
The following AWS CLI example is formatted for Unix, Linux, and macOS. For Windows, change `"\$LATEST"` to `$LATEST` and replace the backslash (\$1) continuation character at the end of each line with a caret (^).

**To publish a slot type (AWS CLI)**

1. In the AWS CLI, get the latest version of the slot type:

   ```
   aws lex-models get-slot-type \
       --region region \
       --name FlowerTypes \
       --slot-type-version "\$LATEST"
   ```

   The response from Amazon Lex follows. Record the checksum for the current revision of the `$LATEST` version.

   ```
   {
       "enumerationValues": [
           {
               "value": "tulips"
           }, 
           {
               "value": "lilies"
           }, 
           {
               "value": "roses"
           }
       ], 
       "name": "FlowerTypes", 
       "checksum": "checksum", 
       "version": "$LATEST", 
       "lastUpdatedDate": timestamp, 
       "createdDate": timestamp, 
       "description": "Types of flowers to pick up"
   }
   ```

1. Publish a version of the slot type. Use the checksum that you recorded in the previous step.

   ```
   aws lex-models create-slot-type-version \
       --region region \
       --name FlowerTypes \
       --checksum "checksum"
   ```

   The response from Amazon Lex follows. Record the version number for the next step.

   ```
   {
       "version": "1", 
       "enumerationValues": [
           {
               "value": "tulips"
           }, 
           {
               "value": "lilies"
           }, 
           {
               "value": "roses"
           }
       ], 
       "name": "FlowerTypes", 
       "createdDate": timestamp, 
       "lastUpdatedDate": timestamp, 
       "description": "Types of flowers to pick up"
   }
   ```

## Next Step
<a name="gs-cli-publish-2"></a>

[Step 2: Publish the Intent (AWS CLI)](gs-cli-publish-intent.md)

# Step 2: Publish the Intent (AWS CLI)
<a name="gs-cli-publish-intent"></a>

Before you can publish an intent, you have to publish all of the slot types referred to by the intent. The slot types must be numbered versions, not the `$LATEST` version.

First, update the `OrderFlowers` intent to use the version of the `FlowerTypes` slot type that you published in the previous step. Then publish a new version of the `OrderFlowers` intent.

**Note**  
The following AWS CLI example is formatted for Unix, Linux, and macOS. For Windows, change `"\$LATEST"` to `$LATEST` and replace the backslash (\$1) continuation character at the end of each line with a caret (^).

**To publish a version of an intent (AWS CLI)**

1. In the AWS CLI, get the `$LATEST` version of the `OrderFlowers` intent and save it to a file:

   ```
   aws lex-models get-intent \
       --region region \
       --name OrderFlowers \
       --intent-version "\$LATEST" > OrderFlowers_V4.json
   ```

1. In a text editor, open the **OrderFlowers\$1V4.json** file. Delete the `createdDate`, `lastUpdatedDate`, and `version` fields. Find the `FlowerTypes` slot type and change the version to the version number that you recorded in the previous step. The following fragment of the **OrderFlowers\$1V4.json** file shows the location of the change:

   ```
           {
               "slotType": "FlowerTypes", 
               "name": "FlowerType", 
               "slotConstraint": "Required", 
               "valueElicitationPrompt": {
                   "maxAttempts": 2, 
                   "messages": [
                       {
                           "content": "What type of flowers?", 
                           "contentType": "PlainText"
                       }
                   ]
               }, 
               "priority": 1, 
               "slotTypeVersion": "version", 
               "sampleUtterances": []
           },
   ```

1. In the AWS CLI, save the revision of the intent:

   ```
   aws lex-models put-intent \
       --name OrderFlowers \
       --cli-input-json file://OrderFlowers_V4.json
   ```

1. Get the checksum of the latest revision of the intent:

   ```
   aws lex-models get-intent \
       --region region \
       --name OrderFlowers \
       --intent-version "\$LATEST" > OrderFlowers_V4a.json
   ```

   The following fragment of the response shows the checksum of the intent. Record this for the next step.

   ```
       "name": "OrderFlowers", 
       "checksum": "checksum", 
       "version": "$LATEST",
   ```

1. Publish a new version of the intent: 

   ```
   aws lex-models create-intent-version \
       --region region \
       --name OrderFlowers \
       --checksum "checksum"
   ```

   The following fragment of the response shows the new version of the intent. Record the version number for the next step.

   ```
       "name": "OrderFlowers", 
       "checksum": "checksum", 
       "version": "version",
   ```

## Next Step
<a name="gs-cli-publish-3"></a>

[Step 3: Publish the Bot (AWS CLI)](gs-cli-publish-bot.md)

# Step 3: Publish the Bot (AWS CLI)
<a name="gs-cli-publish-bot"></a>

After you have published all of the slot types and intents that are used by your bot, you can publish the bot.

Update the `OrderFlowersBot` bot to use the `OrderFlowers` intent that you updated in the previous step. Then, publish a new version of the `OrderFlowersBot` bot.

**Note**  
The following AWS CLI example is formatted for Unix, Linux, and macOS. For Windows, change `"\$LATEST"` to `$LATEST` and replace the backslash (\$1) continuation character at the end of each line with a caret (^).

**To publish a version of a bot (AWS CLI)**

1. In the AWS CLI, get the `$LATEST` version of the `OrderFlowersBot` bot and save it to a file:

   ```
   aws lex-models get-bot \
       --region region \
       --name OrderFlowersBot \
       --version-or-alias "\$LATEST" > OrderFlowersBot_V4.json
   ```

1. In a text editor, open the **OrderFlowersBot\$1V4.json** file. Delete the `createdDate`, `lastUpdatedDate`, `status` and `version` fields. Find the `OrderFlowers` intent and change the version to the version number that you recorded in the previous step. The following fragment of **OrderFlowersBot\$1V4.json** shows the location of the change.

   ```
       "intents": [
           {
               "intentVersion": "version", 
               "intentName": "OrderFlowers"
           }
   ```

1. In the AWS CLI, save the new revision of the bot. Make note of the version number returned by the call to `put-bot`.

   ```
   aws lex-models put-bot \
       --name OrderFlowersBot \
       --cli-input-json file://OrderFlowersBot_V4.json
   ```

1. Get the checksum of the latest revision of the bot. Use the version number returned in step 3.

   ```
   aws lex-models get-bot \
       --region region \
       --version-or-alias version \
       --name OrderFlowersBot > OrderFlowersBot_V4a.json
   ```

   The following fragment of the response shows the checksum of the bot. Record this for the next step.

   ```
       "name": "OrderFlowersBot", 
       "locale": "en-US", 
       "checksum": "checksum",
   ```

1. Publish a new version of the bot:

   ```
   aws lex-models create-bot-version \
       --region region \
       --name OrderFlowersBot \
       --checksum "checksum"
   ```

   The following fragment of the response shows the new version of the bot.

   ```
       "checksum": "checksum", 
       "abortStatement": {
           ...
       }, 
       "version": "1",
       "lastUpdatedDate": timestamp,
   ```

## Next Step
<a name="gs-cli-next-exercise-5"></a>

[Exercise 5: Create an Alias (AWS CLI)](gs-cli-create-alias.md)