AWS Builder Center
Introducing Bref Lambda Layers Terraform module

Introducing Bref Lambda Layers Terraform module

Today I'm glad to introduce Bref Lambdas Layers Terraform module, making your PHP deployments on Lambda with Terraform easier than ever!

Feet on the ground, head in the Cloud
Today I'm glad to introduce Bref Lambdas Layers Terraform module !
Check it out on the Terraform registry !

What is Bref?

Bref  is a PHP community runtime for AWS Lambda, enabling serverless deployment of PHP applications.
With Bref, you can deploy any PHP code, from standalone functions or microservices to full (Symfony or Laravel) apps in a fully managed way.Thanks to Lambda you don't need to manage high availability or scalability and you can focus on your business logic.
Bref has three separate runtimes (function, FPM and console) and the Bref team maintains Lambda Layers for the most common PHP extensions.

Why a Terraform module?

The Bref core team, namely Matthieu Napoli, has a strong preference for the ServerLess  framework (a deployment framework, not to be confused with the concept of serverless that's the foundation of some AWS services (Lambda, S3, SQS, etc.) and as a result, the Bref documentation is quite focused on this deployment framework.
However, it's totally possible to deploy Bref-powered apps with other deployment tools (CDK, CloudFormation, Terraform). As a matter of fact, last year I offered a fully functional example of Terraform deployment  of a Bref-powered app using Terraform (my favourite deployment tools).
Deploying a Bref-powered app can be done in two ways. Either by using a Lambda container that contains the Bref framework, or using Lambda layers. Layers make your deployment way lighter (you only upload your source code). However you need to tell Lambda which layer(s) to use, by providing their ARN (AWS Resource Name). The Bref team maintains official Layers for all supported PHP versions and for many PHP extensions.
For those who use the ServerLess framework, the Bref team offers a plugin that will identify those Layers ARNs for you. But until today there was no such thing for Terraform aficionados!

How to use it?

Simply declare the module in your Terraform configuration
1
2
3
4
5
6
7
8
module "bref_layers" {
source = "../../"

php_version = "84"
cpu_type = "x86"
aws_region = "us-east-1"
php_extensions = ["gd", "imagick", "redis"]
}
then when defining the Lambdas function, just use the module outputs!
1
2
3
4
resource "aws_lambda_function" "example" {
# ... other configuration
layers = module.bref_layers.fpm_layers # Includes runtime + all extensions
}
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article