ssut / nestjs-sqs

A project to make SQS easier to use within NestJS, with decorator-based handling and seamless NestJS-way integration.
MIT License
214 stars 53 forks source link

InvalidClientTokenId error after upgrading to 2.0.0 locally. #49

Open egimenos opened 1 year ago

egimenos commented 1 year ago

So basically that, everything worked fine in 1.2.x. I am using Localstack, which should not make any difference, and I'm loading the credentials and config from aws CLI files.

If I try to upgrade to 2.0.0 then I get this error in the method receiveMessage of the consumer.js file from sqs-consumer

InvalidClientTokenId: The security token included in the request is invalid.

If I go to consumer.js and try to log region and credentials I got his which looks as expected:

console.log({region: this.sqs.config.region(), credentials: await this.sqs.config.credentials()})


{
  region: Promise { 'eu-central-1' },
  credentials: { accessKeyId: 'dummy', secretAccessKey: 'dummy' }
}

Any idea on what might be happening? As I said this setup was working fine in 1.2.x and according to the docs no further configuration needs to be done if I'm not wrong.

egimenos commented 1 year ago

Just in case someone has the same problem, the credentials were fine, the problem was that I needed to explicitly set the endpoint to trigger Localstack. As I said this was not necessary before because the endpoint is included in sqs queue url, but I think this is something related to the sqs-consumer library that nestjs-sqs uses under the hood.

So now in development environment I need to pass a sqs client defining the endpoint as part of the SqsConsumerOptions

This is an example:

 {
    name: '...',
    queueUrl: '...',
    region:  '...'
    sqs: new SQSClient({
      endpoint: 'http://localhost:4566',
    })

  }
rmogio-encora commented 1 year ago

@egimenos Thank you a lot for that! I was struggling to get rid of this error. I do think that this should be place somewhere on the documentation for this library.