brefphp / laravel-bridge

Package to use Laravel on AWS Lambda with Bref
https://bref.sh/docs/frameworks/laravel.html
MIT License
325 stars 64 forks source link

SQS Session token is stored only in default connection #155

Closed giagara closed 4 months ago

giagara commented 4 months ago

I have multiple connection in my queue.php config file like:

'sqs' => [
          'driver' => 'sqs',
          'key' => env('AWS_ACCESS_KEY_ID'),
          'secret' => env('AWS_SECRET_ACCESS_KEY'),
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE', 'default'),
          'suffix' => env('SQS_SUFFIX'),
          'region' => env('AWS_DEFAULT_REGION', 'eu-west-1'),
          'after_commit' => false,
          'endpoint' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
],

'another-queue' => [
          'driver' => 'sqs',
          'key' => env('AWS_ACCESS_KEY_ID'),
          'secret' => env('AWS_SECRET_ACCESS_KEY'),
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE_ANOTHER_QUEUE', 'another-queue'),
          'suffix' => env('SQS_SUFFIX'),
          'region' => env('AWS_DEFAULT_REGION', 'eu-west-1'),
          'after_commit' => false,
          'endpoint' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
],

in my code i execute something like

Queue::pushRaw(json_encode(....));

Queue::connection('another-queue')->pushRaw(json_encode(....));

The default queue is working and the "other" returns: {"__type":"com.amazon.coral.service#UnrecognizedClientException","message":"The security token included in the request i (truncated...): The security token included in the request is invalid

From what i can debug i see that the "other" configuration is missing the AWS_SESSION_TOKEN stored in the token property of the connection's config. I think this is related to this: https://github.com/brefphp/laravel-bridge/blob/1dd21c63c3b14a12b4a73bb79fbc2854d2556349/src/BrefServiceProvider.php#L50

Have i to set the AWS_SESSION_TOKEN in a custom ServiceProvider? Like:

Config::set('queue.connections.another-queue.token', env('AWS_SESSION_TOKEN'));

I didn't see anything in the doc related to a custom sqs connection.

deleugpn commented 4 months ago

I recommend you trim your configuration like this:

'sqs' => [
          'driver' => 'sqs',
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE', 'default'),
          'suffix' => env('SQS_SUFFIX'),
          'after_commit' => false,
],

'another-queue' => [
          'driver' => 'sqs',
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE_ANOTHER_QUEUE', 'another-queue'),
          'suffix' => env('SQS_SUFFIX'),
          'after_commit' => false,
],

I would even go one step further and remove prefix and suffix in favor of having everything in queue

giagara commented 4 months ago

I recommend you trim your configuration like this:

'sqs' => [
          'driver' => 'sqs',
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE', 'default'),
          'suffix' => env('SQS_SUFFIX'),
          'after_commit' => false,
],

'another-queue' => [
          'driver' => 'sqs',
          'prefix' => env('SQS_PREFIX', 'https://sqs.eu-west-1.amazonaws.com/your-account-id'),
          'queue' => env('SQS_QUEUE_ANOTHER_QUEUE', 'another-queue'),
          'suffix' => env('SQS_SUFFIX'),
          'after_commit' => false,
],

I would even go one step further and remove prefix and suffix in favor of having everything in queue

I copied it from the dev env where I have all parameters. Anyway, that's not concern to the issue I've got.

giagara commented 4 months ago

Apparently to achieve this you have to set it in a ServiceProvider (or whatever you want):

Config::set('queue.connections.<queue-connection>.token', env('AWS_SESSION_TOKEN'));

I'm creating a PR to the docs to explain it.