Skip to content

Commit b9f420c

Browse files
dhaval nagardhaval nagar
dhaval nagar
authored and
dhaval nagar
committed
initial commit
1 parent 6fec0b1 commit b9f420c

13 files changed

+9985
-0
lines changed

functions/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
const { helloWorld } = require('../lib/util');
3+
const { Lambda } = require('aws-sdk');
4+
5+
let lambda;
6+
7+
const getLambda = () => {
8+
console.log('Using Local Lambda Endpoint');
9+
if(process.env.IS_OFFLINE){
10+
lambda = new Lambda({
11+
region: 'us-east-1',
12+
endpoint: process.env.LAMBDA_ENDPOINT
13+
});
14+
}else{
15+
lambda = new Lambda({});
16+
}
17+
18+
return lambda;
19+
}
20+
21+
lambda = getLambda();
22+
23+
module.exports.hello = async (event, context) => {
24+
const { name } = event.queryStringParameters || event;
25+
const params = {
26+
FunctionName: process.env.WORLD_FUNC,
27+
InvocationType: 'RequestResponse',
28+
Payload: JSON.stringify({ val: name }),
29+
}
30+
31+
if(!lambda){
32+
lambda = getLambda();
33+
}
34+
35+
const response = await lambda.invoke(params).promise()
36+
const res = JSON.parse(response.Payload);
37+
38+
return {
39+
statusCode: 200,
40+
body: JSON.stringify({
41+
message: res.message
42+
})
43+
};
44+
}
45+
46+
module.exports.world = async (event, context) => {
47+
const { val } = event;
48+
const message = helloWorld(val);
49+
return {
50+
message: message
51+
}
52+
}

functions/reverseFunc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { reverseStr } = require('../lib/util');
2+
3+
module.exports.handler = async (event, context) => {
4+
const { val } = event.queryStringParameters || event;
5+
const revVal = reverseStr(val);
6+
7+
return {
8+
statusCode: 200,
9+
body: JSON.stringify({
10+
val: revVal
11+
})
12+
};
13+
}

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
setupFiles: [
3+
'dotenv/config'
4+
],
5+
}

lib/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
const funcs = {
3+
helloWorld : (val) => {
4+
return `Hello world to ${val}`
5+
},
6+
7+
reverseStr : (val) => {
8+
return val.split('').reverse().join('');
9+
}
10+
}
11+
12+
module.exports = funcs;

0 commit comments

Comments
 (0)