{"id":1164,"date":"2020-01-02T21:31:28","date_gmt":"2020-01-02T12:31:28","guid":{"rendered":"http:\/\/168.138.214.208\/?p=1164"},"modified":"2020-01-02T21:40:36","modified_gmt":"2020-01-02T12:40:36","slug":"post-1164","status":"publish","type":"post","link":"https:\/\/nobunobu1717.site\/?p=1164","title":{"rendered":"AWS Lambda\u306bTypescript\u3067\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u6982\u8981<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u524d\u63d0<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u624b\u9806<\/a><\/li><li><a href=\"#i-4\"><span class=\"toc_number toc_depth_1\">4<\/span> \u5b9f\u88c5\u3068\u30d3\u30eb\u30c9<\/a><\/li><\/ul><\/div>\n<h2><span id=\"i\">\u6982\u8981<\/span><\/h2>\n<p>AWS Lambda\u3067Typescript\u3092\u4f7f\u7528\u3057\u305f\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3002<\/p>\n<h2><span id=\"i-2\">\u524d\u63d0<\/span><\/h2>\n<p>\u4e0b\u8a18\u306e\u74b0\u5883\u3067\u5b9f\u65bd<br \/>\nmacOS 10.15.2<br \/>\nVSCode 1.41.1<\/p>\n<p>\u4e0b\u8a18\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u3068\u3059\u308b<br \/>\nnode.js (v12.14.0)<br \/>\nyarn (v1.17.3)<\/p>\n<h2><span id=\"i-3\">\u624b\u9806<\/span><\/h2>\n<p>\u4e0b\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210\u3068\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\ntest_func1\r\n|-src\r\n|  |- index.ts\r\n|-package.json\r\n|-tsconfig.json\r\n|-build.sh\r\n\r\n<\/pre>\n<p>1. src\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4ee5\u4e0b\u306b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u683c\u7d0d<br \/>\n2. build.sh\u3092\u4f7f\u7528\u3057\u3066Lambda\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b<\/p>\n<h3>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210<\/h3>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210\u3092\u884c\u3046\u3002<br \/>\n(test_func1\u306e\u90e8\u5206\u306f\u5404\u81ea\u3067\u4efb\u610f\u306e\u540d\u79f0\u3092\u8a2d\u5b9a\u3002)<\/p>\n<pre class=\"lang:default decode:true \" >mkdir test_func1\r\ncd test_func1\r\nmkdir src<\/pre>\n<h3>yarn\u521d\u671f\u5316<\/h3>\n<p>package.json\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >cd test_func1\r\nyarn init<\/pre>\n<p>yarn\u3067\u5fc5\u8981\u6700\u4f4e\u9650\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\nyarn add -D typescript @types\/node @types\/aws-lambda\r\n<\/pre>\n<h3>Typescript\u521d\u671f\u5316<\/h3>\n<p>typescript\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u3092\u884c\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\n.\/node_modules\/.bin\/tsc --init\r\n<\/pre>\n<p>tsconfig.json\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<br \/>\n\u4e0b\u8a18\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<br \/>\n\u4e00\u4f8b\u306a\u306e\u3067\u3001\u8a2d\u5b9a\u306f\u76ee\u7684\u306b\u5fdc\u3058\u3066\u5909\u66f4\u3059\u308b\u4e8b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\n{\r\n  \"compilerOptions\": {\r\n    \"module\": \"commonjs\",\r\n    \"target\": \"es6\",\r\n    \"declaration\": false,\r\n    \"removeComments\": true,\r\n    \"sourceMap\": false,\r\n    \"outDir\": \".\/dist\",\r\n    \"baseUrl\": \".\/src\"\r\n  },\r\n  \"exclude\": [\"node_modules\"]\r\n}\r\n<\/pre>\n<h3>\u30d3\u30eb\u30c9\u7528\u8a2d\u5b9a<\/h3>\n<h4>\u30b7\u30a7\u30eb\u306e\u4f5c\u6210<\/h4>\n<p>test_func1\u30d5\u30a9\u30eb\u30c0\u76f4\u4e0b\u306b\u3001build.sh\u3092\u4f5c\u6210\u3057\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true \">#!\/bin\/sh\r\necho remove dir and zip\r\nrm -rf dist\/\r\n\r\necho compile ts\r\ntsc -p tsconfig.json\r\n\r\necho copy package.json\r\ncp -f .\/package.json .\/dist\r\n\r\necho install module\r\ncd dist\r\nyarn install\r\n\r\necho zip \r\nzip -r dist.zip .\/<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u4e8b\u3068\u3057\u3066\u306f\u4e0b\u8a18<br \/>\n1. \u4ee5\u524d\u306e\u30d3\u30eb\u30c9\u7d50\u679c\u306e\u524a\u9664<br \/>\n2. Typescript\u306e\u30d3\u30eb\u30c9<br \/>\n3. \u30d3\u30eb\u30c9\u5148\u306bpackage.json\u3092\u30b3\u30d4\u30fc<br \/>\n4. \u30d3\u30eb\u30c9\u5148\u3067yarn\u3067node_module\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\n5. zip\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210<\/p>\n<h4>\u8a2d\u5b9a<\/h4>\n<p>package.json\u306b\u4f5c\u6210\u3057\u305f\u30d3\u30eb\u30c9\u7528\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >{\r\n  \/\/ \u7565\r\n  \"scripts\": {\r\n    \"build\": \"sh .\/build.sh\"\r\n  },\r\n  \/\/ \u7565\r\n}\r\n<\/pre>\n<p>\u4ee5\u4e0a\u3067\u6e96\u5099\u306f\u7d42\u4e86\u3002<\/p>\n<h2><span id=\"i-4\">\u5b9f\u88c5\u3068\u30d3\u30eb\u30c9<\/span><\/h2>\n<h3>\u30b5\u30f3\u30d7\u30eb\u7528\u30b3\u30fc\u30c9<\/h3>\n<p>src\/index.ts\u3092\u4f5c\u6210\u3057\u3066\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3002<\/p>\n<pre class=\"lang:js decode:true \" >import * as lambda from 'aws-lambda';\r\n\r\nexport const handler = (\r\n  event: any,\r\n  context: lambda.Context,\r\n  callback: lambda.Callback\r\n) =&gt; {\r\n  const response = {\r\n    statusCode: 200,\r\n    body: JSON.stringify({\r\n      message: 'This is a lambda testing'\r\n    })\r\n  };\r\n\r\n  callback(null, response);\r\n};\r\n<\/pre>\n<h3>\u30d3\u30eb\u30c9<\/h3>\n<p>yarn run build\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3001dist\/dist.zip\u304c\u4f5c\u6210\u3067\u304d\u308c\u3070\u6210\u529f<br \/>\ndist.zip\u3092CLI\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u7b49\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u6982\u89812 \u524d\u63d03 \u624b\u98064 \u5b9f\u88c5\u3068\u30d3\u30eb\u30c9 \u6982\u8981 AWS Lambda\u3067Typescript\u3092\u4f7f\u7528\u3057\u305f\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3002 \u524d\u63d0 \u4e0b\u8a18\u306e\u74b0\u5883\u3067\u5b9f\u65bd macOS 10.15 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,16,24],"tags":[],"_links":{"self":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1164"}],"collection":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1164"}],"version-history":[{"count":8,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1164\/revisions"}],"predecessor-version":[{"id":1171,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1164\/revisions\/1171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/media\/1170"}],"wp:attachment":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}