Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9173

Node.js の Lambda 関数を ローカルでテストする (その2)

$
0
0

AWS のコンソールから、ダウンロードして解凍した index.js を実行する方法です。

download_package.png

フォルダー構造

$ tree example01/
example01/
├── index.js
└── test_local.js
index.js
exports.handler=async(event)=>{// TODO implementconsole.error("***** start example01 PM 18:49 ***")varrvalue={}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'constresponse={statusCode:200,body:JSON.stringify(rvalue),};console.error("***** end example01 ***")returnresponse;};
test_local.js

#! /usr/bin/node
// ---------------------------------------------------------------//  test_local.js////                  Jun/06/2020//// ---------------------------------------------------------------varfs=require("fs")varexample01=require('../example01')// ---------------------------------------------------------------console.error("*** 開始 *** test_local.js ***")constevent={"key1":11,"key2":21,"key3":31}constcontext=""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 ***

Viewing all articles
Browse latest Browse all 9173

Trending Articles