aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
5.99k stars 1.2k forks source link

SQS: unable to send messages to local endpoint #2947

Open jasonbigl opened 1 week ago

jasonbigl commented 1 week ago

Describe the bug

I'm using docker image softwaremill/elasticmq to simulate local SQS endpoint, it help me test code in my local machine, I use php sdk to send message to it (http://localhost:9324/000000000000/emails), in version 3.238.3, it works well, however if I upgrade the sdk to latest version (3.314.3), I always get the error saying that POST https://sqs.us-east-1.amazonaws.com resulted in a 404 Not Found response, it seems the new sdk always to send to online sqs endpoint, ignore the queue url I specified.

Expected Behavior

php sdk should always send message to the exact endpoint that I specified in the QueueUrl parameter

Current Behavior

php sdk send message to the online endpoint

Reproduction Steps

  1. pull docker image softwaremill/elasticmq and run it
  2. send a message to the locahost enpoint, which is backed by docker image from step 2
  3. you will get the error, however if you use old version 3.238.3, all good.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

3.314.3

Environment details (Version of PHP (php -v)? OS name and version, etc.)

php 8.3, debian 12

yenfryherrerafeliz commented 6 days ago

Hi @jasonbigl, sorry to hear about your issues. Previously we had a middleware, which you can check here, that used to pick up the QueueUrl, from the command or request parameters, and made it the request URL to be used, however, due to a protocol migration from query to json that the service did, that is not possible anymore. However, you may have a workaround and is passing the endpoint to the client constructor instead, as follow:

<?php

require '../vendor/autoload.php';

use Aws\Sqs\SqsClient;

$client = new SqsClient([
    'region' => getenv('TEST_REGION'),
    'endpoint' =>  'YOUR_CUSTOM_ENDPOINT' // in this case I guess it would be "http://elasticmq:9324"
]);
$response = $client->sendMessage([
    'QueueUrl' => 'YOUR_QUEUE_URL',
    'MessageBody' => 'Test message body'
]);

print_r([$response]);

You can also reference the following previous issue.

Please let me know if that helps!

Thanks!