AWS のコンソールから、ダウンロードして解凍した index.js を実行する方法です。
フォルダー構造
$ tree example01/
example01/
├── index.js
└── test_local.js
index.js
exports.handler = async (event) => {
// TODO implement
console.error("***** start example01 PM 18:49 ***")
var rvalue = {}
rvalue['key1'] = parseInt(event['key1'],10)
rvalue['key2'] = parseInt(event['key2'],10)
rvalue['key3'] = parseInt(event['key3'],10)
rvalue['sum'] = rvalue['key1']+ rvalue['key2'] + rvalue['key3']
rvalue['message'] = 'Hello from example01'
const response = {
statusCode: 200,
body: JSON.stringify(rvalue),
};
console.error("***** end example01 ***")
return response;
};
test_local.js
#! /usr/bin/node
// ---------------------------------------------------------------
// test_local.js
//
// Jun/06/2020
//
// ---------------------------------------------------------------
var fs = require("fs")
var example01 = require('../example01')
// ---------------------------------------------------------------
console.error ("*** 開始 *** test_local.js ***")
const event = {
"key1": 11,
"key2": 21,
"key3": 31
}
const context = ""
rvalue = example01.handler(event)
console.log(rvalue)
console.error ("*** 終了 *** test_local.js ***")
// ---------------------------------------------------------------
実行結果
$ ./test_local.js
*** 開始 *** test_local.js ***
***** start example01 PM 18:49 ***
***** end example01 ***
Promise {
{
statusCode: 200,
body: '{"key1":11,"key2":21,"key3":31,"sum":63,"message":"Hello from example01"}'
}
}
*** 終了 *** test_local.js ***