{"id":21146,"date":"2018-12-25T16:00:54","date_gmt":"2018-12-25T07:00:54","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=21146"},"modified":"2018-12-25T15:58:15","modified_gmt":"2018-12-25T06:58:15","slug":"aws-lambda-custom-runtime-%e3%82%b7%e3%82%a7%e3%83%ab%e3%82%92%e5%8b%95%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2018\/12\/25\/aws-lambda-custom-runtime-%e3%82%b7%e3%82%a7%e3%83%ab%e3%82%92%e5%8b%95%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f\/","title":{"rendered":"AWS Lambda Custom Runtime \u30b7\u30a7\u30eb\u3092\u52d5\u304b\u3057\u3066\u307f\u305f"},"content":{"rendered":"
\u3053\u308c\u306f TECHSCORE Advent Calendar 2018 \u306e25\u65e5\u76ee(\u6700\u7d42\u65e5)\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n
\u3053\u3093\u306b\u3061\u306f\u3001\u5bae\u57a3\u3067\u3059\u3002
\n\u30c6\u30c3\u30af\u30b9\u30b3\u30a2\u30d6\u30ed\u30b0\u306b\u6295\u7a3f\u3059\u308b\u306e\u306f\u7d044\u5e74\u3076\u308a\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3057\u307e\u3059\u3002<\/p>\n
\u3055\u3066\u3001\u5148\u65e5\u3001AWS re:Invent 2018\u306eKeynote Day2 \u3067 AWS Lambda \u306b\u65b0\u6a5f\u80fd\u3001Custom Runtime \u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u3053\u3068\u304c\u767a\u8868\u3055\u308c\u307e\u3057\u305f\u3002 \u4eca\u56de\u306f\u3001\u3053\u306e\u65b0\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066Lambda\u3067\u30b7\u30a7\u30eb\u3092\u52d5\u304b\u3059\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n Custom Runtime \u3092\u52d5\u304b\u3059\u305f\u3081\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u304c\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067 Tutorial \u2013 Publishing a Custom Runtime - AWS Lambda<\/a><\/p>\n \u307e\u305a\u306f\u95a2\u6570\u306e\u4f5c\u6210\u3092\u884c\u3044\u307e\u3059\u3002 \u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb#Using a Custom Runtime<\/a><\/p>\n \u306b\u6cbf\u3063\u3066\u30012\u3064\u306e\u95a2\u6570\u30d5\u30a1\u30a4\u30eb\u3092\u6e96\u5099\u3057\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u30f3\u30b0\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n bootstrap<\/strong><\/p>\n function.sh<\/strong><\/p>\n \u5b9f\u884c\u6a29\u9650\u3092\u4ed8\u4e0e\u3057zip\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u3059\u308b<\/strong><\/p>\n \u3042\u3068\u3082\u3046\u5c11\u3057\u3002<\/p>\n \u30d1\u30c3\u30b1\u30fc\u30b8\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u5f8c\u306e\u52d5\u4f5c\u78ba\u8a8d\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u306e\u4f5c\u6210\u3067\u3059\u3002 \u30fb\u30a4\u30d9\u30f3\u30c8\u540d\u3092\u6c7a\u3081\u308b\u3068\u304d\u306b\u4f55\u5ea6\u304b\u6012\u3089\u308c\u305f\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30eb\u30fc\u30eb\u306f\u6e80\u305f\u3059\u3088\u3046\u306b\uff01<\/p>\n \u30fb\u534a\u89d2\u82f1\u6570\u5b57\u306e\u307f<\/strong> \u30fb\u6700\u5927\u9577\u306f25\u6587\u5b57<\/strong> \u4e0a\u8a18\u3067\u4f5c\u6210\u3057\u305f\u300clambda-custom-runtime-for-shell.zip\u300d\u3092\u3001\u300c\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u300d\u30dc\u30bf\u30f3\u3088\u308a\u30a2\u30c3\u30d7\u3057\u3001 \u3053\u308c\u3067\u5168\u3066\u306e\u6e96\u5099\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n \u300c\u30c6\u30b9\u30c8\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u4e0b\u3057\u305f\u7d50\u679c\u304c\u4ee5\u4e0b\u3002 \u7121\u4e8b\u306b\u6210\u529f\u3057\u307e\u3057\u305f\uff01<\/strong><\/p>\n \u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u306b\u3088\u3063\u3066\u6e21\u3055\u308c\u305fJSON\u30c7\u30fc\u30bf\u3092\u30b7\u30a7\u30eb\u304c\u53d7\u3051\u53d6\u3063\u3066\u51fa\u529b(echo)\u3059\u308b\u3000\u3068\u3044\u3046\u3053\u3068\u304c\u5b9f\u73fe\u3067\u304d\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n \u307e\u305f\u3001CloudWatch Logs \u306b\u3082\u6210\u529f\u30ed\u30b0\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u4eca\u56de\u306f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057\u305f\u3060\u3051\u3067\u3059\u304c\u3001\u5165\u529b\u3055\u308c\u305f\u5024\u3092 \u65e2\u306bCustom Runtime\u95a2\u9023\u306e\u8a18\u4e8b\u306f\u4e16\u306b\u591a\u304f\u51fa\u3066\u3044\u307e\u3059\u304c\u3001\u591a\u304f\u306e\u8a00\u8a9e\u3067Lambda\u95a2\u6570\u3092\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3053\u3068\u3067\u3001\u4eca\u5f8c\u3001\u6d3b\u7528\u65b9\u6cd5\u304c\u3069\u3093\u3069\u3093\u5171\u6709\u3055\u308c\u3066\u3044\u304f\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002 Windows\u74b0\u5883\u306b\u3066\u3001bootstrap\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3057\u305f\u5f8c\u3001\u518d\u5ea6zip\u5316\u3057\u305f\u3082\u306e\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3066\u3057\u307e\u3046\u3068\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u3067\u3046\u307e\u304f\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002 \u3061\u3083\u3093\u3068\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b Linux \u4e92\u63db\u74b0\u5883\u3092\u7528\u610f\u3059\u308b\u3088\u3046\u306b\uff01\u3068\u66f8\u3044\u3066\u3044\u307e\u3057\u305f\u306e\u3067 \u3053\u308c\u306f TECHSCORE Advent Calendar 2018 \u306e25\u65e5\u76ee(\u6700\u7d42\u65e5)\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n \u3053\u3093\u306b\u3061\u306f\u3001\u5bae\u57a3\u3067\u3059\u3002
\nAWS Lambda \u304c\u30ab\u30b9\u30bf\u30e0\u30e9\u30f3\u30bf\u30a4\u30e0\u3092\u30b5\u30dd\u30fc\u30c8<\/a><\/p>\n
\n\u3053\u308c\u3092\u53c2\u8003\u306b\u3057\u306a\u304c\u3089\u3001\u4e3b\u306b\u30de\u30cd\u30b8\u30e1\u30f3\u30c8\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u5229\u7528\u3057\u3066\u5b9f\u65bd\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\uff11\uff0e\u95a2\u6570\u306e\u4f5c\u6210\u3092\u958b\u59cb<\/h2>\n
\nAWS Lambda \u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u300c\u95a2\u6570\u306e\u4f5c\u6210\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002
\n<\/a>
\n
\n\u6b21\u306b\u3001\u95a2\u6570\u306e\u8a73\u7d30\u9805\u76ee\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n
\nCustom Runtime\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u3001\u300c\u30e9\u30f3\u30bf\u30a4\u30e0\u300d\u9805\u76ee\u306f
\n\u300c\u95a2\u6570\u30b3\u30fc\u30c9\u307e\u305f\u306f\u30ec\u30a4\u30e4\u30fc\u3067\u30ab\u30b9\u30bf\u30e0\u30e9\u30f3\u30bf\u30a4\u30e0\u3092\u4f7f\u7528\u300d\u3092\u9078\u629e\u3059\u308b\u3053\u3068<\/li>\n<\/ul>\n\n
\n\u300c\u30ed\u30fc\u30eb\u300d\u9805\u76ee\u306f\u300c1\u3064\u4ee5\u4e0a\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304b\u3089\u65b0\u3057\u3044\u30ed\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u300d\u3092\u9078\u629e\u3057
\n\u4efb\u610f\u306e\u540d\u79f0\u3092\u5165\u529b\u3059\u308b\u3053\u3068
\n#\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u300cTo create an execution role\u300d\u306e\u7b87\u6240\u3068\u540c\u3058\u3053\u3068\u306b\u306a\u308b<\/li>\n<\/ul>\n<\/a><\/p>\n
\uff12\uff0e\u95a2\u6570\u30d5\u30a1\u30a4\u30eb\u306e\u6e96\u5099<\/h2>\n
\n
\n\u30d5\u30a1\u30a4\u30eb\u540d\u3092bootstrap\u3068\u3057\u305f\u5b9f\u884c\u53ef\u80fd\u306a\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002
\n\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d1\u30c3\u30b1\u30fc\u30b8\u5185\u306e bootstrap \u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u307e\u305a\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul>\n\n
\nbootstrap\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u308b\u95a2\u6570\u3067\u3001\u5b9f\u969b\u306e\u51e6\u7406\u306e\u4e2d\u8eab\u306f\u3053\u3053\u306b\u8a18\u8f09\u3057\u307e\u3059\u3002\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u826f\u3044\u3067\u3059\u3002<\/li>\n<\/ul>\n#!\/bin\/sh\n\nset -euo pipefail\n\n# \u30cf\u30f3\u30c9\u30e9\u95a2\u6570\u306e\u8aad\u307f\u8fbc\u307f\nsource $LAMBDA_TASK_ROOT\/\"$(echo $_HANDLER | cut -d. -f1).sh\"\n\nwhile true\ndo\nHEADERS=\"$(mktemp)\"\n\n# \u30a4\u30d9\u30f3\u30c8\u306e\u53d6\u5f97\nEVENT_DATA=$(curl -sS -LD \"$HEADERS\" -X GET \"http:\/\/${AWS_LAMBDA_RUNTIME_API}\/2018-06-01\/runtime\/invocation\/next\")\nREQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id \"$HEADERS\" | tr -d '[:space:]' | cut -d: -f2)\n\n# \u30cf\u30f3\u30c9\u30e9\u95a2\u6570\u306e\u5b9f\u884c\nRESPONSE=$($(echo \"$_HANDLER\" | cut -d. -f2) \"$EVENT_DATA\")\n\n# \u7d50\u679c\u3092\u8fd4\u5374\ncurl -X POST \"http:\/\/${AWS_LAMBDA_RUNTIME_API}\/2018-06-01\/runtime\/invocation\/$REQUEST_ID\/response\" -d \"$RESPONSE\"\ndone\n<\/pre>\n
function handler () {\nEVENT_DATA=$1\necho \"$EVENT_DATA\" 1>&2;\nRESPONSE=\"Echoing request: '$EVENT_DATA'\"\n\necho $RESPONSE\n}\n\n<\/pre>\n
$ chmod 755 function.sh bootstrap\n$ zip lambda-custom-runtime-for-shell.zip function.sh bootstrap\n$ ls -la\n -rw-r--r-- 1 miyagaki.y domain users 802 12\u6708 11 11:49 2018 lambda-custom-runtime-for-shell.zip\n -rwxr-xr-x 1 miyagaki.y domain users 129 12\u6708 11 11:37 2018 function.sh\n -rwxr-xr-x 1 miyagaki.y domain users 674 12\u6708 11 11:37 2018 bootstrap\n<\/pre>\n
\uff13\uff0e\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u306e\u8a2d\u5b9a<\/h2>\n
\n\u30c6\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u540d\u3092\u6c7a\u3081\u3066\u4f5c\u6210\u5b8c\u4e86\u3057\u307e\u3059\u3002
\n<\/a><\/p>\n
\n<\/a><\/p>\n
\n<\/a><\/p>\n
\uff14\uff0e\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3068\u5b9f\u884c<\/h2>\n
<\/a><\/p>\n
\n\u300c\u30cf\u30f3\u30c9\u30e9\u300d\u9805\u76ee\u306b\u30b7\u30a7\u30eb\u5185\u306e\u95a2\u6570\u540d\u300cfunction handler\u300d\u3092\u6307\u5b9a\u3057\u3066\u3001\u8a2d\u5b9a\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n
\n<\/a>
\n<\/a><\/p>\n
\n\"Echoing request: '{\\\"key1\\\":\\\"value1\\\",\\\"key2\\\":\\\"value2\\\",\\\"key3\\\":\\\"value3\\\"}'\"\n<\/pre>\n
\n<\/a><\/p>\n
\uff15\uff0e\u307e\u3068\u3081<\/h2>\n
echo<\/code>\u3059\u308b\u3060\u3051\u3067\u306a\u304f\u6574\u5f62\u3057\u3066\u8fd4\u3057\u305f\u308a\u3001\u30b5\u30fc\u30d3\u30b9\u6b7b\u6d3b\u76e3\u8996\u306e\u4ed5\u7d44\u307f\u3092\u4f5c\u3063\u3066\u307f\u305f\u308a\u3057\u3066\u307f\u308b\u3068\u3068\u9762\u767d\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n
\n#\u30ad\u30fc\u30ef\u30fc\u30c9\uff1aAWS Lambda Custom Runtimes\u82b8\u4eba<\/p>\n\u304a\u307e\u3051\uff0eCustom Runtime\u5b9f\u884c\u30a8\u30e9\u30fc<\/h2>\n
\n\/var\/task\/bootstrap : permission denied<\/span><\/strong>
\n<\/a><\/p>\n
\n\u95a2\u6570\u30d5\u30a1\u30a4\u30eb\u306b\u300c\u5b9f\u884c\u6a29\u9650\u300d\u3092\u4ed8\u4e0e\u3059\u308b\u8a2d\u5b9a\u306f\u91cd\u8981\u3067\u3059\u306d\u3002
\n#\u554f\u984c\u89e3\u6c7a\u306b\u5354\u529b\u3057\u3066\u304f\u308c\u305f\u3000\u938c\u7530\u60a0\u5e73 \u7de8\u96c6\u9577<\/a> \u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002m(_ _)m<\/p>\n","protected":false},"excerpt":{"rendered":"
\n\u30c6\u30c3\u30af\u30b9\u30b3\u30a2\u30d6\u30ed\u30b0\u306b\u6295\u7a3f\u3059\u308b\u306e\u306f\u7d044\u5e74\u3076\u308a\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3057\u307e\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[308,18],"tags":[],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/21146"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=21146"}],"version-history":[{"count":44,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/21146\/revisions"}],"predecessor-version":[{"id":21910,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/21146\/revisions\/21910"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=21146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=21146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=21146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}