Skip to content

Instantly share code, notes, and snippets.

@sime sime/hanlder.js
Created May 25, 2017

Embed
What would you like to do?
TechTalk: Serverless Framework, 24 May 2015
'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`);
});
}
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
You can’t perform that action at this time.