15

I have created my lex bot and published it. I am now trying to test it out from a rest client.

The idea is once working from rest client ,i can integrate this with my custom UI using rest calls.

enter image description here

I am using this request body from posttext as per this link http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html

When i am using this from rest client i am getting Missing Authentication Token.

enter image description here

The end point url used is https://runtime.lex.us-east-1.amazonaws.com

Should i add something in the authorization header like AWS Signature or something else to make this work.

lost Coder
  • 577
  • 2
  • 8
  • 34
  • 1
    Did you check out [Authentication and Access Control for Amazon Lex](http://docs.aws.amazon.com/lex/latest/dg/auth-and-access-control.html)? – Michael - sqlbot Jul 04 '17 at 16:24

1 Answers1

12

You need to include an AWS Signature in the Authorization tab, containing the details of an IAM user that has access to run your Lex bot.

Steps: 1. In AWS go to IAM -> Users -> Add User

enter image description here

  1. Give it a Username like "myBotUser" and select an Access Type of "Programmatic access". Hit Next:Permissions.

enter image description here

  1. Hit Create Group to create a group to give permissions to the user.

enter image description here

  1. Give it a name and then filter the policies for Lex - and select "AmazonLexReadOnly" and "AmazonLexRunBotsOnly".

enter image description here

Hit Create Group.

  1. Then hit "Next: Review".
  2. Then hit "Create User" - and your IAM user is ready. You'll see an Access key ID and a Secret Access Key.

  3. In Postman, in Authorization, select AWS Signature and enter in the Access key ID and the Secret Access Key, along with an AWS Region of "us-east-1" and a Service Name of "lex":

enter image description here

  1. Make sure you're body is as required (here I'm just sending text):

enter image description here

Hit Send and you should get a response like this:

{
    "dialogState": "Fulfilled",
    "intentName": "yourIntentName",
    "message": "A response for that intent",
    "responseCard": null,
    "sessionAttributes": {},
    "slotToElicit": null,
    "slots": {}
}

Update

Note also - the POST url would be in format:

https://runtime.lex.us-east-1.amazonaws.com/bot/MyBotName/alias/myMyAlias/user/aUniqueUserID/text and it should be a POST

Also make sure the header Content-Type is application/json, as is the body.

AndyOS
  • 3,607
  • 3
  • 23
  • 31
  • Did all this . i am getting this error "Error while sending request:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'runtime.lex.us-east-1.amazonaws.com' is not a valid http header field value" . Is this because the endpoint url is not correct? I f so what should be the right url to call a published lex bot having bot name and alias name. – lost Coder Jul 12 '17 at 10:55
  • i am using the same.. i have added the screen shot in the question – lost Coder Jul 12 '17 at 11:48
  • { "inputText": "i want to raise a ticket", "sessionAttributes": { "string" : "string" } } – lost Coder Jul 12 '17 at 11:58
  • the request is not going i guess – lost Coder Jul 12 '17 at 11:59
  • Hmm. Can you post the postman json of the request (just remove the keys if they're in it) – AndyOS Jul 12 '17 at 12:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149002/discussion-between-lost-coder-and-andyos). – lost Coder Jul 12 '17 at 12:40
  • POST /bot/test/alias/lexTestChat/user/unique123r/text HTTP/1.1 Content-Type: application/json Host: runtime.lex.us-east-1.amazonaws.com​ X-Amz-Date: 20170712T123140Z Authorization: AWS4-HMAC-SHA256 Credential=xxxxxxxxxx/20170712/us-east-1/lex/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Cache-Control: no-cache Postman-Token: 46f48b78-ab05-1f1b-5f37-bceb4e02dc9e { "inputText": "i want to raise a ticket", "sessionAttributes": { "string" : "string" } } – lost Coder Jul 12 '17 at 15:24
  • is there anything specific in user we have to give or can it be any random value ? – lost Coder Jul 12 '17 at 15:25
  • See the chat discussion – AndyOS Jul 12 '17 at 15:42
  • Check the chat, I've posted json for postman that should work – AndyOS Jul 14 '17 at 08:17