2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS Lambdaのマネジメントコンソールでjsを複数ファイルとして使う

Last updated at Posted at 2022-06-24
  • index.js だけでなく、別のjsファイルに書き、そのjsファイルをどう使うか確かめた時の情報です

jsファイルの配置等の画面キャプチャ

  • ものすごく手軽だった。zip圧縮でのソースコードアップと似てる
  • 左のツリー

index.js


var myfunc = require('./myfunc.js');

exports.handler = async (event) => {
  console.log(`EVENT: ${JSON.stringify(event)}`);

  myfunc.dummy21();
  myfunc.foo();

  const response = {
    statusCode: 200,
    body: JSON.stringify('success.'),
  };
  return response;
};

myfunc.js

// モジュール定義
module.exports = {
    foo: function () {
        console.log("foo");
    },
    bar: function (v1, v2) {
        console.log("bar");
    }
};

module.exports.dummy21 = function () {
    console.log("dummy21") ;
};

実行結果

Test Event Name
20220624-1

Response
{
  "statusCode": 200,
  "body": "\"success.\""
}

Function Logs
START RequestId: b336b9f8-ae3e-49e5-9073-46ce62ce8f4a Version: $LATEST
2022-06-24T14:44:53.043Z	b336b9f8-ae3e-49e5-9073-46ce62ce8f4a	INFO	EVENT: {"key1":"value1","key2":"value2","key3":"value3"}
2022-06-24T14:44:53.043Z	b336b9f8-ae3e-49e5-9073-46ce62ce8f4a	INFO	dummy21
2022-06-24T14:44:53.043Z	b336b9f8-ae3e-49e5-9073-46ce62ce8f4a	INFO	foo
END RequestId: b336b9f8-ae3e-49e5-9073-46ce62ce8f4a
REPORT RequestId: b336b9f8-ae3e-49e5-9073-46ce62ce8f4a	Duration: 4.97 ms	Billed Duration: 5 ms	Memory Size: 128 MB	Max Memory Used: 56 MB	Init Duration: 158.70 ms

Request ID
b336b9f8-ae3e-49e5-9073-46ce62ce8f4a

AWSマネジメントコンソールでのソースコード画面

  • myfunc.js

  • Execution Result

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?