{"id":12933,"date":"2017-10-27T18:18:09","date_gmt":"2017-10-27T09:18:09","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=12933"},"modified":"2024-02-01T16:04:28","modified_gmt":"2024-02-01T07:04:28","slug":"cloudfrontapigatewaylambda%e6%a7%8b%e6%88%90%e3%81%ae%e3%83%ac%e3%82%b9%e3%83%9d%e3%83%b3%e3%82%b9%e3%82%bf%e3%82%a4%e3%83%a0%e6%94%b9%e5%96%84","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/cloudfrontapigatewaylambda%e6%a7%8b%e6%88%90%e3%81%ae%e3%83%ac%e3%82%b9%e3%83%9d%e3%83%b3%e3%82%b9%e3%82%bf%e3%82%a4%e3%83%a0%e6%94%b9%e5%96%84\/","title":{"rendered":"CloudFront+APIGateway+Lambda\u69cb\u6210\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30bf\u30a4\u30e0\u6539\u5584"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>CloudFront+APIGateway+Lambda\u69cb\u6210\u306e\u30b5\u30fc\u30d0\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067<br \/>\nLambda\u306e\u975e\u540c\u671f\u547c\u3073\u51fa\u3057\u3092\u884c\u3044\u30ec\u30b9\u30dd\u30f3\u30b9\u30bf\u30a4\u30e0\u6539\u5584\u3092\u5b9f\u65bd\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u76ee\u6b21<\/h2>\n<ul>\n<li><a href=\"#env\">\u5b9f\u884c\u74b0\u5883<\/a><\/li>\n<li><a href=\"#kaizen\">\u6539\u5584<\/a><\/li>\n<li><a href=\"#matome\">\u307e\u3068\u3081<\/a><\/li>\n<\/ul>\n<h2 id=\"env\">\u5b9f\u884c\u74b0\u5883<\/h2>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12934\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/10\/AsyncLambda.png\" alt=\"\" width=\"652\" height=\"269\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/10\/AsyncLambda.png 652w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/10\/AsyncLambda-300x124.png 300w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u74b0\u5883\u3067\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u5373\u6642\u8fd4\u5374\u3059\u308b\u305f\u3081\u306eLambda\u304b\u3089\u30e1\u30a4\u30f3\u51e6\u7406\u306eLambda\u3092\u975e\u540c\u671f\u547c\u3073\u51fa\u3057<br \/>\n\u5229\u7528\u8a00\u8a9e\u306fPython\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2 id=\"kaizen\">\u6539\u5584<\/h2>\n<h3>Lambda\u306e\u975e\u540c\u671f\u547c\u3073\u51fa\u3057<\/h3>\n<p>\u8ca0\u8377\u8a66\u9a13\u3092\u5b9f\u65bd\u3057\u540c\u6642\u30ea\u30af\u30a8\u30b9\u30c8\u6570\u3092\u5897\u3084\u3057\u3066\u884c\u304f\u3068\u5e73\u5747\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u3069\u3093\u3069\u3093\u3068\u9045\u304f\u306a\u3063\u3066\u3044\u304f\u4e8b\u304c<br \/>\n\u5206\u304b\u3063\u305f\u305f\u3081\u3001\u975e\u540c\u671f\u547c\u3073\u51fa\u3057\u306b\u5909\u66f4\u3059\u308b\u4e8b\u3067\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u3042\u308b\u7a0b\u5ea6\u4e00\u5b9a\u306b\u6291\u3048\u308b\u4e8b\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>APIGateway + Lambda\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u975e\u540c\u671f\u5316\u306e\u8a18\u4e8b\u3082\u591a\u304f\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001<br \/>\n\u73fe\u5728\u306eBoto3 \u30de\u30cb\u30e5\u30a2\u30eb\u3092\u8aad\u3080\u3068\u3001invoke_async \u306f\u975e\u63a8\u5968\u3068\u306a\u3063\u3066\u304a\u308a\u305d\u306e\u5909\u308f\u308a\u306b<br \/>\nInvocationType \u306bEvent\u3092\u6307\u5b9a\u3057\u308d\u3068\u306e\u4e8b\u3067\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/boto3.readthedocs.io\/en\/latest\/reference\/services\/lambda.html#Lambda.Client.invoke\">http:\/\/boto3.readthedocs.io\/en\/latest\/reference\/services\/lambda.html#Lambda.Client.invoke<\/a><\/p>\n<blockquote><p>\n  You can optionally request asynchronous execution by specifying Event as the InvocationType.\n<\/p><\/blockquote>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef lambda_handler(event, context):\r\n    validate\u51e6\u7406\u7b49\u3005\r\n    ...\r\n    lambda_client = boto3.client(&quot;lambda&quot;)\r\n    lambda_client.invoke(\r\n        FunctionName=&quot;async_lambda&quot;,\r\n        InvocationType=&quot;Event&quot;,\r\n        Payload=payload\r\n    )\r\n<\/pre>\n<h3>\u30e1\u30e2\u30ea\u5272\u308a\u5f53\u3066\u5024\u5909\u66f4<\/h3>\n<p>Lambda\u306f\u30e1\u30e2\u30ea\u5272\u308a\u5f53\u3066\u5024\u3067\u3001CPU\u30d1\u30ef\u30fc\u3082\u5909\u308f\u3063\u3066\u6765\u308b\u306e\u3067\u3059\u304c<br \/>\n\u4e0a\u8a18\u7a0b\u5ea6\u306e\u51e6\u7406\u3067\u306f\u305d\u3053\u307e\u3067\u5909\u308f\u3089\u306a\u3044\u306e\u3067\u306f\u7121\u3044\u304b\u3068\u8003\u3048\u3066\u304a\u308a\u307e\u3057\u305f\u304c<br \/>\n100rps\u3067\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u5b9f\u65bd\u3057\u307e\u3057\u305f\u6240\u3001\u304b\u306a\u308a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u7570\u306a\u308b\u4e8b\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>Lambda\u30e1\u30e2\u30ea<\/th>\n<th>\u5e73\u5747\u6642\u9593<\/th>\n<th>99\u30d1\u30fc\u30bb\u30f3\u30bf\u30a4\u30eb\u5024<\/th>\n<\/tr>\n<tr>\n<td>128MB<\/td>\n<td>812ms<\/td>\n<td>6801ms<\/td>\n<\/tr>\n<tr>\n<td>256MB<\/td>\n<td>395ms<\/td>\n<td>3434ms<\/td>\n<\/tr>\n<tr>\n<td>1536MB<\/td>\n<td>252ms<\/td>\n<td>1331ms<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>128MB\u2192256MB\u3067\u307b\u307c\u534a\u5206\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30bf\u30a4\u30e0\u3092\u5f97\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<br \/>\n\u4f46\u3057\u78ba\u5b9f\u306b\u3053\u306e\u79d2\u6570\u5185\u3067\u5e30\u3063\u3066\u304f\u308b\u4fdd\u8a3c\u306f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3042\u3057\u304b\u3089\u305a\u3002<\/p>\n<h2 id=\"matome\">\u307e\u3068\u3081<\/h2>\n<p>\u6700\u8fd1\u306eSaaS\u7b49\u3067\u306f\u7c21\u5358\u306bAPI\u9023\u643a\u7b49\u304c\u884c\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u3066\u304a\u308a\u307e\u3059\u304c<br \/>\n\u30b5\u30fc\u30d0\u3067\u51e6\u7406\u3055\u305b\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u65b0\u898f\u3067\u7acb\u3066\u308b\u306b\u3057\u3066\u3082\u3001\u9593\u501f\u308a\u3059\u308b\u306b\u3057\u3066\u3082\u7ba1\u7406\u5de5\u6570\u304c\u639b\u304b\u3063\u3066\u3057\u307e\u3046\u306e\u3067<br \/>\n\u30b5\u30fc\u30d0\u30ec\u30b9\u69cb\u6210\u3067\u53d7\u3051\u3088\u3046\uff01\u3068\u3044\u3046\u3054\u691c\u8a0e\u304c\u5897\u3048\u3066\u304f\u308b\u3068\u8003\u3048\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u5f0a\u793e\u3067\u306f\u305d\u306e\u3088\u3046\u306a\u69cb\u6210\u306e\u3054\u63d0\u6848\u3001PoC\u30d5\u30a7\u30a4\u30ba\u304b\u3089\u306e\u5c0e\u5165\u652f\u63f4\u3092\u884c\u3063\u3066\u304a\u308a\u307e\u3059\u306e\u3067<br \/>\n\u662f\u975e\u3054\u76f8\u8ac7\u4e0b\u3055\u3044\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/service\/aws\/introduction.html\">https:\/\/www.skyarch.net\/service\/aws\/introduction.html<\/a><\/p>\n<h2>\u53c2\u8003Web\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/qiita.com\/suetake\/items\/3fc945a380af65ecf82d\">https:\/\/qiita.com\/suetake\/items\/3fc945a380af65ecf82d<\/a><br \/>\n\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b CloudFront+APIGateway+Lambda\u69cb\u6210\u306e\u30b5\u30fc\u30d0\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067 Lambda\u306e\u975e\u540c\u671f\u547c\u3073\u51fa\u3057\u3092\u884c\u3044\u30ec\u30b9\u30dd\u30f3\u30b9\u30bf\u30a4\u30e0\u6539\u5584\u3092\u5b9f\u65bd\u3057\u307e\u3057\u305f\u3002 \u76ee\u6b21 \u5b9f\u884c\u74b0\u5883 \u6539\u5584 \u307e\u3068\u3081 \u5b9f\u884c\u74b0\u5883 \u4e0a\u8a18\u306e\u3088&#8230;<\/p>\n","protected":false},"author":2,"featured_media":12940,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"12933","footnotes":""},"categories":[276],"tags":[],"class_list":{"0":"post-12933","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-serverless","8":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/12933","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=12933"}],"version-history":[{"count":11,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/12933\/revisions"}],"predecessor-version":[{"id":25787,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/12933\/revisions\/25787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/12940"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=12933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=12933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=12933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}