Running serverless is great. When migrating our applications to use Bref we realized that we need a non-standard php-extension.
With “non-standard” I mean that the extension is not included by default by Bref. With some help I manage to make every
thing work as I wanted it to. Here is what I did:
I cloned the Bref repository to be able to build my own image. Then I added the NewRelic extension and config to php.Dockerfile
in the /runtime/php directory.
I disable logging since I run this on a read-only environment.
This is great and it should have been working on a normal server. However, NewRelic is configured to automatically start
with the PHP-FPM server. Since Bref has it custom implementation of PHP-FPM that will not work. We need to start the the
newrelic-daemon manually every time we load our Lambda function.
Let’s start with the function layer:
Finally done, but let’s move on to the website layer. First I rename the boostrap file to bootstrap-php. Then I create
a new bootstrap file with the following contents:
Now I add a line in bootstrap-php to make sure NewRelic is not considering my requests as background jobs:
Last thing to do is to make sure the new bootstrap-php is part of the runtime zip file.
Now we are finally done. Just rebuild your php docker, package your zip files and publish them on AWS.
In the response to the aws lambda publish-layer-version you will see the new ARN to use.
When everything is deployed, you need to make sure that your lambda function can reach internet. The NewRelic
daemon must be able to send data to NewRelic’s servers. You should also add newrelic_start_transaction and
newrelic_end_of_transaction on appropriate places in your application. Or else NewRelic will log really
long response times. If you are using Symfony and EkinoNewRelic bundle, you should configure it as you were
using Symfony HTTP Cache.
To accomplish this setup took me way more hours then I want to admit. So I hope this small post could help
someone to be a little faster than I was.