diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 0265b619c8be..883e0f4bfe2e 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -243,6 +243,7 @@ jobs: MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages MESSENGER_SQS_DSN: "sqs://localhost:4566/messages?sslmode=disable&poll_timeout=0.01" MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:4566/messages.fifo?sslmode=disable&poll_timeout=0.01" + AWS_ENDPOINT_URL: "http://localhost:4566" KAFKA_BROKER: 127.0.0.1:9092 POSTGRES_HOST: localhost PGBOUNCER_HOST: localhost:6432 diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php index 16dff20e3d34..e3cd590ebd29 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Messenger\Bridge\AmazonSqs\Transport; +use AsyncAws\Core\Sts\StsClient; use AsyncAws\Sqs\Enum\MessageSystemAttributeName; use AsyncAws\Sqs\Enum\QueueAttributeName; use AsyncAws\Sqs\Result\ReceiveMessageResult; @@ -53,6 +54,7 @@ class Connection private array $configuration; private SqsClient $client; + private StsClient $stsClient; private ?ReceiveMessageResult $currentResponse = null; /** @var array[] */ private array $buffer = []; @@ -61,9 +63,11 @@ public function __construct( array $configuration, ?SqsClient $client = null, private ?string $queueUrl = null, + ?StsClient $stsClient = null, ) { $this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration); $this->client = $client ?? new SqsClient([]); + $this->stsClient = $stsClient ?? new StsClient([]); } public function __sleep(): array @@ -274,8 +278,11 @@ public function setup(): void return; } - if (null !== $this->configuration['account']) { - throw new InvalidArgumentException(\sprintf('The Amazon SQS queue "%s" does not exist (or you don\'t have permissions on it), and can\'t be created when an account is provided.', $this->configuration['queue_name'])); + $accountId = $this->stsClient->getCallerIdentity()->getAccount(); + + // If the queue does not exist, we can create it only if the account is the same + if (null !== $this->configuration['account'] && $accountId !== $this->configuration['account']) { + throw new InvalidArgumentException(\sprintf('The Amazon SQS queue "%s" does not exist (or you don\'t have permissions on it), and can\'t be created when an other account is provided.', $this->configuration['queue_name'])); } $parameters = ['QueueName' => $this->configuration['queue_name']];