Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

televisit-demo sendMessage from lambda assumeRole error #311

Open
stephen-tenorless opened this issue Apr 17, 2023 · 2 comments
Open

televisit-demo sendMessage from lambda assumeRole error #311

stephen-tenorless opened this issue Apr 17, 2023 · 2 comments

Comments

@stephen-tenorless
Copy link

the lambda is failing when trying to return the response from the lex bot

2023-04-15T02:49:28.972Z 0696baa3-3d05-49ad-9758-495f33defbdd INFO {
"message": "User: arn:aws:sts::xxxxxxxxxxx:assumed-role/chime-sdk-televisit-backend-LambdaKinesisRole-1OJU72XPACAFW/ChimeSDKTelevisitDemo-MessageModerator is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::xxxxxxxxxxxx:role/chime-sdk-televisit-backend-LambdaKinesisRole-1OJU72XPACAFW",
"code": "AccessDenied",
"time": "2023-04-15T02:49:28.972Z",
"requestId": "674469a9-db9f-4cf2-8ed8-7499a67805b5",
"statusCode": 403,
"retryable": false,
"retryDelay": 6.397304262170911
}

@Jgeissler14
Copy link

the sdk v1 has been deprecated, i got mine to work by changing the lambda code for ChimeAppInstanceLambda in the backend/template.yml to
ZipFile: >
"use strict";
const AWS = require("aws-sdk");
const { v4: uuidv4 } = require('uuid');
var response = require("cfn-response");
AWS.config.update({ region: process.env.AWS_REGION });
const chimeMessaging = new AWS.ChimeSDKMessaging({ region: process.env.AWS_REGION });
const chimeIdentity = new AWS.ChimeSDKIdentity({ region: process.env.AWS_REGION });
var chime_response;
var dateNow = new Date();

      exports.handler = async (event, context, callback) => {
        console.log("Event: \n", event);
        function sleep(ms) {
          return new Promise(resolve => setTimeout(resolve, ms));
        }
        if (event["RequestType"] === "Create") {
          console.log("Create Chime SDK App Instance");
          var params = {
            Name: `AWSChimeMessagingSDKDemo-${uuidv4()}`,
          };
          try {
            chime_response = await chimeIdentity.createAppInstance(
              params,
              function (err, data) {
                if (err) console.log(err, err.stack);
                // an error occurred
                else {
                  console.log(data); // successful response
                  return data;
                }
              }
            ).promise();
          } catch (error) {
            console.log("ERROR CAUGHT \n", error);
            await response.send(event, context, response.FAILED, {});
          }
        } else {
          console.log("Update Chime SDK App Instance");
          chime_response = {"AppInstanceArn": process.env.AppInstanceArn};
        }

        //Create AppInstanceAdmin
        try {
          var createUserParams = {
            AppInstanceArn: chime_response.AppInstanceArn, /* required */
            AppInstanceUserId: "ModeratorBot", /* required */
            ClientRequestToken: dateNow.getHours().toString() + dateNow.getMinutes().toString(), /* required */
            Name: "ModeratorBot", /* required */
          };
          await chimeIdentity.createAppInstanceUser(
            createUserParams,
            function (err, data) {
              if (err) console.log(err, err.stack); // an error occurred
              else {
                console.log(data);           // successful response
                chime_response.adminUserArn = data.AppInstanceUserArn;
              }
            }
          ).promise();
          var createAdminParams = {
            AppInstanceAdminArn: chime_response.adminUserArn, /* required */
            AppInstanceArn: chime_response.AppInstanceArn /* required */
          };
          await chimeIdentity.createAppInstanceAdmin(
            createAdminParams,
            function (err, data) {
              if (err) console.log(err, err.stack); // an error occurred
              else {
                console.log(data);           // successful response
              }
            }
          ).promise();
        } catch (error) {
          console.log("ERROR CAUGHT \n", error);
          await response.send(event, context, response.FAILED, {});
        }

        //Configure data streaming feature
        async function putStreamConfig(maxAttempts, retryTimeout) {
          if (maxAttempts > 0) {
            try {
              await sleep(retryTimeout);
              var streaminConfigurationParams = {
                AppInstanceArn: chime_response.AppInstanceArn, /* required */
                StreamingConfigurations: [ /* required */
                  {
                    DataType: "ChannelMessage", /* required */
                    ResourceArn: event.ResourceProperties.KinesisStreamArn /* required */
                  },
                  /* more items */
                ]
              };
              await chimeMessaging.putMessagingStreamingConfigurations(
                streaminConfigurationParams,
                function (err, data) {
                  if (err) console.log(err, err.stack); // an error occurred
                  else {
                    console.log(data);           // successful response
                  }
                }
              ).promise();
            } catch (error) {
                console.log("ERROR CAUGHT \n", error);
                await putStreamConfig(maxAttempts - 1, retryTimeout);
            }
          } else {
              console.log("Max retry reached.");
              await response.send(event, context, response.FAILED, {});
          }
        }
        await putStreamConfig(30, 10000);
        await response.send(event, context, response.SUCCESS, chime_response);
      };

@Jgeissler14
Copy link

@stephen-tenorless the solution above should fix your deployment, however i am still running into dependency issues in the frontend with npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants