{"id":15750,"date":"2018-12-04T18:27:55","date_gmt":"2018-12-04T09:27:55","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=15750"},"modified":"2018-12-04T18:46:00","modified_gmt":"2018-12-04T09:46:00","slug":"reinvent2018%e3%81%a7%e7%99%ba%e8%a1%a8%e3%81%95%e3%82%8c%e3%81%9falb%e3%83%90%e3%83%83%e3%82%af%e3%82%a8%e3%83%b3%e3%83%89lambda%e3%82%92%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/reinvent2018%e3%81%a7%e7%99%ba%e8%a1%a8%e3%81%95%e3%82%8c%e3%81%9falb%e3%83%90%e3%83%83%e3%82%af%e3%82%a8%e3%83%b3%e3%83%89lambda%e3%82%92%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f\/","title":{"rendered":"re:Invent2018\u3067\u767a\u8868\u3055\u308c\u305fALB\u30d0\u30c3\u30af\u30a8\u30f3\u30c9Lambda\u3092\u8a66\u3057\u3066\u307f\u305f"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>ALB\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u5148\u306bLambda\u3092\u6307\u5b9a\u3057\u3066\u3001URL\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304b\u3089\u8db3\u3057\u7b97\u304c\u3067\u304d\u308b\u30da\u30fc\u30b8\u3092\u8efd\u304f\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f<\/p>\n<p>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306bJinja2\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059<\/p>\n<h2>\u76ee\u6b21<\/h2>\n<ul>\n<li><a href=\"#nagare\">\u6d41\u308c<\/a><\/li>\n<li><a href=\"#overview\">\u624b\u9806\u306e\u6982\u8981<\/a><\/li>\n<li><a href=\"#env\">\u5b9f\u884c\u74b0\u5883<\/a><\/li>\n<li><a href=\"#tejun\">\u624b\u9806<\/a><\/li>\n<li><a href=\"#matome\">\u307e\u3068\u3081<\/a><\/li>\n<\/ul>\n<h2 id=\"nagare\">\u6d41\u308c<\/h2>\n<p>ALB\u306eURL\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6e21\u3059\u3068\u8db3\u3057\u7b97\u3057\u305f\u7d50\u679c\u304c\u5e30\u3063\u3066\u304f\u308b\u3068\u3044\u3046\u52d5\u304d\u3067\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Untitled-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Untitled-Diagram.png\" alt=\"\" width=\"422\" height=\"110\" class=\"alignnone size-full wp-image-15809\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Untitled-Diagram.png 422w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Untitled-Diagram-300x78.png 300w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/a>\n<h2 id=\"overview\">\u624b\u9806\u306e\u6982\u8981<\/h2>\n<ol>\n<li>\u95a2\u6570\u306e\u4f5c\u6210<\/li>\n<li>\u30ec\u30b9\u30dd\u30f3\u30b9\u8a2d\u5b9a\u306b\u3064\u3044\u3066<\/li>\n<li>ALB\u306e\u4f5c\u6210<\/li>\n<li>\u63a5\u7d9a\u78ba\u8a8d<\/li>\n<\/ol>\n<h2 id=\"env\">\u5b9f\u884c\u74b0\u5883<\/h2>\n<p>Python3.6.5<br \/>\nJinja2<\/p>\n<h2 id=\"tejun\">\u624b\u9806<\/h2>\n<h3>\u6e96\u5099<\/h3>\n<p>\u672c\u6765\u3067\u3042\u308c\u3070pip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u304c\u4e8b\u524d\u306b\u7528\u610f\u3057\u305fLambdalayers\u3092\u4f7f\u7528\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u9020\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5f62\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-04-18-13-09.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-04-18-13-09.png\" alt=\"\" width=\"195\" height=\"78\" class=\"alignnone size-full wp-image-15808\" \/><\/a>\n<h3>\u95a2\u6570\u306e\u4f5c\u6210<\/h3>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfrom jinja2 import Environment, FileSystemLoader\r\n\r\ndef lambda_handler(event, context):\r\n    # jinja\r\n    env = Environment(loader=FileSystemLoader('.\/', encoding='utf8'))\r\n    result = env.get_template('result.html')\r\n\r\n    answer = &quot;&quot;\r\n\r\n    if event&#x5B;'path'] == &quot;\/&quot;:\r\n        if event&#x5B;'queryStringParameters'] == &quot;&quot;:\r\n            answer = &quot;\u4f55\u304b\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044&quot;\r\n        else:\r\n            i = event&#x5B;'queryStringParameters']\r\n            print(i)\r\n            answer = int(i&#x5B;&quot;calc1&quot;]) + int(i&#x5B;&quot;calc2&quot;])\r\n    print(answer)\r\n    html = result.render({'answer':answer})\r\n\r\n    response = {\r\n        &quot;statusCode&quot;: 200,\r\n        &quot;statusDescription&quot;: &quot;200 OK&quot;,\r\n        &quot;isBase64Encoded&quot;: False,\r\n        &quot;headers&quot;: {\r\n            &quot;Content-Type&quot;: &quot;text\/html; charset=utf-8&quot;\r\n        },\r\n        &quot;body&quot;: html\r\n    }\r\n    \r\n    return response\r\n<\/pre>\n<p>\u4e0a\u304b\u3089event['path']\u306b\u3066\u30d1\u30b9\u3092\u53d6\u5f97\u3057event['queryStringParameters']\u306b\u3066\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d6\u5f97\u3057\u305f\u5f8c\u306b\u8a08\u7b97\u3092\u3057\u3001jinja\u306e\u30ec\u30f3\u30c0\u30fc\u306b\u6e21\u3059\u5f62\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>event\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3053\u306e\u3088\u3046\u306a\u5185\u5bb9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n    &quot;requestContext&quot;: {\r\n        &quot;elb&quot;: {\r\n            &quot;targetGroupArn&quot;: &quot;arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:targetgroup\/lambda-http-test\/xxxxxxxxxxxx&quot;\r\n        }\r\n    },\r\n    &quot;httpMethod&quot;: &quot;GET&quot;,\r\n    &quot;path&quot;: &quot;\/&quot;,\r\n    &quot;queryStringParameters&quot;: {\r\n        &quot;calc1&quot;: &quot;12&quot;,\r\n        &quot;calc2&quot;: &quot;22&quot;\r\n    },\r\n    &quot;headers&quot;: {\r\n        &quot;accept&quot;: &quot;*\/*&quot;,\r\n        &quot;host&quot;: &quot;lambdahttp-xxxxxxxxxx.ap-northeast-1.elb.amazonaws.com&quot;,\r\n        &quot;user-agent&quot;: &quot;curl\/7.47.0&quot;,\r\n        &quot;x-amzn-trace-id&quot;: &quot;Root=x-xxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx&quot;,\r\n        &quot;x-forwarded-for&quot;: &quot;xxx.xxx.xx.xx&quot;,\r\n        &quot;x-forwarded-port&quot;: &quot;80&quot;,\r\n        &quot;x-forwarded-proto&quot;: &quot;http&quot;\r\n    },\r\n    &quot;body&quot;: &quot;&quot;,\r\n    &quot;isBase64Encoded&quot;: false\r\n}\r\n<\/pre>\n<p>\u30ec\u30b9\u30dd\u30f3\u30b9\u306b\u3064\u3044\u3066\u306fAPIGateway\u306e\u6642\u3068\u306f\u9055\u3044\u5fc5\u305a\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306eHTML\u3092\u4f5c\u6210<\/h3>\n<p>\u4ee5\u4e0b\u306e\u3082\u306e\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=&quot;en&quot;&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\r\n    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;\r\n    &lt;title&gt;saba&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\u7b54\u3048\u306f{{ answer }}\u3067\u3059\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u3068\u304f\u306b\u3044\u3058\u3063\u3066\u3044\u308b\u90e8\u5206\u3082\u306a\u304f\u901a\u5e38\u306eJinja2\u306e\u66f8\u304d\u65b9\u3067OK\u3067\u3059\u3002<\/p>\n<h3>ALB\u306e\u4f5c\u6210<\/h3>\n<p>ALB\u304b\u3089\u5b9f\u969b\u306bLambda\u3092\u63a5\u7d9a\u3057\u307e\u3059<\/p>\n<p><a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f62e4264.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f62e4264.png\" alt=\"\" width=\"529\" height=\"425\" class=\"alignnone size-full wp-image-15804\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f62e4264.png 529w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f62e4264-300x241.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/a><br \/>\n\u3053\u3061\u3089\u306eApplication Load Balancer\u3067\u3059\u306d\u3002<\/p>\n<p>\u300c4.\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u300d\u307e\u3067\u3068\u304f\u306b\u3044\u3058\u308b\u90e8\u5206\u306f\u3042\u308a\u307e\u305b\u3093\u540d\u524d\u3092\u3064\u3051\u3001\u30a2\u30d9\u30a4\u30e9\u30d3\u30ea\u30c6\u30a3\u30fc\u30be\u30fc\u30f3\u306b\u306f\u4efb\u610f\u306e\u3082\u306e\u306b\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002\uff08\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7\u306a\u3069\u8a2d\u5b9a\u3059\u308b\u5834\u5408\u306f\u5225\u3067\u3059\u3002\uff09<\/p>\n<p>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u3067\u306f\u4ee5\u4e0b\u306e\u5834\u6240\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u4eca\u56de\u4f5c\u6210\u3057\u305fLambda\u3092\u9078\u629e\u3057\u307e\u3059<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7f120f11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7f120f11.png\" alt=\"\" width=\"586\" height=\"329\" class=\"alignnone size-full wp-image-15805\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7f120f11.png 586w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7f120f11-300x168.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7f120f11-240x135.png 240w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/a><\/p>\n<p>5.\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u767b\u9332\u306b\u79fb\u52d5\u3057\u30ea\u30b9\u30c8\u304b\u3089Lambda\u95a2\u6570\u3092\u9078\u629e\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f79e3473.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f79e3473.png\" alt=\"\" width=\"519\" height=\"240\" class=\"alignnone size-full wp-image-15806\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f79e3473.png 519w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/f79e3473-300x139.png 300w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/a><\/p>\n<h3>\u63a5\u7d9a\u78ba\u8a8d<\/h3>\n<p>URL\u6b04\u306b ALB\u306eDNS+?calc1=12&amp;calc2=12\u3092\u6253\u3063\u3066\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7dd4c3f74f006b34bb1d70d7adebd54e.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7dd4c3f74f006b34bb1d70d7adebd54e.png\" alt=\"\" width=\"714\" height=\"118\" class=\"alignnone size-full wp-image-15807\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7dd4c3f74f006b34bb1d70d7adebd54e.png 714w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2018\/12\/7dd4c3f74f006b34bb1d70d7adebd54e-300x50.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/a><br \/>\n\u8a08\u7b97\u7d50\u679c\u3067\u305f\u306e\u3067\u6210\u529f\u3067\u3059\u306d<\/p>\n<h2 id=\"matome\">\u307e\u3068\u3081<\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u52d5\u7684\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u968f\u5206\u96d1\u306a\u30b3\u30fc\u30c9\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304c\u3057\u3063\u304b\u308a\u52d5\u3044\u305f\u306e\u306f\u5b09\u3057\u3044\u3067\u3059\u306d\u3002<br \/>\n\u4eca\u56de\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u306f\u3055\u3089\u306b\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u306e\u5e45\u3092\u5e83\u3052\u308b\u3088\u3046\u306a\u3082\u306e\u3067\u3042\u308a\u671f\u5f85\u3067\u3059\u304cFlask\u306a\u3069\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u304f\u308c\u308b\u3068\u3044\u3044\u306a\u3041\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b ALB\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u5148\u306bLambda\u3092\u6307\u5b9a\u3057\u3066\u3001URL\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304b\u3089\u8db3\u3057\u7b97\u304c\u3067\u304d\u308b\u30da\u30fc\u30b8\u3092\u8efd\u304f\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306bJinja2\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059 \u76ee\u6b21 \u6d41\u308c \u624b\u9806\u306e\u6982\u8981 \u5b9f\u884c\u74b0\u5883 \u624b\u9806 \u307e\u3068\u3081 \u6d41\u308c &#8230;<\/p>\n","protected":false},"author":1,"featured_media":15809,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"15750","footnotes":""},"categories":[20,276,9],"tags":[],"class_list":{"0":"post-15750","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-serverless","9":"category-dev","10":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/15750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=15750"}],"version-history":[{"count":11,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/15750\/revisions"}],"predecessor-version":[{"id":15812,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/15750\/revisions\/15812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/15809"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=15750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=15750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=15750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}