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

MIGRATION ISSUE: SQS client send message on mutiple regions #5812

Closed
4 of 5 tasks
lepirlouit opened this issue Feb 19, 2024 · 4 comments
Closed
4 of 5 tasks

MIGRATION ISSUE: SQS client send message on mutiple regions #5812

lepirlouit opened this issue Feb 19, 2024 · 4 comments
Labels
closed-for-staleness guidance General information and guidance, answers to FAQs, or recommended best practices/resources. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. v2-v3-inconsistency Behavior has changed from v2 to v3, or feature is missing altogether

Comments

@lepirlouit
Copy link

lepirlouit commented Feb 19, 2024

Pre-Migration Checklist

Which JavaScript Runtime is this issue in?

Node.js (includes AWS Lambda)

AWS Lambda Usage

  • Yes, my application is running on AWS Lambda.
  • No, my application is not running on AWS Lambda.

Describe the Migration Issue

One of my lambda is sending messages on mutiples queues that could be in different regions
with sdk v2 I was able to init the client in one region and queue region was get from the url

Code Comparison

const { SQS } = require("@aws-sdk/client-sqs");
const AWS = require('aws-sdk');
const sqsV2 = new AWS.SQS({region: "eu-central-1"});
const sqsV3 = new SQS({region: "eu-central-1"});


const queuesURLs = [
  'https://sqs.eu-central-1.amazonaws.com/{AWS_ACCOUNT}/oneQueue',
  "https://sqs.eu-west-1.amazonaws.com/{AWS_ACCOUNT}/anotherQueue",
];

(async () => { 
  for (const queueURL of queuesURLs) { 
    const params = {
      "MessageBody": "Dummy Message",
      QueueUrl: queueURL,
    };
    // await sqsV2.sendMessage(params).promise();
    // await sqsV3.sendMessage(params);
  }

})();

Observed Differences/Errors

  • QueueUrl=https://sqs.eu-west-1.amazonaws.com/{aws_account}/anotherQueue differs from SQSClient resolved endpoint=https://sqs.eu-central-1.amazonaws.com/, using QueueUrl host as endpoint.
  • "SignatureDoesNotMatch: Credential should be scoped to a valid region."

with param useQueueUrlAsEndpoint I got The specified queue does not exist or you do not have access to it

Additional Context

No response

@lepirlouit lepirlouit added needs-triage This issue or PR still needs to be triaged. v2-v3-inconsistency Behavior has changed from v2 to v3, or feature is missing altogether labels Feb 19, 2024
@lepirlouit
Copy link
Author

in v2 endpoint and region is set from QueueUrl

https://github.com/aws/aws-sdk-js/blob/master/lib/services/sqs.js#L127-L128

@kuhe
Copy link
Contributor

kuhe commented Feb 19, 2024

You should use one client per region in v3.

import { SQS } from "@aws-sdk/client-sqs";

const sqsClients = {
  "eu-central-1": new SQS({ region: "eu-central-1" }),
  "eu-west-1": new SQS({ region: "eu-west-1" }),
};

const queues = [
  { region: "eu-central-1", url: "https://sqs.eu-central-1.amazonaws.com/{AWS_ACCOUNT}/oneQueue" },
  { region: "eu-west-1", url: "https://sqs.eu-west-1.amazonaws.com/{AWS_ACCOUNT}/anotherQueue" },
];

for (const { region, url } of queues) {
  const params = {
    MessageBody: "Dummy Message",
    QueueUrl: url,
  };
  await sqsClients[region].sendMessage(params);
}

The v2 behavior was a customization that we don't want to keep supporting for consistency among SDK clients and because region is meant to be initialized at the client level and not changed between requests.

Although it is technically possible to read the region from the standard SQS endpoints, we do not want to attempt to do that because the QueueUrl may deviate from the standard public endpoint.

@kuhe kuhe added the guidance General information and guidance, answers to FAQs, or recommended best practices/resources. label Feb 19, 2024
@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 19, 2024
Copy link

github-actions bot commented Mar 1, 2024

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Mar 1, 2024
@github-actions github-actions bot closed this as completed Mar 6, 2024
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness guidance General information and guidance, answers to FAQs, or recommended best practices/resources. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. v2-v3-inconsistency Behavior has changed from v2 to v3, or feature is missing altogether
Projects
None yet
Development

No branches or pull requests

3 participants