Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 6b3c99a

Browse files
author
Ben Smith
authored
Merge pull request #41 from majdarbash/master
2 parents 9032098 + ccc051c commit 6b3c99a

File tree

5 files changed

+44
-55
lines changed

5 files changed

+44
-55
lines changed
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#Lambda base image Amazon linux
22
FROM public.ecr.aws/lambda/provided as builder
33
# Set desired PHP Version
4-
ARG php_version="7.3.6"
5-
RUN yum clean all && \
6-
yum install -y autoconf \
4+
ARG php_version="8.3.1"
5+
ARG php_path="/var/lang/"
6+
ARG lambda_runtime_path="/var/runtime"
7+
ARG lambda_task_path="/var/task"
8+
9+
RUN dnf clean all && \
10+
dnf install -y autoconf \
711
bison \
812
bzip2-devel \
913
gcc \
@@ -16,39 +20,30 @@ RUN yum clean all && \
1620
openssl-devel \
1721
tar \
1822
unzip \
19-
zip
23+
zip \
24+
re2c \
25+
sqlite-devel \
26+
oniguruma-devel
2027

2128
# Download the PHP source, compile, and install both PHP and Composer
2229
RUN curl -sL https://github.com/php/php-src/archive/php-${php_version}.tar.gz | tar -xvz && \
2330
cd php-src-php-${php_version} && \
2431
./buildconf --force && \
25-
./configure --prefix=/opt/php-7-bin/ --with-openssl --with-curl --with-zlib --without-pear --enable-bcmath --with-bz2 --enable-mbstring --with-mysqli && \
32+
./configure --prefix=${php_path} --with-openssl --with-curl --with-zlib --without-pear --enable-bcmath --with-bz2 --enable-mbstring --with-mysqli && \
2633
make -j 5 && \
2734
make install && \
28-
/opt/php-7-bin/bin/php -v && \
29-
curl -sS https://getcomposer.org/installer | /opt/php-7-bin/bin/php -- --install-dir=/opt/php-7-bin/bin/ --filename=composer
35+
${php_path}/bin/php -v && \
36+
curl -sS https://getcomposer.org/installer | ${php_path}/bin/php -- --install-dir=${php_path}/bin/ --filename=composer
3037

3138
# Prepare runtime files
32-
# RUN mkdir -p /lambda-php-runtime/bin && \
33-
# cp /opt/php-7-bin/bin/php /lambda-php-runtime/bin/php
34-
COPY runtime/bootstrap /lambda-php-runtime/
35-
RUN chmod 0755 /lambda-php-runtime/bootstrap
39+
COPY runtime/bootstrap ${lambda_runtime_path}
40+
RUN chmod 0755 ${lambda_runtime_path}/bootstrap
3641

3742
# Install Guzzle, prepare vendor files
38-
RUN mkdir /lambda-php-vendor && \
39-
cd /lambda-php-vendor && \
40-
/opt/php-7-bin/bin/php /opt/php-7-bin/bin/composer require guzzlehttp/guzzle
41-
43+
RUN cd /opt && \
44+
${php_path}/bin/php ${php_path}/bin/composer require guzzlehttp/guzzle
4245

43-
###### Create runtime image ######
44-
FROM public.ecr.aws/lambda/provided as runtime
45-
# Layer 1: PHP Binaries
46-
COPY --from=builder /opt/php-7-bin /var/lang
47-
# Layer 2: Runtime Interface Client
48-
COPY --from=builder /lambda-php-runtime /var/runtime
49-
# Layer 3: Vendor
50-
COPY --from=builder /lambda-php-vendor/vendor /opt/vendor
5146

52-
COPY src/ /var/task/
47+
COPY src/ ${lambda_task_path}
5348

54-
CMD [ "index" ]
49+
CMD [ "index.handler" ]

