Skip to content

Commit d30e2f7

Browse files
authored
Merge pull request #13 from aws-samples/dev
Add an example to show how to use Lambda Adapter with managed runtime
2 parents b2fa1ed + adaa0ef commit d30e2f7

File tree

21 files changed

+2864
-1
lines changed

21 files changed

+2864
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ The readiness check port/path and traffic port can be configured using environme
137137

138138
## Show me examples
139139

140-
4 examples are included under the 'examples' directory. Check them out, find out how easy it is to run a web application on AWS Lambda.
140+
Several examples are included under the 'examples' directory. Check them out, find out how easy it is to run a web application on AWS Lambda.
141141

142142
- [Flask](examples/flask)
143143
- [Express.js](examples/expressjs)
144144
- [SpringBoot](examples/springboot)
145145
- [nginx](examples/nginx)
146+
- [php](examples/php)
146147

147148
## Acknowledgement
148149

examples/expressjs-zip/.gitignore

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam
4+
5+
### Linux ###
6+
*~
7+
8+
# temporary files which can be created if a process still has a handle open of a deleted file
9+
.fuse_hidden*
10+
11+
# KDE directory preferences
12+
.directory
13+
14+
# Linux trash folder which might appear on any partition or disk
15+
.Trash-*
16+
17+
# .nfs files are created when an open file is removed but is still being accessed
18+
.nfs*
19+
20+
### Node ###
21+
# Logs
22+
logs
23+
*.log
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
lerna-debug.log*
28+
29+
# Diagnostic reports (https://nodejs.org/api/report.html)
30+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
31+
32+
# Runtime data
33+
pids
34+
*.pid
35+
*.seed
36+
*.pid.lock
37+
38+
# Directory for instrumented libs generated by jscoverage/JSCover
39+
lib-cov
40+
41+
# Coverage directory used by tools like istanbul
42+
coverage
43+
*.lcov
44+
45+
# nyc test coverage
46+
.nyc_output
47+
48+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
49+
.grunt
50+
51+
# Bower dependency directory (https://bower.io/)
52+
bower_components
53+
54+
# node-waf configuration
55+
.lock-wscript
56+
57+
# Compiled binary addons (https://nodejs.org/api/addons.html)
58+
build/Release
59+
60+
# Dependency directories
61+
node_modules/
62+
jspm_packages/
63+
64+
# TypeScript v1 declaration files
65+
typings/
66+
67+
# TypeScript cache
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
.npm
72+
73+
# Optional eslint cache
74+
.eslintcache
75+
76+
# Optional stylelint cache
77+
.stylelintcache
78+
79+
# Microbundle cache
80+
.rpt2_cache/
81+
.rts2_cache_cjs/
82+
.rts2_cache_es/
83+
.rts2_cache_umd/
84+
85+
# Optional REPL history
86+
.node_repl_history
87+
88+
# Output of 'npm pack'
89+
*.tgz
90+
91+
# Yarn Integrity file
92+
.yarn-integrity
93+
94+
# dotenv environment variables file
95+
.env
96+
.env.test
97+
.env*.local
98+
99+
# parcel-bundler cache (https://parceljs.org/)
100+
.cache
101+
.parcel-cache
102+
103+
# Next.js build output
104+
.next
105+
106+
# Nuxt.js build / generate output
107+
.nuxt
108+
dist
109+
110+
# Storybook build outputs
111+
.out
112+
.storybook-out
113+
storybook-static
114+
115+
# rollup.js default build output
116+
dist/
117+
118+
# Gatsby files
119+
.cache/
120+
# Comment in the public line in if your project uses Gatsby and not Next.js
121+
# https://nextjs.org/blog/next-9-1#public-directory-support
122+
# public
123+
124+
# vuepress build output
125+
.vuepress/dist
126+
127+
# Serverless directories
128+
.serverless/
129+
130+
# FuseBox cache
131+
.fusebox/
132+
133+
# DynamoDB Local files
134+
.dynamodb/
135+
136+
# TernJS port file
137+
.tern-port
138+
139+
# Stores VSCode versions used for testing VSCode extensions
140+
.vscode-test
141+
142+
# Temporary folders
143+
tmp/
144+
temp/
145+
146+
### OSX ###
147+
# General
148+
.DS_Store
149+
.AppleDouble
150+
.LSOverride
151+
152+
# Icon must end with two \r
153+
Icon
154+
155+
156+
# Thumbnails
157+
._*
158+
159+
# Files that might appear in the root of a volume
160+
.DocumentRevisions-V100
161+
.fseventsd
162+
.Spotlight-V100
163+
.TemporaryItems
164+
.Trashes
165+
.VolumeIcon.icns
166+
.com.apple.timemachine.donotpresent
167+
168+
# Directories potentially created on remote AFP share
169+
.AppleDB
170+
.AppleDesktop
171+
Network Trash Folder
172+
Temporary Items
173+
.apdisk
174+
175+
### SAM ###
176+
# Ignore build directories for the AWS Serverless Application Model (SAM)
177+
# Info: https://aws.amazon.com/serverless/sam/
178+
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html
179+
180+
**/.aws-sam
181+
182+
### Windows ###
183+
# Windows thumbnail cache files
184+
Thumbs.db
185+
Thumbs.db:encryptable
186+
ehthumbs.db
187+
ehthumbs_vista.db
188+
189+
# Dump file
190+
*.stackdump
191+
192+
# Folder config file
193+
[Dd]esktop.ini
194+
195+
# Recycle Bin used on file shares
196+
$RECYCLE.BIN/
197+
198+
# Windows Installer files
199+
*.cab
200+
*.msi
201+
*.msix
202+
*.msm
203+
*.msp
204+
205+
# Windows shortcuts
206+
*.lnk
207+
208+
# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam

examples/expressjs-zip/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# expressjs-zip
2+
3+
This example shows how to use Lambda Adapter to run an express.js application on managed node.js runtime.
4+
5+
### How does it work?
6+
7+
We package Lambda Adapter binary and a wrapper script into a Lambda Layer. And we configure environment variable 'AWS_LAMBDA_EXEC_WRAPPER' pointing to the wrapper script.
8+
9+
When Lambda execution environment starts, Lambda will execute the wrapper script and starts the adapter.
10+
11+
To get more information of Wrapper script, please read Lambda documentation [here](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-modify.html#runtime-wrapper).
12+
13+
### Build and Deploy
14+
15+
Run the following commands to build and deploy the application to lambda.
16+
17+
```bash
18+
sam build
19+
sam deploy --guided
20+
```
21+
When the deployment completes, take note of HelloWorldApi's Value. It is the API Gateway endpoint URL.
22+
23+
### Verify it works
24+
25+
Open HelloWorldApi's URL in a browser, you should see "Hi there!" on the page.
26+
27+
13.5 MB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
args=("$@")
4+
5+
exec -- "/opt/bootstrap" "${args[@]:0:$#-1}" "${LAMBDA_TASK_ROOT}/${_HANDLER}"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"body": "{\"message\": \"hello world\"}",
3+
"resource": "/{proxy+}",
4+
"path": "/path/to/resource",
5+
"httpMethod": "POST",
6+
"isBase64Encoded": false,
7+
"queryStringParameters": {
8+
"foo": "bar"
9+
},
10+
"pathParameters": {
11+
"proxy": "/path/to/resource"
12+
},
13+
"stageVariables": {
14+
"baz": "qux"
15+
},
16+
"headers": {
17+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
18+
"Accept-Encoding": "gzip, deflate, sdch",
19+
"Accept-Language": "en-US,en;q=0.8",
20+
"Cache-Control": "max-age=0",
21+
"CloudFront-Forwarded-Proto": "https",
22+
"CloudFront-Is-Desktop-Viewer": "true",
23+
"CloudFront-Is-Mobile-Viewer": "false",
24+
"CloudFront-Is-SmartTV-Viewer": "false",
25+
"CloudFront-Is-Tablet-Viewer": "false",
26+
"CloudFront-Viewer-Country": "US",
27+
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
28+
"Upgrade-Insecure-Requests": "1",
29+
"User-Agent": "Custom User Agent String",
30+
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
31+
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
32+
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
33+
"X-Forwarded-Port": "443",
34+
"X-Forwarded-Proto": "https"
35+
},
36+
"requestContext": {
37+
"accountId": "123456789012",
38+
"resourceId": "123456",
39+
"stage": "prod",
40+
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
41+
"requestTime": "09/Apr/2015:12:34:56 +0000",
42+
"requestTimeEpoch": 1428582896000,
43+
"identity": {
44+
"cognitoIdentityPoolId": null,
45+
"accountId": null,
46+
"cognitoIdentityId": null,
47+
"caller": null,
48+
"accessKey": null,
49+
"sourceIp": "127.0.0.1",
50+
"cognitoAuthenticationType": null,
51+
"cognitoAuthenticationProvider": null,
52+
"userArn": null,
53+
"userAgent": "Custom User Agent String",
54+
"user": null
55+
},
56+
"path": "/prod/path/to/resource",
57+
"resourcePath": "/{proxy+}",
58+
"httpMethod": "POST",
59+
"apiId": "1234567890",
60+
"protocol": "HTTP/1.1"
61+
}
62+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require('express')
2+
const app = express()
3+
const port = process.env['PORT'] || 8080
4+
5+
6+
app.get('/', (req, res) => {
7+
res.send('Hi there!')
8+
})
9+
10+
app.listen(port, () => {
11+
console.log(`Example app listening at http://localhost:${port}`)
12+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "hello_world",
3+
"version": "1.0.0",
4+
"description": "hello world sample for NodeJS",
5+
"main": "app.js",
6+
"repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs",
7+
"author": "SAM CLI",
8+
"license": "MIT",
9+
"dependencies": {
10+
"express": "^4.17.1"
11+
},
12+
"scripts": {
13+
"test": "mocha tests/unit/"
14+
},
15+
"devDependencies": {
16+
"chai": "^4.2.0",
17+
"mocha": "^8.2.1"
18+
}
19+
}

0 commit comments

Comments
 (0)