{"size": 1284, "ext": "js", "max_stars_repo_path": "functions/index.js", "max_stars_repo_name": "AppGambitStudio/serverless-testing", "max_stars_repo_stars_event_min_datetime": "2021-08-12T12:52:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T22:08:39.000Z", "max_issues_repo_path": "functions/index.js", "max_issues_repo_name": "AppGambitStudio/serverless-testing", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "functions/index.js", "max_forks_repo_name": "AppGambitStudio/serverless-testing", "max_forks_repo_forks_event_min_datetime": "2021-08-18T05:41:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-18T05:41:31.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.6923076923, "max_line_length": 66, "alphanum_fraction": 0.5607476636}
"use strict";
const { helloWorld } = require('../lib/util');
const AWS = require('aws-sdk');

let lambda;

const getLambdaObj = () => {    
    if(lambda) return lambda;

    if(process.env.IS_OFFLINE){
        require('dotenv').config();
        lambda = new AWS.Lambda({
            region: process.env.AWS_REGION,
            endpoint: process.env.LAMBDA_ENDPOINT,
            credentials: new AWS.Credentials({
                accessKeyId: 'fake',
                secretAccessKey: 'fake'
            })
        });
    }else{
        lambda = new AWS.Lambda({});
    }

    return lambda;
}

module.exports.hello = async (event, context) => {    
    const { name } = event.queryStringParameters || event;
    const params = {
        FunctionName: process.env.WORLD_FUNC,
        InvocationType: 'RequestResponse',
        Payload: JSON.stringify({ val: name }),
    }
    
    const response = await getLambdaObj().invoke(params).promise()
    const res = JSON.parse(response.Payload);

    return {
        statusCode: 200,
        body: JSON.stringify({
            message: res.message
        })
    };
}

module.exports.world = async (event, context) => {
    const { val } = event;
    const message = helloWorld(val);
    return {        
        message: message
    }
}