Skip to content

Can't publish SNS messages to fifo topics #198

@niiigoo

Description

@niiigoo

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)

  • Create a fifo topic
  • Subscribe a SQS fifo queue
  • Grant the service the permission to publish messages (we use IAM roles)
  • Try to publish a message with the code snippet provided above

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)

Metadata

Metadata

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions