aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.12k stars 579 forks source link

(Question) How do I use this SDK with lex? #2519

Closed smac89 closed 3 years ago

smac89 commented 3 years ago

In the aws console page for lex, I see that the url contains lexv2. So my question is, can I use the v3 of this SDK to communicate with lex? If so, can someone show an example?

I am trying to use lex in a react app (running on localhost), so I set it up this way:

const lexClient = new LexRuntimeServiceClient({
    region: REGION,
    requestHandler: new FetchHttpHandler({
        requestTimeout: 2000,
    }),
    credentials: fromCognitoIdentityPool({
        client: new CognitoIdentityClient({region: REGION}),
        identityPoolId: POOL_ID,
    }),
});

Then to use it, I do:

this.lexClient.send(new PostTextCommand({
    requestAttributes: {
        "x-amz-lex:time-zone": this.userTimezone
    },
    botAlias: BOT_ALIAS,
    botName: BOT_NAME,
    inputText: message,
    userId: `chatbot-demo-${this.user}`,
}))

However the request fails with some strange errors. Here is a screenshot of FF dev console: (The grayed out parts are just the region) Screenshot_20210625_084153

What am I doing wrong here? Is it a problem with my setup? I need some help! Thanks

smac89 commented 3 years ago

Yea it looks like indeed the LexRuntimeServiceClient from v3 is not compatible with lexv2. I am now using "@aws-sdk/client-lex-runtime-v2@3.19.0", and now I no longer get that error.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.