Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

putBotAlias not working in AWS LexModelBuildingService node.js

I've been trying to replace the existing LexBot Alias(named LATEST) with a newly created bot version.

Now, according to aws documentation

When you want to update a bot alias, set the checksum field to the checksum of the most recent revision of the $LATEST version.

I can see the Alias LATEST is using bot version 12 in the Lex Console.

I have tried getting the checksum using the following (I am using getBot(...) of LexModelBuildingService to get checksum of the bot):

  • using Alias name itself as version i.e. LATEST.
  • setting versionOrAlias in getBot method params as '$LATEST'.
  • Hardcoding the version to 12in getBot(..).

I have used checksum from the above scenarios, but the error seems to be same as

PreconditionFailedException: The checksum value doesn't match for the resource named 'LATEST'.

Here's code snippet

   async putBotAlias(botVersionResponse){
        let checksum;
        await this.getBot(botVersionResponse.name,'12').then(botRes=>{ // have used 12, LATEST, $LATEST with same error
            console.log("Checksum For Latest: " + botRes.checksum);
            checksum = botRes.checksum;
        });

        var params = {
            botName: botVersionResponse.name, 
            botVersion: (parseInt(botVersionResponse.version,10)).toString(), 
            name: 'LATEST', 
            checksum : checksum
          };
// checksum: checksum
          console.log("Params in putBotAlias : " + JSON.stringify(params));

          return new Promise((resolve,reject)=>{
            this.modelBuildingService.putBotAlias(params, function(err, data) {
                if (err){
                    reject(err);
                }  // an error occurred
                else{
                    console.log("Put Alias Response :::" +  JSON.stringify(data)); 
                    resolve(data);
                }               // successful response
              });
          });

    }

I am really at lost here as to what version exactly it wants.

Any help is greatly appreciated.

PS: Please mention any additional required information in comments.

like image 761
Salim Shamim Avatar asked Oct 27 '22 15:10

Salim Shamim


1 Answers

Apparantly I was putting checksum of 'Bot' and not of the 'BotAlias' which I was trying to put.

Updated code gets the checksum of bot Alias :

 async putBotAlias(botVersionResponse,aliasName){
        let checksum;
        if(typeof aliasName != "undefined"){
            await this.getBotAlias(botVersionResponse.name,aliasName).then(res=>{ 
                console.log("Checksum For Latest ALIAS : " + res.checksum);
                checksum = res.checksum;
            }).catch((err)=>{
                console.log(" Unable to getBotAlias checksum " + err);
            });
        }

Silly mistake, but hope it helps anyone making it. :)

like image 90
Salim Shamim Avatar answered Nov 09 '22 15:11

Salim Shamim