Search code examples
phpsymfonyamqpamazon-mq

Fail connect to AmazonMQ using Symfony messenger


I tried to connect to AmazonMQ with amqps protocol in AmazonMQ and get this error:

NOTICE: PHP message: [error] Symfony\Component\Messenger\Exception\InvalidArgumentException
cfi-lms-api_1              | No CA certificate has been provided. Set "amqp.cacert" in your php.ini or pass the "cacert" parameter in the DSN to use SSL. Alternatively, you can use amqp:// to use without SSL.

Where I can get this certificate and how to properly work with amqps in case AmazonMQ? What path for cacert I should specify?

I tried use amqp protocol but Amazon MQ does not support it.


Solution

  • In the docs:

    If you want to use TLS/SSL encrypted AMQP, you must also provide a CA certificate. Define the certificate path in the amqp.cacert PHP.ini setting (e.g. amqp.cacert = /etc/ssl/certs) or in the cacert parameter of the DSN (e.g amqps://localhost?cacert=/etc/ssl/certs/).

    (at https://symfony.com/doc/current/messenger.html)

    It says cacert is "Path to the CA cert file in PEM format."

    You can download the file through your web browser, clicking the "locker" icon next to "https" in the url bar. For example, the ca cert for StackOverflow can be downloaded like so :

    enter image description here

    enter image description here

    Prefer the one from the "root" tab, which is usually valid way longer (+ 10 years).

    Source:

    https://github.com/symfony/amqp-messenger/blob/5.4/Transport/Connection.php#L232

    https://github.com/symfony/amqp-messenger/blob/4175a0a98507e7ec575dca9b36e6c0a5a072d3fd/Transport/Connection.php#L285