Created
May 25, 2017 09:16
-
-
Save sime/f2892d972b5ffdb657f9b178cd09cbaa to your computer and use it in GitHub Desktop.
TechTalk: Serverless Framework, 24 May 2015
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports.hello = (event, context, callback) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify({ | |
message: 'Go Serverless v1.0! Your function executed successfully!', | |
input: event, | |
}), | |
}; | |
callback(null, response); | |
// Use this code if you don't use the http event with the LAMBDA-PROXY integration | |
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); | |
}; | |
module.exports.demo = (event, context, callback) => { | |
let id = event.pathParameters.id; | |
let response = { | |
statusCode: 200, | |
body: JSON.stringify({ | |
id: id | |
}), | |
}; | |
if (id !== "goodbye") { | |
response = { | |
statusCode: 404, | |
body: JSON.stringify({ | |
message: "Bad ID", | |
}) | |
} | |
} | |
callback(null, response); | |
}; | |
module.exports.img = (event, context, callback) => { | |
event.Records.forEach(record => { | |
const filename = record.s3.object.key; | |
const filesize = record.s3.object.size; | |
console.log(`${filename} (${filesize} bytes) was just uploaded`); | |
}); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: techtalk | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
region: eu-west-1 | |
profile: vpdev | |
functions: | |
hello: | |
handler: handler.hello | |
events: | |
- http: | |
path: v1/hello | |
method: post | |
demo: | |
handler: handler.demo | |
events: | |
- http: | |
path: v1/demo/{id} | |
method: get | |
- http: | |
path: v1/demo/{id} | |
method: delete | |
img: | |
handler: handler.img | |
events: | |
- s3: | |
bucket: "demo-techtalk-bucket" | |
event: s3:ObjectCreated:* | |
rules: | |
- suffix: .jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment