PHP APM with AWS Lambda
  • 1 Minute to read
  • Dark
    Light
  • PDF

PHP APM with AWS Lambda

  • Dark
    Light
  • PDF

Article Summary

This document details how to setup APM with your AWS Lambda PHP Functions.

image.png

Stackify AWS Monitor Setup

AWS Lambda support requires a Stackify AWS Monitor server to forward application data to Stackify.
A monitoring server is required for each AWS region you are using functions.

Log into your AWS account and click the Launch Stack button below to deploy the CloudFormation Stack Cloud Formation Template.
Set parameter StackifyLambda is set to true.

image

Lambda Function Setup

Stackify APM works by adding a Lambda Layer to your function.

1. Add Stackify Layer to Function

On your function Configuration page, click the Add a layer button:
image.png

Find the correct StackifyPHPAPMLayer ARN for the region you are working in below:

RegionLayer ARN
us-east-1arn:aws:lambda:us-east-1:686826687729:layer:StackifyPHPAPMLayer:2
us-east-2arn:aws:lambda:us-east-2:686826687729:layer:StackifyPHPAPMLayer:2
us-west-1arn:aws:lambda:us-west-1:686826687729:layer:StackifyPHPAPMLayer:2
us-west-2arn:aws:lambda:us-west-2:686826687729:layer:StackifyPHPAPMLayer:2
ap-south-1arn:aws:lambda:ap-south-1:686826687729:layer:StackifyPHPAPMLayer:2
ap-northeast-1arn:aws:lambda:ap-northeast-1:686826687729:layer:StackifyPHPAPMLayer:2
ap-northeast-2arn:aws:lambda:ap-northeast-2:686826687729:layer:StackifyPHPAPMLayer:2
ap-southeast-1arn:aws:lambda:ap-southeast-1:686826687729:layer:StackifyPHPAPMLayer:2
ap-southeast-2arn:aws:lambda:ap-southeast-2:686826687729:layer:StackifyPHPAPMLayer:2
ca-central-1arn:aws:lambda:ca-central-1:686826687729:layer:StackifyPHPAPMLayer:2
eu-central-1arn:aws:lambda:eu-central-1:686826687729:layer:StackifyPHPAPMLayer:2
eu-west-1arn:aws:lambda:eu-west-1:686826687729:layer:StackifyPHPAPMLayer:2
eu-west-2arn:aws:lambda:eu-west-2:686826687729:layer:StackifyPHPAPMLayer:2
eu-west-3arn:aws:lambda:eu-west-3:686826687729:layer:StackifyPHPAPMLayer:2
eu-north-1arn:aws:lambda:eu-north-1:686826687729:layer:StackifyPHPAPMLayer:2
sa-east-1arn:aws:lambda:sa-east-1:686826687729:layer:StackifyPHPAPMLayer:2

2. Configure Stackify Layer

The StackifyPHPAPMLayer supplies the Stackify PHP Profiler.

  • Adjust PHP Runtime
    • Ensure that PHP is built with --with-config-file-scan-dir.
    • Adjust your bootstrap php script to include: require '/opt/stackify/Stackify.php';
  • Add Environment Variables
    • STACKIFY_APPLICATION_NAME - Application Name to associate with function.
    • STACKIFY_ENVIRONMENT_NAME - Environment Name to associate with function.
    • PHP_INI_SCAN_DIR - :/opt/stackify/ini/linux_[32|64]_[php version]. For example 64 bit distro with PHP 7.3 would be :/opt/stackify/ini/linux_64_7.3
  • Save your function.

3. Test

Run a test execution of your function and verify that the Log output contains a STACKIFY-TRACE line.

  • After a few minutes of function traffic, goto Retrace > Monitoring > Other Apps.
  • Click Add App
  • Click Existing Server
  • Find your application by name and click Add

AWS Costs

  • Each Stackify AWS Monitor runs inside an t2.micro ec2 instance by default.
  • The StackifyPHPAPMLayer writes logs to CloudWatch for each function execution. We suggest reducing retention on CloudWatch LogGroups.

Was this article helpful?