forked from dherault/serverless-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
99 lines (82 loc) · 2.26 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'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);
};
module.exports.rejectedPromise = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
console.log('About to reject promise');
Promise.reject(new Error('This is the rejected error'));
callback(null, response);
};
module.exports.authFunction = (event, context, callback) => {
context.succeed({
principalId: 'xxxxxxx', // the principal user identification associated with the token send by the client
policyDocument: {
// example policy shown below, but this value is any valid policy
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['execute-api:Invoke'],
Resource: [event.methodArn],
},
],
},
});
};
module.exports.hello500 = (event, context, callback) => {
const response = {
statusCode: 500,
body: JSON.stringify({
message: 'Fake internal server error.',
input: event,
}),
};
callback(null, response);
};
module.exports.helloLambdaIntegration = (event, context, cb) => {
cb(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
module.exports.helloLambdaIntegration500 = (event, context, cb) => {
cb(new Error('[500] Fake internal server error.'));
};
module.exports.basicAuthentication = (event, context, cb) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Private Function Executed Correctly',
}),
};
cb(null, response);
};
module.exports.catchAll = (event, context, cb) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Catch all route',
}),
};
cb(null, response);
};
module.exports.pathParams = (event, context, cb) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: `id is ${event.pathParameters.id}`,
}),
};
cb(null, response);
};