Skip to content

Conversation

@bentsku
Copy link
Contributor

@bentsku bentsku commented Nov 14, 2023

Motivation

As reported in #8267 (comment), it seems the PHP SDK still struggles to communicate with LocalStack.

After investigation, it showed that the PHP SDK is still sending the requests to the queue URL even though the specs are specifying that it should be against /. Our router caught the request and assumed it was a Query API.

Changes

  • if the Content-Type header is application/x-amz-json-1.0, raise NotFound in the route so that the handler chain can take of the request
  • add a test testing this very weird behavior by creating a client with an endpoint set to the queue URL (tested against AWS, it weirdly works...)

Tested with a PHP sample, it solves the issue now

Testing

To test the changes with the PHP SDK:

  • docker pull php
  • docker run --rm -it php bash
  • curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  • apt update
  • apt install zip
  • cd /usr/src & mkdir app & cd app
  • composer require aws/aws-sdk-php
  • set this in the file test.php:
<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';

use Aws\Sqs\SqsClient;

$sqs = new SqsClient([
    'version' => 'latest',
    'region'  => 'us-west-2'
]);

$params = [
    'DelaySeconds' => 10,
    'MessageAttributes' => [
        "Title" => [
            'DataType' => "String",
            'StringValue' => "The Hitchhiker's Guide to the Galaxy"
        ]
    ],
    'MessageBody' => "Information about current NY Times fiction bestseller for week of 12/11/2016.",
    'QueueUrl' => 'http://host.docker.internal:4566/queue/us-east-1/000000000000/test'
];

$result = $sqs->sendMessage($params);
var_dump($result);
  • export AWS_ACCESS_KEY_ID=test
  • export AWS_SECRET_ACCESS_KEY=test
  • php test.php
  • run, it should now properly show the result and not an exception

@bentsku bentsku requested a review from alexrashed November 14, 2023 20:37
@bentsku bentsku self-assigned this Nov 14, 2023
@bentsku bentsku added aws:sqs Amazon Simple Queue Service semver: patch Non-breaking changes which can be included in patch releases labels Nov 14, 2023
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks so much for investigating on this weird behavior, fixing it, and writing a validated test for it! 🦸🏽

@coveralls
Copy link

Coverage Status

coverage: 84.019% (+0.007%) from 84.012%
when pulling 44517f8 on fix-query-api-json-protocol
into ccb9552 on master.

@github-actions
Copy link

LocalStack Community integration with Pro

       2 files         2 suites   1h 4m 26s ⏱️
2 314 tests 2 015 ✔️ 299 💤 0
2 315 runs  2 015 ✔️ 300 💤 0

Results for commit 44517f8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws:sqs Amazon Simple Queue Service semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants