Skip to content

Commit

Permalink
docs: add alb example
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstack committed Jun 3, 2019
1 parent 149b449 commit b85e3e0
Show file tree
Hide file tree
Showing 13 changed files with 2,334 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/alb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template.packaged.yaml
*.tgz
5 changes: 5 additions & 0 deletions examples/alb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Development

1. `npm pack ../..`
2. `npm install --prefix ./src ./`
3. `node local.js`
30 changes: 30 additions & 0 deletions examples/alb/alb-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:347971939225:targetgroup/aws-s-Targe-RJF5FKWHX6Y8/29425aed99131fd0"
}
},
"httpMethod": "POST",
"path": "/users",
"multiValueQueryStringParameters": {},
"multiValueHeaders": {
"accept": ["*/*"],
"accept-encoding": ["gzip, deflate"],
"accept-language": ["en-US,en;q=0.9"],
"cache-control": ["no-cache"],
"connection": ["keep-alive"],
"content-length": ["26"],
"content-type": ["application/json"],
"host": ["aws-ser-alb-p9y7dvwm0r42-2135869912.us-east-1.elb.amazonaws.com"],
"origin": ["http://aws-ser-alb-p9y7dvwm0r42-2135869912.us-east-1.elb.amazonaws.com"],
"pragma": ["no-cache"],
"referer": ["http://aws-ser-alb-p9y7dvwm0r42-2135869912.us-east-1.elb.amazonaws.com/"],
"user-agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"],
"x-amzn-trace-id": ["Root=1-5cdf3407-76d73870a87c746001f27090"],
"x-forwarded-for": ["72.21.198.66"],
"x-forwarded-port": ["80"],
"x-forwarded-proto": ["http"]
},
"body": "{\"name\":\"postmaaaateeeee\"}",
"isBase64Encoded": false
}
28 changes: 28 additions & 0 deletions examples/alb/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const lambdaFunction = require('./src/lambda.js')
const albEvent = require('./alb-event.json')

const server = lambdaFunction.handler(albEvent, {})
.then(v => {
console.info(v)
process.exit(0)
})
.catch(v => {
console.error(v)
process.exit(1)
})

process.stdin.resume()

function exitHandler (options, err) {
if (options.cleanup && server && server.close) {
server.close()
}

if (err) console.error(err.stack)
if (options.exit) process.exit()
}

process.on('exit', exitHandler.bind(null, { cleanup: true }))
process.on('SIGINT', exitHandler.bind(null, { exit: true })) // ctrl+c event
process.on('SIGTSTP', exitHandler.bind(null, { exit: true })) // ctrl+v event
process.on('uncaughtException', exitHandler.bind(null, { exit: true }))
Loading

0 comments on commit b85e3e0

Please sign in to comment.