Admiral-Piett / goaws

AWS (SQS/SNS) Clone for Development testing
MIT License
779 stars 144 forks source link

Do not create "MD5OfMessageAttributes" when the message doesn't have "MessageAttributes" field #167

Closed aleferreiranogueira closed 6 years ago

aleferreiranogueira commented 6 years ago

When sending a message, the AWS Client will validate the field MD5OfMessageAttributes only if it's present in the payload.

Apparently, the SendMessage function in gosqs.go is appending the field MD5OfMessageAttributes regardless of the payload having 'MessageAttributes'. This causes the AWS Client validation to fail.

AWS SDK

if (isset($msg['MD5OfMessageAttributes'])) {
    $messageAttributesMd5 = self::calculateMessageAttributesMd5($msg);
       if ($messageAttributesMd5 !== $msg['MD5OfMessageAttributes']) {
          throw new SqsException(
             'Attribute MD5 mismatch. Expected %s, found %s',
             $msg['MD5OfMessageAttributes'],
            $messageAttributesMd5
               ? $messageAttributesMd5
               : 'No Attributes'
          )
      }
}

Stacktrace

 Attribute MD5 mismatch. Expected d41d8cd98f00b204e9800998ecf8427e, found No Attributes {"exception":"[object] (Aws\\Sqs\\Exception\\SqsException(code: 0): Attribute MD5 mismatch. Expected d41d8cd98f00b204e9800998ecf8427e, found No Attributes at /var/www/html/vendor/aws/aws-sdk-php/src/Sqs/SqsClient.php:221)

Apparently the solution is only to not put the "MD5OfMessageAttributes" if the "MessageAttributes" is not present.

I would open a PR to this, but I'm not quite sure if I'm going to have time anytime soon.

Thanks,

williamdes commented 5 years ago

@p4tin Can you please create a release and update the docker image ? I need this fix :)

NedNisW commented 5 years ago

@williamdes In the meantime you can use nednisw/goaws. I've build it a few minutes ago, it is using the current master.