Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 8e8c793

Browse files
committed
More deployment examples
1 parent 7114182 commit 8e8c793

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Run the tool to create and publish Lambda layers that contain the PHP custom run
134134
../bin/local/img2lambda -i lambda-php:latest -r us-east-1 -o ./output
135135
```
136136

137+
### Deploy Manually
137138
Create a PHP function that uses the layers:
138139
```
139140
cd function
@@ -163,6 +164,78 @@ aws lambda invoke \
163164
cat hello-output.txt
164165
```
165166

167+
### Deploy with AWS Serverless Application Model (SAM)
168+
169+
See [the sample template.yml](example/function/template.yml) and [the sample template.json](example/function/template.json).
170+
171+
Insert the layers ARNs into the function definition:
172+
```
173+
cd function
174+
175+
sed -i 's/^- / - /' ../output/layers.yaml && \
176+
sed -e "/LAYERS_PLACEHOLDER/r ../output/layers.yaml" -e "s///" template.yaml > template-with-layers.yaml
177+
178+
OR
179+
180+
cd function
181+
182+
sed -e "/\"LAYERS_PLACEHOLDER\"/r ../output/layers.json" -e "s///" template.json | jq . > template-with-layers.json
183+
```
184+
185+
Deploy the function:
186+
```
187+
sam package --template-file template-with-layers.yaml \
188+
--output-template-file packaged.yaml \
189+
--region us-east-1 \
190+
--s3-bucket <bucket name>
191+
192+
sam deploy --template-file packaged.yaml \
193+
--capabilities CAPABILITY_IAM \
194+
--region us-east-1 \
195+
--stack-name img2lambda-php-example
196+
197+
OR
198+
199+
sam package --template-file template-with-layers.json \
200+
--output-template-file packaged.json \
201+
--region us-east-1 \
202+
--s3-bucket <bucket name>
203+
204+
sam deploy --template-file packaged.json \
205+
--capabilities CAPABILITY_IAM \
206+
--region us-east-1 \
207+
--stack-name img2lambda-php-example
208+
```
209+
210+
Invoke the function:
211+
```
212+
aws lambda invoke \
213+
--function-name sam-php-example-hello \
214+
--region us-east-1 \
215+
--log-type Tail \
216+
--query 'LogResult' \
217+
--output text \
218+
--payload '{"name": "World"}' hello-output.txt | base64 --decode
219+
220+
cat hello-output.txt
221+
```
222+
223+
### Deploy with Serverless Framework
224+
225+
See [the sample serverless.yml](example/function/serverless.yml) for how to use the img2lambda-generated layers in your Serverless function.
226+
227+
Deploy the function:
228+
```
229+
cd function
230+
231+
serverless deploy -v
232+
```
233+
234+
Invoke the function:
235+
```
236+
serverless invoke -f hello -l -d '{"name": "World"}'
237+
```
238+
166239
## License Summary
167240

168241
This sample code is made available under a modified MIT license. See the LICENSE file.

example/function/serverless.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
service: php-example-hello
2+
3+
provider:
4+
name: aws
5+
runtime: provided
6+
7+
functions:
8+
hello:
9+
handler: hello.hello
10+
package:
11+
include:
12+
- src/hello.php
13+
layers:
14+
${file(../output/layers.json)}
15+
goodbye:
16+
handler: goodbye.goodbye
17+
package:
18+
include:
19+
- src/goodbye.php
20+
layers:
21+
${file(../output/layers.json)}

example/function/template.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Transform": "AWS::Serverless-2016-10-31",
4+
"Resources": {
5+
"Hello": {
6+
"Type": "AWS::Serverless::Function",
7+
"Properties": {
8+
"FunctionName": "sam-php-example-hello",
9+
"Handler": "hello.hello",
10+
"Runtime": "provided",
11+
"CodeUri": "./",
12+
"Layers": "LAYERS_PLACEHOLDER"
13+
}
14+
},
15+
"Goodbye": {
16+
"Type": "AWS::Serverless::Function",
17+
"Properties": {
18+
"FunctionName": "sam-php-example-goodbye",
19+
"Handler": "goodbye.goodbye",
20+
"Runtime": "provided",
21+
"CodeUri": "./",
22+
"Layers": "LAYERS_PLACEHOLDER"
23+
}
24+
}
25+
}
26+
}

example/function/template.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: 'AWS::Serverless-2016-10-31'
3+
4+
Resources:
5+
Hello:
6+
Type: 'AWS::Serverless::Function'
7+
Properties:
8+
FunctionName: sam-php-example-hello
9+
Handler: hello.hello
10+
Runtime: provided
11+
CodeUri: ./
12+
Layers: LAYERS_PLACEHOLDER
13+
14+
Goodbye:
15+
Type: 'AWS::Serverless::Function'
16+
Properties:
17+
FunctionName: sam-php-example-goodbye
18+
Handler: goodbye.goodbye
19+
Runtime: provided
20+
CodeUri: ./
21+
Layers: LAYERS_PLACEHOLDER

0 commit comments

Comments
 (0)