‎0.7-PHP-Lambda-functions-with-Docker-container-images/readme.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,45 +60,32 @@ This [Dockerfile](./0.7-PHP-Lambda-functions-with-Docker-container-images/Docker
6060

6161
## Deploy the sample application
6262

63-
1. Use the AWS CLI to create a new ECR repository to store the container image for the phpLambdaFunction.
64-
65-
```bash
66-
aws ecr create-repository --repository-name php-lambda-function \
67-
--image-tag-mutability IMMUTABLE --image-scanning-configuration scanOnPush=true
68-
```
69-
![create-repository-output](../repository-resources/repositryUrl.png)
70-
71-
Make a note of the repositoryUri as you need it in the next step.
72-
73-
2. Authenticate the Docker CLI to your Amazon ECR registry.
74-
75-
``` bash
76-
aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {yourAccountID}.dkr.ecr.{region} .amazonaws.com
77-
```
78-
3. Build the application locally
63+
1. Build the application locally
7964
```bash
8065
sam build
8166
```
8267

83-
4. Use the guided version of the sam deploy command and follow these steps:
68+
2. Use the guided version of the sam deploy command and follow these steps:
69+
(AWS SAM will create a new ECR repository to store the container image for the phpLambdaFunction)
8470

8571
```bash
8672
sam deploy -g
8773
```
8874
* For Stack Name, enter my-php-lambda-container-demo.
89-
* Choose the same Region that you created the ECR repository in.
90-
* Enter the Image Repository for the HelloWorldFunction (this is the repositoryUri of the ECR repository).
75+
* Choose the region that you want to deploy to.
9176
* For Confirm changes before deploy and Allow SAM CLI IAM role creation, keep the defaults.
9277
* For HelloWorldFunction may not have authorization defined, Is this okay? Select Y.
9378
* Keep the defaults for the remaining prompts:
9479
![Sam-deploy-oci](../repository-resources/samDeployOci.png)
9580

96-
5. The output displays the HTTP APIs endpoint url:
81+
3. The output displays the HTTP APIs endpoint url:
9782
![sam-oci-output](../repository-resources/SamOciOutput.png)
9883

99-
6. Send a POST request to the endpoint URL to invoke the Lambda function:
84+
4. Send a POST request to the endpoint URL to invoke the Lambda function:
85+
(replace the api-gateway-url below with the value from the previous step)
86+
10087
```bash
101-
curl "https://n2s2asbh90.execute-api.eu-west-1.amazonaws.com" -d '{"queryStringParameters": {"name":"Ben"}}'
88+
curl "{api-gateway-url}?name=Ben"
10289
```
10390

10491
![Post-Request-OCI](../repository-resources/finalLambdaOCI.png)

‎0.7-PHP-Lambda-functions-with-Docker-container-images/runtime/bootstrap

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ do {
2525
$request = getNextRequest();
2626

2727
// Obtain the function name from the _HANDLER environment variable and ensure the function's code is available.
28-
$handlerFunction = $_ENV['_HANDLER'];
29-
require_once $_ENV['LAMBDA_TASK_ROOT'] . '/' . $handlerFunction . '.php';
28+
$arr = explode('.', $_ENV['_HANDLER']);
29+
$handlerFile = array_slice($arr, 0, count($arr) - 1)[0];
30+
$handlerFunction = array_slice($arr, -1)[0];
31+
32+
if (!$handlerFile) {
33+
$handlerFile = $handlerFunction;
34+
}
35+
36+
require_once $_ENV['LAMBDA_TASK_ROOT'] . '/' . $handlerFile . '.php';
3037

3138
// Execute the desired function and obtain the response.
3239
$response = $handlerFunction($request['payload']);
@@ -41,16 +48,16 @@ function getNextRequest()
4148
$response = $client->get('http://' . $_ENV['AWS_LAMBDA_RUNTIME_API'] . '/2018-06-01/runtime/invocation/next');
4249

4350
return [
44-
'invocationId' => $response->getHeader('Lambda-Runtime-Aws-Request-Id')[0],
45-
'payload' => json_decode((string) $response->getBody(), true)
51+
'invocationId' => $response->getHeader('Lambda-Runtime-Aws-Request-Id')[0],
52+
'payload' => json_decode((string) $response->getBody(), true)
4653
];
4754
}
4855

4956
function sendResponse($invocationId, $response)
5057
{
5158
$client = new \GuzzleHttp\Client();
5259
$client->post(
53-
'http://' . $_ENV['AWS_LAMBDA_RUNTIME_API'] . '/2018-06-01/runtime/invocation/' . $invocationId . '/response',
54-
['body' => $response]
60+
'http://' . $_ENV['AWS_LAMBDA_RUNTIME_API'] . '/2018-06-01/runtime/invocation/' . $invocationId . '/response',
61+
['body' => $response]
5562
);
5663
}

‎0.7-PHP-Lambda-functions-with-Docker-container-images/src/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<?
2+
<?
33
/* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
55
Permission is hereby granted, free of charge, to any person obtaining a copy of this
@@ -19,7 +19,7 @@
1919

2020

2121
//hello function
22-
function index($data)
22+
function handler($data)
2323
{
2424
return APIResponse("Hello, ". $data['queryStringParameters']['name']);
2525
}

‎repository-resources/finalLambdaOCI.png

11.4 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /