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.
The Symfony Runtime component is AWESOME. I did a talk about it at
Symfony World 2021 where I explain how and
why it works. I spent a lot of time on the cont...
The lock component have saved me so many times. It helps me with race conditions,
it makes my code simpler and my application more reliable. I’m using it to ...
I’ve been blogging now and then for over a decade now. I have used Drupal, Wordpress,
plain HTML files, static generators as Jekyll and Sculpin. I’ve also us...
It has been one year since Jérémy Derussé and I started to work on a new API client
for AWS. At the time we could never have imagined how popular it would be...
Leave a Comment