{"id":606,"date":"2020-01-27T09:00:00","date_gmt":"2020-01-27T00:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/01\/27\/lambda-node"},"modified":"2020-01-27T09:00:00","modified_gmt":"2020-01-27T00:00:00","slug":"lambda-node","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/01\/27\/lambda-node\/","title":{"rendered":"AWS Lambda\u5165\u9580 Node.js"},"content":{"rendered":"

\u571f\u5c45\u3067\u3059\u3002\u8d64\u3061\u3083\u3093\u304c\u751f\u5f8c4\u304b\u6708\u3092\u8fce\u3048\u3066\u3001\u4f53\u91cd\u3082\u751f\u307e\u308c\u305f\u6642\u306e\u500d\u4ee5\u4e0a\u306b\u306a\u308a\u3001\u4f55\u5ea6\u3082\u62b1\u3063\u3053\u3057\u3066\u3044\u308b\u3068\u304b\u306a\u308a\u8155\u3084\u624b\u9996\u306b\u75b2\u308c\u3084\u75db\u307f\u304c\u304f\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002\u4e00\u751f\u3067\u3082\u3063\u3068\u3082\u6210\u9577\u3059\u308b\u3053\u306e\u6642\u671f\u3001\u4f53\u306e\u5927\u304d\u3055\u3060\u3051\u3067\u306a\u304f\u3055\u307e\u3056\u307e\u306a\u5909\u5316\u3092\u65e5\u3005\u5b9f\u611f\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n

\u4eca\u56de\u306fAWS Lambda\u5165\u9580\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u5404\u8a00\u8a9e\u3067\u7c21\u5358\u306a\u8a00\u8a9e\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\uff01
\n\u7b2c1\u56de\u306fNode.js\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

TypeScript<\/h2>\n

TypeScript\u3067\u66f8\u304f\u5834\u5408\u3001\u4ee5\u4e0b\u3092\u5c0e\u5165\u3057\u307e\u3059\u3002<\/p>\n

# yarn add typescript ts-node<\/code><\/pre>\n

TypeScript\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u6e96\u5099\u3057\u307e\u3059\u3002<\/p>\n

{\n  "compilerOptions": {\n    "module": "commonjs",\n    "lib": ["ES2015", "DOM"],\n    "outDir": ".\/dist",\n    "strict": true,\n    "baseUrl": ".\/",\n    "esModuleInterop": true,\n  }\n}<\/code><\/pre>\n

Serverless Framework<\/h2>\n

Serverless Framework\u3092\u4f7f\u3063\u3066\u30b5\u30af\u3063\u3068\u30c7\u30d7\u30ed\u30a4\u3057\u307e\u3059\u3002
\n\u203b\u5229\u7528\u3059\u308bAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u306ecredentials\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059<\/a><\/p>\n

# yarn add serverless<\/code><\/pre>\n

Lambda\u3078\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u95a2\u6570\u306e\u5b9a\u7fa9<\/h2>\n

\u30ed\u30b0\u51fa\u529b\u3057\u3066\u3001\u53d7\u3051\u53d6\u3063\u305fevent\u5f15\u6570\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059\u3060\u3051\u306e\u95a2\u6570<\/p>\n

export const hello = async (event: any) => {\n  const hello: string = 'hello world'\n  console.log(hello)\n  const response = JSON.stringify(event, null, 2)\n  return response;\n}<\/code><\/pre>\n

\u5b9a\u7fa9\u3057\u305f\u95a2\u6570\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u8a2d\u5b9a\u3092\u8a18\u8ff0\u3057\u307e\u3059
\n\u203bfunctions\u306ehandler\u306b\u306f\u3001tsc\u3067\u51fa\u529b\u3055\u308c\u308b\u30d3\u30eb\u30c9\u5f8c\u306e\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u95a2\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n

service: hello\nprovider:\n  name: aws\n  runtime: nodejs12.x\nfunctions:\n  hello:\n    handler: dist\/handler.hello<\/code><\/pre>\n

scripts\u306b\u30d3\u30eb\u30c9\u3068\u30c7\u30d7\u30ed\u30a4\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n

...\n"scripts": {\n    "build": "tsc",\n    "deploy": "yarn build && sls deploy"\n  }\n...<\/code><\/pre>\n

\u30c7\u30d7\u30ed\u30a4<\/h2>\n

\u4ee5\u4e0b\u3092\u5b9f\u884c\u3057\u3001TypeScript\u304b\u3089\u306e\u30d3\u30eb\u30c9\u3001Serverless Framework\u306b\u3088\u308b\u30c7\u30d7\u30ed\u30a4\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n

# yarn deploy<\/code><\/pre>\n

\u30c7\u30d7\u30ed\u30a4\u304c\u6210\u529f\u3057\u305f\u3089\u3001\u95a2\u6570\u540d\u304c\u8fd4\u308a\u307e\u3059\u3002<\/p>\n

...\nfunctions:\n  hello: hello-dev-hello\n...<\/code><\/pre>\n

\u95a2\u6570\u306e\u30c6\u30b9\u30c8<\/h2>\n

\u30b3\u30f3\u30bd\u30fc\u30eb\u3088\u308a\u3001\u30c7\u30d7\u30ed\u30a4\u3057\u305f\u95a2\u6570\u3092\u30c6\u30b9\u30c8\u5b9f\u884c\u3057\u3066\u52d5\u4f5c\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n

\u95a2\u6570\u3092\u9078\u629e<\/h3>\n

\"\"<\/p>\n

\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210<\/h3>\n

\"\"<\/p>\n

\u5f15\u6570\u306e\u8a2d\u5b9a<\/h3>\n

\"\"<\/p>\n

\u30c6\u30b9\u30c8\u5b9f\u884c<\/h3>\n

\"\"<\/p>\n

\u7d50\u679c\u3092\u78ba\u8a8d<\/h3>\n

\"\"
\nconsole.log\u3082\u51fa\u529b\u3055\u308c\u3066\u3044\u307e\u3059\u3002
\n\"\"<\/p>\n

\u307e\u3068\u3081<\/h2>\n

\u4eca\u56de\u306fNode.js\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3057\u305f\u3002\u3053\u308c\u304b\u3089\u3082\u4ed6\u8a00\u8a9e\u3084\u3001\u3055\u307e\u3056\u307e\u306a\u624b\u9806\u3092\u7d39\u4ecb\u3067\u304d\u305f\u3089\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

MMM\u3067\u306f2020\u5e74\u3088\u308a\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30fb\u30b3\u30f3\u30d4\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u30d3\u30b8\u30cd\u30b9\u6d3b\u7528\u306b\u3068\u304f\u306b\u6ce8\u529b\u3057\u3066\u53c2\u308a\u307e\u3059\u3002
\n\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u958b\u767a\u306b\u8208\u5473\u306e\u3042\u308b\u65b9\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3082\u662f\u975e\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u30fb\u306a\u305c\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u304c\u6ce8\u76ee\u3055\u308c\u3066\u3044\u308b\u306e\u304b\uff1f\u30bc\u30ed\u304b\u3089\u5b66\u3076\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\uff08FaaS\uff09\u5165\u9580<\/a><\/p>\n

\u30fb\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\uff08AWS Lambda\uff09 | \u682a\u5f0f\u4f1a\u793eMMM(\u30a8\u30e0\u30a8\u30e0\u30a8\u30e0)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u571f\u5c45\u3067\u3059\u3002\u8d64\u3061\u3083\u3093\u304c\u751f\u5f8c4\u304b\u6708\u3092\u8fce\u3048\u3066\u3001\u4f53\u91cd\u3082\u751f\u307e\u308c\u305f\u6642\u306e\u500d\u4ee5\u4e0a\u306b\u306a\u308a\u3001\u4f55\u5ea6\u3082\u62b1\u3063\u3053\u3057\u3066\u3044\u308b\u3068\u304b\u306a\u308a\u8155\u3084\u624b\u9996\u306b\u75b2\u308c\u3084\u75db\u307f\u304c\u304f\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002\u4e00\u751f\u3067\u3082\u3063\u3068\u3082\u6210\u9577\u3059\u308b\u3053\u306e\u6642\u671f\u3001\u4f53\u306e\u5927\u304d\u3055\u3060\u3051\u3067\u306a\u304f\u3055\u307e\u3056\u307e\u306a\u5909\u5316\u3092\u65e5\u3005\u5b9f\u611f\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002 \u4eca\u56de\u306fAWS Lambda\u5165\u9580\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u5404\u8a00\u8a9e\u3067\u7c21\u5358\u306a\u8a00\u8a9e\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\uff01 \u7b2c1\u56de\u306fNode.js\u306b\u306a\u308a\u307e\u3059\u3002 TypeScript Ty […]<\/p>\n","protected":false},"author":11,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,21],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/606"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}