aws / aws-sdk-php-laravel

A Laravel 5+ (and 4) service provider for the AWS SDK for PHP
http://aws.amazon.com/sdkforphp/
Apache License 2.0
1.64k stars 242 forks source link

Can't publish SNS messages to fifo topics #198

Closed niiigoo closed 1 year ago

niiigoo commented 3 years ago

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug We have an ECS Cluster and a task should publish events to SNS topics. It works fine for non-fifo topics, but for fifo ones, the following error is returned: Invalid parameter: The MessageGroupId parameter is required for FIFO topics.

We use the region eu-central-1 and the task has the permission to publish SNS messages from the assigned role.

This is the used code snipped (the arn of the topic is correct):

$data = [
    'TopicArn' => $arn,
    'Message' => json_encode($message),
    'MessageAttributes' => [
        'Event' => [
            'DataType' => 'String',
            'StringValue' => $event, // e.g. "user.updated"
        ],
    ],
    'MessageGroupId' => $group, // e.g. "user-123"
    'MessageDeduplicationId' => md5($data['Message'] . microtime());
];
try {
    $this->sns->publish($data);
} catch (Exception $exception) {
    Log::critical('failed to publish message', ['data' => $data, 'error' => $exception->getMessage()]);
}

Detailed log entry:

{
    "message": "failed to publish message",
    "context": {
        "data": {
            "TopicArn": "arn:aws:sns:eu-central-1:***:test-user.fifo",
            "Message": "{\"id\":123,\"forename\":\"***\",\"surname\":\"***\",\"phone\":\"***\",\"email\":\"***\"}",
            "MessageAttributes": {
                "Event": {
                    "DataType": "String",
                    "StringValue": "user.updated"
                }
            },
            "MessageGroupId": "user-123",
            "MessageDeduplicationId": "53f4a129a6ad74166af9d33053cb1948"
        },
        "error": "Error executing \"Publish\" on \"https://sns.eu-central-1.amazonaws.com\"; AWS HTTP error: Client error: `POST https://sns.eu-central-1.amazonaws.com` resulted in a `400 Bad Request` response:\n<ErrorResponse xmlns=\"http://sns.amazonaws.com/doc/2010-03-31/\">\n <Error>\n <Type>Sender</Type>\n <Code>InvalidPara (truncated...)\n InvalidParameter (client): Invalid parameter: The MessageGroupId parameter is required for FIFO topics - <ErrorResponse xmlns=\"http://sns.amazonaws.com/doc/2010-03-31/\">\n <Error>\n <Type>Sender</Type>\n <Code>InvalidParameter</Code>\n <Message>Invalid parameter: The MessageGroupId parameter is required for FIFO topics</Message>\n </Error>\n <RequestId>a8e61439-c3f5-567f-9334-4c63612e659d</RequestId>\n</ErrorResponse>\n"
    },
    "level": 500,
    "level_name": "CRITICAL"
}

The parameters are set accordingly to the PHP SDK Reference.

Version of AWS SDK for PHP? aws/aws-sdk-php-laravel: 3.6.0 aws/aws-sdk-php: 3.138.8

Version of AWS Service Provider for Laravel?

Version of Laravel (php artisan --version)? 7.13.0

Version of PHP (php -v)? 7.4.5

To Reproduce (observed behavior)

Expected behavior The request to aws should contain the given parameters and of course, should be accepted/processed

Additional context The package aws/aws-sdk-php-laravel was installed with composer require aws/aws-sdk-php-laravel:^3.0 and the package aws/aws-sdk-php:3.138.8 was automatically installed. I'm not sure how to update this dependency (current version: 3.171.2)

kumarravisingh commented 3 years ago

I had the same issue in one of my client's legacy applications which were using some 3.x version of the aws-php-sdk. The solution which worked for me was to use latest version of the PHP SDK which right now is: 3.178.0 So it seems the solution for this issue is the SDK upgrade in this library and considering how it is written in composer.json i.e "aws/aws-sdk-php": "~3.0" A quick composer update command (which will bump up your aws-sdk-php version to the latest minor release i.e 3.178.0) should resolve this issue.

mathiasselleslach commented 3 years ago

I can confirm that updating aws-php-sdk to at least 3.173.19 fixes this issue. So seems unrelated to this repo 😉

yenfryherrerafeliz commented 1 year ago

Hi @niiigoo, thanks for opening this issue. Could you please try updating to the latest SDK version as @kumarravisingh and @mathiasselleslach mentioned?, also thanks to you folks for the comments.

@niiigoo In the meantime I will close this issue, but if after updating to the latest version the issue persist just reach out back.

Thanks!

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.