Skip to content

Commit 74a7978

Browse files
committed
initialized repository
0 parents  commit 74a7978

File tree

16 files changed

+359
-0
lines changed

16 files changed

+359
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Layer
2+
# layer/php/php
3+
layer/php/php.zip

README.MD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# AWS Lambda PHP Hello World
2+
3+
The basics of using [Serverless Framework][1] for AWS Lambda PHP applications.
4+
5+
## Notes
6+
7+
1. Install Serverless Framework by following the [Quick Start][2]
8+
2. Set up your [AWS credentials][3]
9+
3. Create php binary by following steps in [`doc/create_php_binary.md`][4]
10+
4. Write your serverless application (!) - the default is in `handler.php`
11+
5. Run `sls deploy` to deploy to Lambda
12+
6. Run `sls invoke -f hello -l` to invoke your function
13+
14+
## PHP handler function signature
15+
Handler: filename.functionName
16+
hello.hello
17+
The signature for the PHP function is:
18+
19+
function main($eventData) : array
20+
21+
Hello world looks like:
22+
23+
<?php
24+
function hello($eventData) : array
25+
{
26+
return ["msg" => "Hello from PHP " . PHP_VERSION];
27+
}
28+
29+
30+
[1]: https://serverless.com
31+
[2]: https://serverless.com/framework/docs/providers/aws/guide/quick-start/
32+
[3]: https://serverless.com/framework/docs/providers/aws/guide/credentials/
33+
[4]: doc/create_php_binary.md

deploy.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
sam package --template-file template.yaml --output-template-file serverless-output.yaml --s3-bucket magistum-sam
4+
sam deploy --template-file serverless-output.yaml --stack-name magistum-serverless-php73 --capabilities CAPABILITY_IAM

docs/compile-php-7.3.1.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export SSH_KEY_FILE=~/magistum-pwa/files/appmagistumcom.pem
4+
scp -i $SSH_KEY_FILE ~/aws-lambda-layer-php73/docs/compile_php.sh $AWS_IP:compile_php.sh
5+
ssh -i $SSH_KEY_FILE -t $AWS_IP "chmod a+x compile_php.sh && ./compile_php.sh 7.3.1"
6+
scp -i $SSH_KEY_FILE $AWS_IP:/home/ec2-user/php-7-bin/bin/php ~/aws-lambda-layer-php73/layer/php

docs/compile_php.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# FROM https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/
4+
5+
PHP_VERSION=$1
6+
if [ -z "$PHP_VERSION" ]; then
7+
echo "Usage: compile_php.sh <PHP version>"
8+
exit 1
9+
fi
10+
11+
# Update packages and install needed compilation dependencies
12+
sudo yum update -y
13+
sudo yum install autoconf bison gcc gcc-c++ libcurl-devel libxml2-devel -y
14+
15+
# Compile OpenSSL v1.0.1 from source, as Amazon Linux uses a newer version than the Lambda Execution Environment, which
16+
# would otherwise produce an incompatible binary.
17+
curl -sL http://www.openssl.org/source/openssl-1.0.1k.tar.gz | tar -xvz
18+
cd openssl-1.0.1k
19+
./config && make && sudo make install
20+
cd ~
21+
22+
# Download the PHP 7.3.0 source
23+
mkdir ~/php-7-bin
24+
curl -sL https://github.com/php/php-src/archive/php-${PHP_VERSION}.tar.gz | tar -xvz
25+
cd php-src-php-${PHP_VERSION}
26+
27+
# Compile PHP 7.3.0 with OpenSSL 1.0.1 support, and install to /home/ec2-user/php-7-bin
28+
./buildconf --force
29+
./configure --prefix=/home/ec2-user/php-7-bin/ --with-openssl=/usr/local/ssl --with-curl --with-zlib
30+
export LC_ALL=en_US.UTF-8
31+
make install

layer/.DS_Store

6 KB
Binary file not shown.

layer/php/.DS_Store

6 KB
Binary file not shown.

layer/php/bootstrap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Modified from: https://github.com/pagnihotry/PHP-Lambda-Runtime/blob/master/runtime/bootstrap
4+
# Copyright (c) 2018 Parikshit Agnihotry
5+
6+
# go into the source directory
7+
cd $LAMBDA_TASK_ROOT
8+
9+
# execute the runtime
10+
/opt/php /opt/runtime.php

layer/php/php

36.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)