0

I am using aws-sdk/clients/chimesdkmessaging to make requests to get/delete/send channel messages.

But the issue is that the temporary credentials are expired after 1 hour and I cannot use the services without renewing the credentials. I am able to renew them, but couldn't set them in the API Request header.

I tried to set the request header as :

request.httpRequest.headers["x-amz-security-token"] = NEW_TOKEN

But it didn't work. Also, I couldn't find anything on adding a middleware to these API's.

Here's my code

 const ChimeMessaging = require("aws-sdk/clients/chimesdkmessaging");

 const chimeMessaging = new ChimeMessaging();

 async function sendChannelMessage(
      channelArn,
      messageContent,
      persistence,
      type,
      member,
      options = null
 ) {
    const chimeBearerArn = createMemberArn(member.userId);

    const params = {
     ChimeBearer: chimeBearerArn,
     ChannelArn: channelArn,
     Content: messageContent,
     Persistence: persistence, // Allowed types are PERSISTENT and NON_PERSISTENT
     Type: type,
    };
   const request = (await chimeMessagingClient()).sendChannelMessage(params)

  request.on("complete", function (err, data) {
     request.httpRequest.headers["x-amz-security-token"] = NEW_TOKEN
  });
  const response = await request.promise();
  const sentMessage = {
     response: response,
     CreatedTimestamp: new Date(),
     Sender: { Arn: createMemberArn(member.userId), Name: member.username },
   };
 return sentMessage;
}
Sangeet
  • 145
  • 3
  • 9

0 Answers0