This is the basic example using the Bref plugin with the Serverless framework. Bref creates a runtime for PHP on AWS so you can use PHP to write out your functions instead of JavaScript.
More information on Bref is available here.
This is the serverless.yml
file:
service: php-app
provider:
name: aws
region: us-east-1
runtime: provided.al2
plugins:
- ./vendor/bref/bref
functions:
app:
handler: index.php
description: 'Just a fun test app...'
layers:
- ${bref:layer.php-74-fpm}
events:
- httpApi: '*'
# Exclude files from deployment
package:
patterns:
- '!node_modules/**'
- '!tests/**'
This is the index.php
file:
<?php
// PHP associative arrays!
echo json_encode(
[
'name' => 'Joan Smith',
'dob' => 'January 1, 1970',
'snack' => 'pb cup',
]
);