{"id":2434,"date":"2025-03-24T08:47:17","date_gmt":"2025-03-23T23:47:17","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=2434"},"modified":"2025-03-24T08:47:48","modified_gmt":"2025-03-23T23:47:48","slug":"%e3%80%90%e4%bf%9d%e5%ad%98%e7%89%88%e3%80%91aws-sam-cli%e5%ae%8c%e5%85%a8%e3%82%ac%e3%82%a4%e3%83%892024-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e3%81%8b%e3%82%89%e5%ae%9f%e8%b7%b5%e7%9a%84%e3%81%aa","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=2434","title":{"rendered":"\u3010\u4fdd\u5b58\u7248\u3011AWS SAM CLI\u5b8c\u5168\u30ac\u30a4\u30c92024 &#8211; \u74b0\u5883\u69cb\u7bc9\u304b\u3089\u5b9f\u8df5\u7684\u306a\u30c7\u30d7\u30ed\u30a4\u307e\u3067\u89e3\u8aac"},"content":{"rendered":"\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">AWS SAM CLI \u3068\u306f\uff1f\u521d\u5fc3\u8005\u3067\u3082\u308f\u304b\u308b\u57fa\u790e\u77e5\u8b58<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">AWS SAM CLI \u304c\u89e3\u6c7a\u3059\u308b 3 \u3064\u306e\u958b\u767a\u8ab2\u984c<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">\u5f93\u6765\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u958b\u767a\u3068\u306e\u6c7a\u5b9a\u7684\u306a\u9055\u3044<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-6\">AWS SAM CLI \u74b0\u5883\u69cb\u7bc9\u5b8c\u5168\u30ac\u30a4\u30c9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-7\">MacOS\/Windows\/Linux \u305d\u308c\u305e\u308c\u306e\u69cb\u7bc9\u624b\u9806<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-11\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0 \u2013 \u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u89e3\u6c7a\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-17\">AWS SAM CLI\u306b\u3088\u308b\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u306e\u59cb\u3081\u65b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-18\">SAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4f5c\u6210\u3068\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>      <li>        <a href=\"#i-21\">Lambda\u95a2\u6570\u306e\u30ed\u30fc\u30ab\u30eb\u30c6\u30b9\u30c8\u5b9f\u884c\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-24\">API\u306e\u30c6\u30b9\u30c8\u30ed\u30fc\u30ab\u30eb\u3068\u30c7\u30d0\u30c3\u30b0\u624b\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-29\">\u5b9f\u8df5\u7684\u306aAWS SAM CLI\u306e\u4f7f\u7528\u65b9\u6cd5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-30\">CI\/CD\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u3068\u306e\u9023\u643a\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-33\">\u672c\u756a\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d5\u30ed\u30fc<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-36\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306e\u5b9f\u88c5<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-41\">AWS SAM CLI \u3092\u4f7f\u7528\u3057\u305f\u958b\u767a\u52b9\u7387\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-42\">\u958b\u767a\u751f\u7523\u6027\u30923\u500d\u306b\u3059\u308b\u81ea\u52d5\u5316\u30b9\u30af\u30ea\u30d7\u30c8\u96c6<\/a>      <\/li>      <li>        <a href=\"#i-45\">\u30b3\u30b9\u30c8\u6700\u9069\u5316\u306e\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-48\">\u5927\u898f\u6a21\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u6d3b\u7528\u4e8b\u4f8b<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">AWS SAM CLI \u3068\u306f\uff1f\u521d\u5fc3\u8005\u3067\u3082\u308f\u304b\u308b\u57fa\u790e\u77e5\u8b58<\/h2>\n\n\n\n<p>AWS Serverless Application Model Command Line Interface\uff08AWS SAM CLI\uff09\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u767a\u3001\u30c6\u30b9\u30c8\u3001\u30c7\u30d7\u30ed\u30a4\u3092\u52b9\u7387\u5316\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3053\u306e\u30c4\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u958b\u767a\u8005\u306f\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067AWS\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30ea\u30bd\u30fc\u30b9\u3092\u7c21\u5358\u306b\u69cb\u7bc9\u3001\u30c6\u30b9\u30c8\u3001\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">AWS SAM CLI \u304c\u89e3\u6c7a\u3059\u308b 3 \u3064\u306e\u958b\u767a\u8ab2\u984c<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u74b0\u5883\u306e\u8ab2\u984c<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u554f\u984c\u70b9<\/strong>: \u5f93\u6765\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u958b\u767a\u3067\u306f\u3001\u30b3\u30fc\u30c9\u306e\u52d5\u4f5c\u78ba\u8a8d\u306e\u305f\u3073\u306bAWS\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u304c\u5fc5\u8981\u3067\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u89e3\u6c7a\u7b56<\/strong>: SAM CLI\u306e<code>sam local<\/code>\u30b3\u30de\u30f3\u30c9\u306b\u3088\u308a\u3001\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067Lambda\u95a2\u6570\u3084API\u306e\u30c6\u30b9\u30c8\u304c\u53ef\u80fd\u306b\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # Lambda\u95a2\u6570\u3092\u30ed\u30fc\u30ab\u30eb\u3067\u5b9f\u884c\n   sam local invoke \"MyFunction\" -e events\/event.json\n\n   # API\u3092\u30ed\u30fc\u30ab\u30eb\u3067\u8d77\u52d5\n   sam local start-api<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u306e\u8907\u96d1\u3055<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u554f\u984c\u70b9<\/strong>: \u8907\u6570\u306eAWS\u30ea\u30bd\u30fc\u30b9\u306e\u9023\u643a\u304c\u5fc5\u8981\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30c7\u30d7\u30ed\u30a4\u306f\u7169\u96d1\u3067\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u89e3\u6c7a\u7b56<\/strong>: <code>template.yaml<\/code>\u306b\u3088\u308b\u5ba3\u8a00\u7684\u306a\u30a4\u30f3\u30d5\u30e9\u5b9a\u7fa9\u3068<code>sam deploy<\/code>\u30b3\u30de\u30f3\u30c9\u306b\u3088\u308b\u4e00\u62ec\u30c7\u30d7\u30ed\u30a4\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # template.yaml\u306e\u4f8b\n   Resources:\n     MyFunction:\n       Type: AWS::Serverless::Function\n       Properties:\n         Handler: index.handler\n         Runtime: nodejs18.x\n         Events:\n           ApiEvent:\n             Type: Api\n             Properties:\n               Path: \/hello\n               Method: get<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30c6\u30b9\u30c8\u3068\u30c7\u30d0\u30c3\u30b0\u306e\u56f0\u96e3\u3055<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u554f\u984c\u70b9<\/strong>: \u30af\u30e9\u30a6\u30c9\u74b0\u5883\u3067\u306e\u30c7\u30d0\u30c3\u30b0\u306f\u6642\u9593\u304c\u304b\u304b\u308a\u3001\u30ed\u30b0\u306e\u78ba\u8a8d\u3082\u9045\u5ef6\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u89e3\u6c7a\u7b56<\/strong>: \u30ed\u30fc\u30ab\u30eb\u3067\u306e\u30b9\u30c6\u30c3\u30d7\u5b9f\u884c\u3084\u30ed\u30b0\u306e\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u8868\u793a\u304c\u53ef\u80fd\u306b\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3067Lambda\u95a2\u6570\u3092\u5b9f\u884c\n   sam local invoke -d 5858 \"MyFunction\"\n\n   # \u30ed\u30b0\u306e\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u8868\u793a\n   sam logs -n MyFunction --tail<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">\u5f93\u6765\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u958b\u767a\u3068\u306e\u6c7a\u5b9a\u7684\u306a\u9055\u3044<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-3\">1. \u958b\u767a\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u306e\u6539\u5584<\/h4>\n\n\n<div id=\"id-5f73f47b-6b5b-4a52-ad5d-3c29813ee6be\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u958b\u767a\u30d5\u30a7\u30fc\u30ba<\/th><th>\u5f93\u6765\u306e\u65b9\u6cd5<\/th><th>SAM CLI\u3092\u4f7f\u7528\u3057\u305f\u65b9\u6cd5<\/th><\/tr><\/thead><tbody><tr><td>\u30b3\u30fc\u30c9\u4f5c\u6210<\/td><td>\u30a8\u30c7\u30a3\u30bf\u3067\u30b3\u30fc\u30c9\u4f5c\u6210\u306e\u307f<\/td><td>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304b\u3089\u306e\u81ea\u52d5\u751f\u6210\u3068\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u63d0\u4f9b<\/td><\/tr><tr><td>\u30c6\u30b9\u30c8\u5b9f\u884c<\/td><td>AWS\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u304c\u5fc5\u8981<\/td><td>\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u5373\u6642\u5b9f\u884c\u53ef\u80fd<\/td><\/tr><tr><td>\u30c7\u30d0\u30c3\u30b0<\/td><td>CloudWatch\u30ed\u30b0\u306e\u78ba\u8a8d\u5f85\u3061<\/td><td>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c7\u30d0\u30c3\u30b0\u53ef\u80fd<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"i-4\">2. \u30a4\u30f3\u30d5\u30e9\u7ba1\u7406\u306e\u5909\u9769<\/h4>\n\n\n\n<p>SAM CLI\u306f\u3001Infrastructure as Code\uff08IaC\uff09\u306e\u8003\u3048\u65b9\u3092\u5b8c\u5168\u306b\u53d6\u308a\u5165\u308c\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30fc\u30c9\u3068\u30a4\u30f3\u30d5\u30e9\u5b9a\u7fa9\u3092\u4e00\u5143\u7ba1\u7406\u3067\u304d\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7d71\u5408\u3055\u308c\u305f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7ba1\u7406<\/strong><\/li>\n\n\n\n<li>\u4e00\u3064\u306e<code>template.yaml<\/code>\u30d5\u30a1\u30a4\u30eb\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5168\u4f53\u3092\u5b9a\u7fa9<\/li>\n\n\n\n<li>\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3067\u30a4\u30f3\u30d5\u30e9\u306e\u5909\u66f4\u5c65\u6b74\u3092\u8ffd\u8de1\u53ef\u80fd<\/li>\n\n\n\n<li>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u518d\u5229\u7528\u306b\u3088\u308b\u958b\u767a\u306e\u6a19\u6e96\u5316<\/li>\n\n\n\n<li><strong>\u7c21\u7d20\u5316\u3055\u308c\u305f\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d7\u30ed\u30bb\u30b9<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  # \u30d3\u30eb\u30c9\u304b\u3089\u30c7\u30d7\u30ed\u30a4\u307e\u3067\u30ef\u30f3\u30b3\u30de\u30f3\u30c9\n  sam build &amp;&amp; sam deploy --guided<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-5\">3. \u958b\u767a\u4f53\u9a13\u306e\u5411\u4e0a<\/h4>\n\n\n\n<p>SAM CLI\u306e\u5c0e\u5165\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u70b9\u3067\u958b\u767a\u8005\u4f53\u9a13\u304c\u5927\u304d\u304f\u6539\u5584\u3055\u308c\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9ad8\u901f\u306a\u30d5\u30a3\u30fc\u30c9\u30d0\u30c3\u30af\u30eb\u30fc\u30d7<\/strong><\/li>\n\n\n\n<li>\u30b3\u30fc\u30c9\u5909\u66f4\u2192\u30c6\u30b9\u30c8\u2192\u30c7\u30d0\u30c3\u30b0\u306e\u30b5\u30a4\u30af\u30eb\u304c\u6570\u5206\u304b\u3089\u6570\u79d2\u306b\u77ed\u7e2e<\/li>\n\n\n\n<li>\u30db\u30c3\u30c8\u30ea\u30ed\u30fc\u30c9\u6a5f\u80fd\u306b\u3088\u308b\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306a\u5909\u66f4\u53cd\u6620<\/li>\n\n\n\n<li><strong>\u7d71\u5408\u3055\u308c\u305f\u958b\u767a\u74b0\u5883<\/strong><\/li>\n\n\n\n<li>VS Code\u3001IntelliJ\u7b49\u306e\u4e3b\u8981IDE\u3068\u306e\u9023\u643a<\/li>\n\n\n\n<li>\u30c7\u30d0\u30c3\u30ac\u30fc\u3084\u30c6\u30b9\u30c8\u30e9\u30f3\u30ca\u30fc\u3068\u306e seamless \u306a\u7d71\u5408<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001AWS SAM CLI\u306f\u5358\u306a\u308b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb\u3067\u306f\u306a\u304f\u3001\u30e2\u30c0\u30f3\u306a\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u958b\u767a\u306e\u305f\u3081\u306e\u5305\u62ec\u7684\u306a\u958b\u767a\u74b0\u5883\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u5f93\u6765\u306e\u958b\u767a\u624b\u6cd5\u3068\u6bd4\u8f03\u3057\u3066\u3001\u751f\u7523\u6027\u3001\u54c1\u8cea\u3001\u958b\u767a\u8005\u4f53\u9a13\u306e\u3059\u3079\u3066\u306e\u9762\u3067\u5927\u304d\u306a\u6539\u5584\u3092\u3082\u305f\u3089\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-6\">AWS SAM CLI \u74b0\u5883\u69cb\u7bc9\u5b8c\u5168\u30ac\u30a4\u30c9<\/h2>\n\n\n\n<p>AWS SAM CLI\u3092\u52b9\u679c\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u9069\u5207\u306a\u74b0\u5883\u69cb\u7bc9\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u3053\u306e\u30ac\u30a4\u30c9\u3067\u306f\u3001\u5404OS\u3067\u306e\u8a73\u7d30\u306a\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u624b\u9806\u3068\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-7\">MacOS\/Windows\/Linux \u305d\u308c\u305e\u308c\u306e\u69cb\u7bc9\u624b\u9806<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-8\">MacOS \u3067\u306e\u74b0\u5883\u69cb\u7bc9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u524d\u63d0\u6761\u4ef6\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # Homebrew\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff08\u672a\u5c0e\u5165\u306e\u5834\u5408\uff09\n   \/bin\/bash -c \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/master\/install.sh)\"\n\n   # Python3\u3068pip\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   brew install python3\n\n   # Docker Desktop\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   brew install --cask docker<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>AWS SAM CLI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # AWS SAM CLI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   brew install aws-sam-cli\n\n   # \u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\n   sam --version<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>AWS\u8a8d\u8a3c\u60c5\u5831\u306e\u8a2d\u5b9a<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # AWS CLI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   brew install awscli\n\n   # \u8a8d\u8a3c\u60c5\u5831\u306e\u8a2d\u5b9a\n   aws configure<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-9\">Windows \u3067\u306e\u74b0\u5883\u69cb\u7bc9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u524d\u63d0\u6761\u4ef6\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python3.8\u4ee5\u4e0a\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff08<a href=\"https:\/\/www.python.org\/downloads\/windows\/\">\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u304b\u3089\uff09<\/li>\n\n\n\n<li>Docker Desktop\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff08WSL2\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\uff09<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>WSL2\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # WSL2\u306e\u6709\u52b9\u5316\uff08\u7ba1\u7406\u8005\u6a29\u9650\u3067\u5b9f\u884c\uff09\n   dism.exe \/online \/enable-feature \/featurename:Microsoft-Windows-Subsystem-Linux \/all \/norestart\n   dism.exe \/online \/enable-feature \/featurename:VirtualMachinePlatform \/all \/norestart<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>AWS SAM CLI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/aws\/aws-sam-cli\/releases\/latest\/download\/AWS_SAM_CLI_64_PY3.msi\">AWS SAM CLI Windows Installer<\/a>\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/li>\n\n\n\n<li>\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3092\u5b9f\u884c<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\n   sam --version<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-10\">Linux (Ubuntu\/Debian) \u3067\u306e\u74b0\u5883\u69cb\u7bc9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u524d\u63d0\u6761\u4ef6\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   sudo apt-get update\n   sudo apt-get install -y python3 python3-pip docker.io\n\n   # Docker\u30b5\u30fc\u30d3\u30b9\u306e\u958b\u59cb\n   sudo systemctl start docker\n   sudo systemctl enable docker<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>AWS SAM CLI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3068\u5b9f\u884c\n   wget https:\/\/github.com\/aws\/aws-sam-cli\/releases\/latest\/download\/aws-sam-cli-linux-x86_64.zip\n   unzip aws-sam-cli-linux-x86_64.zip -d sam-installation\n   sudo .\/sam-installation\/install<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-11\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0 \u2013 \u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u89e3\u6c7a\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-12\">1. Docker\u95a2\u9023\u306e\u554f\u984c<\/h4>\n\n\n<div id=\"id-476a2078-6d59-4f35-963e-0931de4e48cc\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30a8\u30e9\u30fc<\/th><th>\u539f\u56e0<\/th><th>\u89e3\u6c7a\u65b9\u6cd5<\/th><\/tr><\/thead><tbody><tr><td><code>Cannot connect to the Docker daemon<\/code><\/td><td>Docker\u30b5\u30fc\u30d3\u30b9\u304c\u8d77\u52d5\u3057\u3066\u3044\u306a\u3044<\/td><td>\u2013 Docker\u30c7\u30fc\u30e2\u30f3\u306e\u8d77\u52d5\u78ba\u8a8d<br>\u2013 <code>sudo systemctl start docker<\/code>\u306e\u5b9f\u884c<\/td><\/tr><tr><td><code>permission denied<\/code><\/td><td>Docker\u6a29\u9650\u306e\u554f\u984c<\/td><td>\u2013 <code>sudo usermod -aG docker $USER<\/code>\u306e\u5b9f\u884c<br>\u2013 \u30b7\u30b9\u30c6\u30e0\u306e\u518d\u8d77\u52d5<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"i-13\">2. AWS\u8a8d\u8a3c\u95a2\u9023\u306e\u554f\u984c<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30a8\u30e9\u30fc: The config profile (default) could not be found\n# \u89e3\u6c7a\u7b56\uff1aAWS\u8a8d\u8a3c\u60c5\u5831\u306e\u518d\u8a2d\u5b9a\naws configure\n\n# \u8a2d\u5b9a\u9805\u76ee\nAWS Access Key ID: [\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u3092\u5165\u529b]\nAWS Secret Access Key: [\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc\u3092\u5165\u529b]\nDefault region name: [\u30ea\u30fc\u30b8\u30e7\u30f3\u3092\u5165\u529b\uff08\u4f8b\uff1aap-northeast-1\uff09]\nDefault output format: [json]<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-14\">3. Python\u74b0\u5883\u306e\u554f\u984c<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u30a8\u30e9\u30fc<\/strong>: <code>sam: command not found<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  # \u89e3\u6c7a\u7b561: PATH\u306e\u78ba\u8a8d\u3068\u8ffd\u52a0\n  echo $PATH\n  export PATH=$PATH:~\/.local\/bin\n\n  # \u89e3\u6c7a\u7b562: \u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u306e\u4f5c\u6210\n  sudo ln -s $(which sam) \/usr\/local\/bin\/sam<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-15\">4. \u30e1\u30e2\u30ea\u4e0d\u8db3\u306e\u554f\u984c<\/h4>\n\n\n\n<p>Docker Desktop\u8a2d\u5b9a\u306e\u8abf\u6574\u304c\u5fc5\u8981\u306a\u5834\u5408\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># .samconfig.toml\u3067\u306e\u30e1\u30e2\u30ea\u8a2d\u5b9a\nversion = 0.1<\/pre>\n\n\n[default]\n\n\n\n[default.local_invoke] docker_host = \u201cunix:\/\/\/var\/run\/docker.sock\u201d container_memory = 2048 # \u30e1\u30e2\u30ea\u5236\u9650\u30922GB\u306b\u8a2d\u5b9a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-16\">\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c\u306e\u52d5\u4f5c\u78ba\u8a8d<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306a\u52d5\u4f5c\u78ba\u8a8d<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\n   sam --version\n\n   # \u30d8\u30eb\u30d7\u306e\u8868\u793a\n   sam --help<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # Hello World\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\n   sam init --runtime python3.9 --dependency-manager pip --app-template hello-world\n\n   # \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30d3\u30eb\u30c9\n   cd sam-app\n   sam build\n\n   # \u30ed\u30fc\u30ab\u30eb\u3067\u306e\u5b9f\u884c\u30c6\u30b9\u30c8\n   sam local invoke<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u74b0\u5883\u5909\u6570\u306e\u8a2d\u5b9a\u78ba\u8a8d<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # AWS\u8a8d\u8a3c\u60c5\u5831\u306e\u78ba\u8a8d\n   aws sts get-caller-identity\n\n   # SAM\u8a2d\u5b9a\u306e\u78ba\u8a8d\n   sam local generate-event s3 put --help<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u624b\u9806\u3092\u5b8c\u4e86\u3059\u308b\u3053\u3068\u3067\u3001AWS SAM CLI\u306e\u958b\u767a\u74b0\u5883\u304c\u6574\u3044\u307e\u3059\u3002\u30c8\u30e9\u30d6\u30eb\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u4e0a\u8a18\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30ac\u30a4\u30c9\u3092\u53c2\u7167\u3057\u306a\u304c\u3089\u3001\u7cfb\u7d71\u7684\u306b\u554f\u984c\u3092\u89e3\u6c7a\u3057\u3066\u3044\u304f\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-17\">AWS SAM CLI\u306b\u3088\u308b\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u306e\u59cb\u3081\u65b9<\/h2>\n\n\n\n<p>\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u3092\u52b9\u7387\u7684\u306b\u9032\u3081\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068\u5b9f\u8df5\u7684\u306a\u624b\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">SAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4f5c\u6210\u3068\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-19\">1. \u52b9\u7387\u7684\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u9020<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">my-serverless-app\/\n\u251c\u2500\u2500 template.yaml           # \u30e1\u30a4\u30f3\u306eSAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\n\u251c\u2500\u2500 src\/\n\u2502   \u251c\u2500\u2500 handlers\/          # Lambda\u95a2\u6570\u306e\u30cf\u30f3\u30c9\u30e9\u30fc\n\u2502   \u2502   \u251c\u2500\u2500 create-user\/\n\u2502   \u2502   \u2502   \u251c\u2500\u2500 index.js\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 package.json\n\u2502   \u2502   \u2514\u2500\u2500 process-order\/\n\u2502   \u2502       \u251c\u2500\u2500 index.js\n\u2502   \u2502       \u2514\u2500\u2500 package.json\n\u2502   \u251c\u2500\u2500 layers\/            # Lambda \u30ec\u30a4\u30e4\u30fc\n\u2502   \u2502   \u2514\u2500\u2500 common-libs\/\n\u2502   \u2514\u2500\u2500 utils\/            # \u5171\u901a\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\n\u251c\u2500\u2500 tests\/\n\u2502   \u251c\u2500\u2500 unit\/\n\u2502   \u2514\u2500\u2500 integration\/\n\u251c\u2500\u2500 events\/               # \u30c6\u30b9\u30c8\u7528\u30a4\u30d9\u30f3\u30c8\n\u2502   \u251c\u2500\u2500 create-user.json\n\u2502   \u2514\u2500\u2500 process-order.json\n\u2514\u2500\u2500 samconfig.toml       # SAM CLI\u8a2d\u5b9a<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-20\">2. \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u8a2d\u8a08\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># template.yaml\nAWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: \u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\n\nGlobals:\n  Function:\n    Timeout: 30\n    MemorySize: 128\n    Runtime: nodejs18.x\n    Environment:\n      Variables:\n        STAGE: !Ref Stage\n\nParameters:\n  Stage:\n    Type: String\n    Default: dev\n    AllowedValues:\n      - dev\n      - stg\n      - prod\n\nResources:\n  CreateUserFunction:\n    Type: AWS::Serverless::Function\n    Properties:\n      Handler: index.handler\n      CodeUri: src\/handlers\/create-user\/\n      Policies:\n        - DynamoDBCrudPolicy:\n            TableName: !Ref UsersTable\n      Events:\n        ApiEvent:\n          Type: Api\n          Properties:\n            Path: \/users\n            Method: post\n\n  UsersTable:\n    Type: AWS::Serverless::SimpleTable\n    Properties:\n      PrimaryKey:\n        Name: userId\n        Type: String\n\nOutputs:\n  ApiEndpoint:\n    Description: API Gateway endpoint URL\n    Value: !Sub \"https:\/\/${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com\/${Stage}\/\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">Lambda\u95a2\u6570\u306e\u30ed\u30fc\u30ab\u30eb\u30c6\u30b9\u30c8\u5b9f\u884c\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-22\">1. \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ tests\/unit\/create-user.test.js\nconst { handler } = require('..\/..\/src\/handlers\/create-user');\n\ndescribe('CreateUser Lambda', () =&gt; {\n  it('should create a new user successfully', async () =&gt; {\n    const event = {\n      body: JSON.stringify({\n        email: 'test@example.com',\n        name: 'Test User'\n      })\n    };\n\n    const result = await handler(event);\n    expect(result.statusCode).toBe(200);\n  });\n});<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-23\">2. \u30ed\u30fc\u30ab\u30eb\u3067\u306eLambda\u5b9f\u884c<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30a4\u30d9\u30f3\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3057\u305f\u5b9f\u884c\nsam local invoke CreateUserFunction -e events\/create-user.json\n\n# \u74b0\u5883\u5909\u6570\u306e\u4e0a\u66f8\u304d\nsam local invoke CreateUserFunction \\\n  -e events\/create-user.json \\\n  --env-vars env.json\n\n# \u30db\u30c3\u30c8\u30ea\u30ed\u30fc\u30c9\u3067\u306e\u5b9f\u884c\uff08\u958b\u767a\u52b9\u7387\u5411\u4e0a\uff09\nsam local invoke CreateUserFunction \\\n  -e events\/create-user.json \\\n  --hot-reload<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-24\">API\u306e\u30c6\u30b9\u30c8\u30ed\u30fc\u30ab\u30eb\u3068\u30c7\u30d0\u30c3\u30b0\u624b\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-25\">1. \u30ed\u30fc\u30ab\u30ebAPI\u30b5\u30fc\u30d0\u30fc\u306e\u8d77\u52d5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># API\u306e\u30ed\u30fc\u30ab\u30eb\u8d77\u52d5\nsam local start-api\n\n# \u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3067\u306e\u8d77\u52d5\nsam local start-api -d 5858\n\n# \u7279\u5b9a\u306e\u30dd\u30fc\u30c8\u3067\u306e\u8d77\u52d5\nsam local start-api -p 3000<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-26\">2. \u9ad8\u5ea6\u306a\u30c7\u30d0\u30c3\u30b0\u30c6\u30af\u30cb\u30c3\u30af<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>VSCode\u3067\u306e\u30c7\u30d0\u30c3\u30b0\u8a2d\u5b9a<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ .vscode\/launch.json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"name\": \"SAM CLI CreateUser\",\n      \"type\": \"node\",\n      \"request\": \"attach\",\n      \"address\": \"localhost\",\n      \"port\": 5858,\n      \"localRoot\": \"${workspaceFolder}\/src\/handlers\/create-user\",\n      \"remoteRoot\": \"\/var\/task\",\n      \"protocol\": \"inspector\",\n      \"stopOnEntry\": false\n    }\n  ]\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u52b9\u679c\u7684\u306a\u30ed\u30b0\u51fa\u529b<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ src\/handlers\/create-user\/index.js\nconst handler = async (event) =&gt; {\n  console.log('Event:', JSON.stringify(event, null, 2));\n\n  try {\n    \/\/ \u51e6\u7406\u5185\u5bb9\n    console.log('Processing user creation...');\n  } catch (error) {\n    console.error('Error:', error);\n    throw error;\n  }\n};<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-27\">3. \u30c6\u30b9\u30c8\u81ea\u52d5\u5316\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30c6\u30b9\u30c8\u5b9f\u884c\u30b9\u30af\u30ea\u30d7\u30c8\n#!\/bin\/bash\n\n# \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306e\u5b9f\u884c\nnpm test\n\n# \u30ed\u30fc\u30ab\u30eb\u3067\u306eAPI\u7d71\u5408\u30c6\u30b9\u30c8\nsam local start-api &amp;\nAPI_PID=$!\n\n# API\u304c\u8d77\u52d5\u3059\u308b\u307e\u3067\u5f85\u6a5f\nsleep 5\n\n# \u30c6\u30b9\u30c8\u306e\u5b9f\u884c\ncurl -X POST http:\/\/localhost:3000\/users \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\"email\":\"test@example.com\",\"name\":\"Test User\"}'\n\n# \u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\nkill $API_PID<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-28\">\u30c7\u30d0\u30c3\u30b0\u306e\u305f\u3081\u306eTips<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u52b9\u679c\u7684\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const createError = (statusCode, message) =&gt; ({\n  statusCode,\n  body: JSON.stringify({ error: message })\n});\n\nconst handler = async (event) =&gt; {\n  try {\n    \/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\n    if (!event.body) {\n      return createError(400, 'Request body is required');\n    }\n\n    const { email, name } = JSON.parse(event.body);\n    if (!email || !name) {\n      return createError(400, 'Email and name are required');\n    }\n\n    \/\/ \u30e1\u30a4\u30f3\u51e6\u7406\n\n  } catch (error) {\n    console.error('Error:', error);\n    return createError(500, 'Internal server error');\n  }\n};<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u74b0\u5883\u5909\u6570\u306e\u7ba1\u7406<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># env.json\n{\n  \"CreateUserFunction\": {\n    \"STAGE\": \"local\",\n    \"TABLE_NAME\": \"local-users-table\",\n    \"DEBUG\": \"true\"\n  }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u8df5\u7684\u306a\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u52b9\u7387\u7684\u306a\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3001\u9ad8\u54c1\u8cea\u306a\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u767a\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-29\">\u5b9f\u8df5\u7684\u306aAWS SAM CLI\u306e\u4f7f\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u5b9f\u904b\u7528\u74b0\u5883\u3067\u306eAWS SAM CLI\u306e\u6d3b\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3001CI\/CD\u3001\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u89b3\u70b9\u304b\u3089\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-30\">CI\/CD\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u3068\u306e\u9023\u643a\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-31\">1. GitHub Actions\u3092\u4f7f\u7528\u3057\u305fCI\/CD\u69cb\u7bc9<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># .github\/workflows\/sam-deploy.yml\nname: Deploy SAM Application\n\non:\n  push:\n    branches: [ main ]\n  pull_request:\n    branches: [ main ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/checkout@v2\n\n      - name: Setup Python\n        uses: actions\/setup-python@v2\n        with:\n          python-version: '3.9'\n\n      - name: Setup AWS SAM CLI\n        uses: aws-actions\/setup-sam@v1\n\n      - name: Configure AWS Credentials\n        uses: aws-actions\/configure-aws-credentials@v1\n        with:\n          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}\n          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}\n          aws-region: ap-northeast-1\n\n      - name: SAM Build\n        run: sam build\n\n      - name: Run Tests\n        run: |\n          pip install pytest\n          python -m pytest tests\/\n\n      - name: SAM Deploy\n        if: github.ref == 'refs\/heads\/main'\n        run: |\n          sam deploy --no-confirm-changeset \\\n            --stack-name prod-stack \\\n            --s3-bucket deployment-artifacts \\\n            --capabilities CAPABILITY_IAM<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-32\">2. AWS CodePipeline\u3068\u306e\u7d71\u5408<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># template.yaml\u5185\u306bCodePipeline\u306e\u5b9a\u7fa9\u3092\u8ffd\u52a0\nResources:\n  Pipeline:\n    Type: AWS::CodePipeline::Pipeline\n    Properties:\n      RoleArn: !GetAtt CodePipelineServiceRole.Arn\n      Stages:\n        - Name: Source\n          Actions:\n            - Name: Source\n              ActionTypeId:\n                Category: Source\n                Owner: AWS\n                Version: 1\n                Provider: CodeCommit\n              Configuration:\n                RepositoryName: !Ref RepositoryName\n                BranchName: main\n              OutputArtifacts:\n                - Name: SourceCode\n\n        - Name: Build\n          Actions:\n            - Name: Build\n              ActionTypeId:\n                Category: Build\n                Owner: AWS\n                Version: 1\n                Provider: CodeBuild\n              Configuration:\n                ProjectName: !Ref BuildProject\n              InputArtifacts:\n                - Name: SourceCode\n              OutputArtifacts:\n                - Name: BuildOutput<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-33\">\u672c\u756a\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d5\u30ed\u30fc<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-34\">1. \u6bb5\u968e\u7684\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u6226\u7565<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u958b\u767a\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\nsam deploy --stack-name dev-stack \\\n  --parameter-overrides Stage=dev \\\n  --tags Environment=Development\n\n# \u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\nsam deploy --stack-name stg-stack \\\n  --parameter-overrides Stage=stg \\\n  --tags Environment=Staging\n\n# \u672c\u756a\u74b0\u5883\u3078\u306e\u30c7\u30d7\u30ed\u30a4\nsam deploy --stack-name prod-stack \\\n  --parameter-overrides Stage=prod \\\n  --tags Environment=Production \\\n  --no-execute-changeset  # \u5909\u66f4\u30bb\u30c3\u30c8\u306e\u78ba\u8a8d\u7528<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-35\">2. \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u6226\u7565\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># template.yaml\u3067\u306e\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u8a2d\u5b9a\nGlobals:\n  Function:\n    AutoPublishAlias: live\n    DeploymentPreference:\n      Type: Linear10PercentEvery10Minutes\n      Alarms:\n        - !Ref AliasErrorMetricGreaterThanZeroAlarm\n        - !Ref LatencyAlarm\n\nResources:\n  AliasErrorMetricGreaterThanZeroAlarm:\n    Type: AWS::CloudWatch::Alarm\n    Properties:\n      AlarmDescription: Lambda Function Error &gt; 0\n      ComparisonOperator: GreaterThanThreshold\n      EvaluationPeriods: 2\n      MetricName: Errors\n      Namespace: AWS\/Lambda\n      Period: 300\n      Statistic: Sum\n      Threshold: 0<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-36\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306e\u5b9f\u88c5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-37\">1. IAM\u30dd\u30ea\u30b7\u30fc\u306e\u6700\u5c0f\u6a29\u9650\u539f\u5247<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Resources:\n  MyFunction:\n    Type: AWS::Serverless::Function\n    Properties:\n      Handler: index.handler\n      Runtime: nodejs18.x\n      Policies:\n        - Statement:\n            - Effect: Allow\n              Action:\n                - dynamodb:GetItem\n                - dynamodb:PutItem\n              Resource: !GetAtt MyTable.Arn\n              Condition:\n                StringEquals:\n                  'aws:RequestTag\/Environment': !Ref Environment<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-38\">2. \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\u306e\u81ea\u52d5\u30c1\u30a7\u30c3\u30af<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># AWS Config Rule\u306e\u8a2d\u5b9a\nResources:\n  LambdaFunctionSettingsRule:\n    Type: AWS::Config::ConfigRule\n    Properties:\n      ConfigRuleName: lambda-function-settings-check\n      Source:\n        Owner: AWS\n        SourceIdentifier: LAMBDA_FUNCTION_SETTINGS_CHECK\n      Scope:\n        ComplianceResourceTypes:\n          - AWS::Lambda::Function\n      InputParameters:\n        runtime: nodejs18.x\n        timeout: 30\n        memorySize: 128<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-39\">3. \u6a5f\u5bc6\u60c5\u5831\u306e\u5b89\u5168\u306a\u7ba1\u7406<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># AWS Systems Manager\u30d1\u30e9\u30e1\u30fc\u30bf\u30b9\u30c8\u30a2\u306e\u4f7f\u7528\naws ssm put-parameter \\\n    --name \"\/myapp\/prod\/db-password\" \\\n    --value \"mypassword\" \\\n    --type SecureString\n\n# SAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u306e\u53c2\u7167\nResources:\n  MyFunction:\n    Type: AWS::Serverless::Function\n    Properties:\n      Environment:\n        Variables:\n          DB_PASSWORD: !Sub '{{resolve:ssm:\/myapp\/${Stage}\/db-password:1}}'<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-40\">4. \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Resources:\n  SecurityLogGroup:\n    Type: AWS::Logs::LogGroup\n    Properties:\n      RetentionInDays: 14\n\n  SecurityAlarm:\n    Type: AWS::CloudWatch::Alarm\n    Properties:\n      AlarmDescription: Security violation alarm\n      MetricName: SecurityViolations\n      Namespace: Custom\/Security\n      ComparisonOperator: GreaterThanThreshold\n      EvaluationPeriods: 1\n      Period: 300\n      Statistic: Sum\n      Threshold: 0\n      TreatMissingData: notBreaching<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u8df5\u7684\u306a\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30bb\u30ad\u30e5\u30a2\u3067\u52b9\u7387\u7684\u306a\u672c\u756a\u74b0\u5883\u306e\u904b\u7528\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u7279\u306b\u3001CI\/CD\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u306e\u81ea\u52d5\u5316\u3001\u6bb5\u968e\u7684\u306a\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u6226\u7565\u3001\u305d\u3057\u3066\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306e\u5b9f\u88c5\u306f\u3001\u5b89\u5b9a\u3057\u305f\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u904b\u7528\u306b\u4e0d\u53ef\u6b20\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-41\">AWS SAM CLI \u3092\u4f7f\u7528\u3057\u305f\u958b\u767a\u52b9\u7387\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/h2>\n\n\n\n<p>\u5b9f\u8df5\u7684\u306a\u958b\u767a\u52b9\u7387\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3068\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u6d3b\u7528\u4e8b\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-42\">\u958b\u767a\u751f\u7523\u6027\u30923\u500d\u306b\u3059\u308b\u81ea\u52d5\u5316\u30b9\u30af\u30ea\u30d7\u30c8\u96c6<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-43\">1. \u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u81ea\u52d5\u5316\u30b9\u30af\u30ea\u30d7\u30c8<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n# deploy.sh - \u74b0\u5883\u5225\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30b9\u30af\u30ea\u30d7\u30c8\n\n# \u8a2d\u5b9a\u5024\nSTACK_NAME_PREFIX=\"my-serverless-app\"\nS3_BUCKET=\"my-deployment-artifacts\"\nREGION=\"ap-northeast-1\"\n\n# \u5f15\u6570\u30c1\u30a7\u30c3\u30af\nif [ -z \"$1\" ]; then\n    echo \"Usage: .\/deploy.sh &lt;environment&gt;\"\n    exit 1\nfi\n\nENV=$1\nSTACK_NAME=\"${STACK_NAME_PREFIX}-${ENV}\"\n\n# \u30d3\u30eb\u30c9\u3068\u30c6\u30b9\u30c8\necho \"Building and testing...\"\nsam build || exit 1\nnpm test || exit 1\n\n# \u30c7\u30d7\u30ed\u30a4\necho \"Deploying to ${ENV} environment...\"\nsam deploy \\\n    --stack-name ${STACK_NAME} \\\n    --s3-bucket ${S3_BUCKET} \\\n    --parameter-overrides \\\n        Environment=${ENV} \\\n        Stage=${ENV} \\\n    --capabilities CAPABILITY_IAM \\\n    --region ${REGION} \\\n    --no-fail-on-empty-changeset \\\n    --tags Environment=${ENV}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-44\">2. Lambda\u95a2\u6570\u306e\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u751f\u6210\u30b9\u30af\u30ea\u30d7\u30c8<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># generate_function.py\nimport os\nimport sys\nfrom typing import Dict, Any\n\ndef create_function_template(name: str, api_path: str) -&gt; Dict[str, Any]:\n    return {\n        \"handler\": f\"src\/handlers\/{name}\/index.handler\",\n        \"template\": f\"\"\"\n# src\/handlers\/{name}\/index.js\nconst handler = async (event) =&gt; {{\n    try {{\n        const response = {{\n            statusCode: 200,\n            body: JSON.stringify({{\n                message: \"Success\"\n            }})\n        }};\n        return response;\n    }} catch (error) {{\n        console.error('Error:', error);\n        return {{\n            statusCode: 500,\n            body: JSON.stringify({{ error: \"Internal Server Error\" }})\n        }};\n    }}\n}};\n\nexports.handler = handler;\n        \"\"\",\n        \"test\": f\"\"\"\n# tests\/unit\/{name}.test.js\nconst {{ handler }} = require('..\/..\/src\/handlers\/{name}');\n\ndescribe('{name} Lambda', () =&gt; {{\n    it('should return success response', async () =&gt; {{\n        const event = {{}};\n        const result = await handler(event);\n        expect(result.statusCode).toBe(200);\n    }});\n}});\n        \"\"\",\n        \"sam_template\": f\"\"\"\n  {name}Function:\n    Type: AWS::Serverless::Function\n    Properties:\n      Handler: src\/handlers\/{name}\/index.handler\n      Runtime: nodejs18.x\n      Events:\n        ApiEvent:\n          Type: Api\n          Properties:\n            Path: {api_path}\n            Method: post\n        \"\"\"\n    }\n\ndef main(function_name: str, api_path: str):\n    template = create_function_template(function_name, api_path)\n\n    # \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u6210\n    os.makedirs(f\"src\/handlers\/{function_name}\", exist_ok=True)\n    os.makedirs(f\"tests\/unit\", exist_ok=True)\n\n    # \u30d5\u30a1\u30a4\u30eb\u751f\u6210\n    with open(f\"src\/handlers\/{function_name}\/index.js\", \"w\") as f:\n        f.write(template[\"template\"])\n\n    with open(f\"tests\/unit\/{function_name}.test.js\", \"w\") as f:\n        f.write(template[\"test\"])\n\n    print(f\"SAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9:\\n{template['sam_template']}\")\n\nif __name__ == \"__main__\":\n    if len(sys.argv) != 3:\n        print(\"Usage: python generate_function.py &lt;function_name&gt; &lt;api_path&gt;\")\n        sys.exit(1)\n\n    main(sys.argv[1], sys.argv[2])<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-45\">\u30b3\u30b9\u30c8\u6700\u9069\u5316\u306e\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-46\">1. \u30ea\u30bd\u30fc\u30b9\u4f7f\u7528\u52b9\u7387\u306e\u6700\u9069\u5316<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># template.yaml\nGlobals:\n  Function:\n    # \u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u306e\u6700\u9069\u5316\n    MemorySize: 128\n    # \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306e\u9069\u5207\u306a\u8a2d\u5b9a\n    Timeout: 6\n    # \u540c\u6642\u5b9f\u884c\u6570\u306e\u5236\u9650\n    ReservedConcurrentExecutions: 100\n\nResources:\n  OptimizedFunction:\n    Type: AWS::Serverless::Function\n    Properties:\n      # Provisioned Concurrency\u306e\u8a2d\u5b9a\n      ProvisionedConcurrencyConfig:\n        ProvisionedConcurrentExecutions: 5\n      # \u30ec\u30a4\u30e4\u30fc\u306e\u6d3b\u7528\n      Layers:\n        - !Ref CommonLibsLayer<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-47\">2. \u30b3\u30b9\u30c8\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u306e\u8a2d\u5b9a<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Resources:\n  CostAlarm:\n    Type: AWS::CloudWatch::Alarm\n    Properties:\n      AlarmName: !Sub ${AWS::StackName}-CostAlarm\n      AlarmDescription: Daily cost exceeded threshold\n      MetricName: EstimatedCharges\n      Namespace: AWS\/Billing\n      Statistic: Maximum\n      Period: 21600  # 6\u6642\u9593\n      EvaluationPeriods: 1\n      Threshold: 10  # 10\u30c9\u30eb\n      ComparisonOperator: GreaterThanThreshold\n      AlarmActions:\n        - !Ref AlertTopic<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-48\">\u5927\u898f\u6a21\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u6d3b\u7528\u4e8b\u4f8b<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-49\">1. \u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u5b9f\u88c5\u4f8b<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u8907\u6570\u306e\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u3092\u7ba1\u7406\u3059\u308bSAM\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\nResources:\n  # \u30e6\u30fc\u30b6\u30fc\u30b5\u30fc\u30d3\u30b9\n  UserService:\n    Type: AWS::Serverless::Application\n    Properties:\n      Location: .\/services\/user-service\/template.yaml\n      Parameters:\n        Environment: !Ref Environment\n\n  # \u6ce8\u6587\u30b5\u30fc\u30d3\u30b9\n  OrderService:\n    Type: AWS::Serverless::Application\n    Properties:\n      Location: .\/services\/order-service\/template.yaml\n      Parameters:\n        Environment: !Ref Environment\n\n  # \u6c7a\u6e08\u30b5\u30fc\u30d3\u30b9\n  PaymentService:\n    Type: AWS::Serverless::Application\n    Properties:\n      Location: .\/services\/payment-service\/template.yaml\n      Parameters:\n        Environment: !Ref Environment<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-50\">2. \u958b\u767a\u30c1\u30fc\u30e0\u3067\u306e\u52b9\u7387\u7684\u306a\u5354\u696d\u65b9\u6cd5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u9020\nproject\/\n\u251c\u2500\u2500 services\/\n\u2502   \u251c\u2500\u2500 user-service\/\n\u2502   \u2502   \u251c\u2500\u2500 template.yaml\n\u2502   \u2502   \u2514\u2500\u2500 src\/\n\u2502   \u251c\u2500\u2500 order-service\/\n\u2502   \u2502   \u251c\u2500\u2500 template.yaml\n\u2502   \u2502   \u2514\u2500\u2500 src\/\n\u2502   \u2514\u2500\u2500 payment-service\/\n\u2502       \u251c\u2500\u2500 template.yaml\n\u2502       \u2514\u2500\u2500 src\/\n\u251c\u2500\u2500 layers\/\n\u2502   \u2514\u2500\u2500 common\/\n\u251c\u2500\u2500 scripts\/\n\u2502   \u251c\u2500\u2500 deploy.sh\n\u2502   \u2514\u2500\u2500 generate_function.py\n\u2514\u2500\u2500 template.yaml\n\n# \u30c1\u30fc\u30e0\u958b\u767a\u7528\u306eMakefile\u306e\u4f8b\nMakefile:\nmake install:\n    npm install\n\nmake test:\n    npm test\n\nmake lint:\n    eslint .\n\nmake build:\n    sam build\n\nmake deploy-dev:\n    .\/scripts\/deploy.sh dev\n\nmake deploy-prod:\n    .\/scripts\/deploy.sh prod<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-51\">3. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u306e\u5b9f\u4f8b<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Lambda\u95a2\u6570\u306e\u6700\u9069\u5316\u4f8b\nconst AWS = require('aws-sdk');\nconst dynamodb = new AWS.DynamoDB.DocumentClient();\n\n\/\/ \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\u518d\u5229\u7528\nconst ddbClient = new AWS.DynamoDB.DocumentClient({\n    maxRetries: 3,\n    httpOptions: {\n        timeout: 5000,\n        connectTimeout: 3000\n    }\n});\n\n\/\/ \u30d0\u30c3\u30c1\u51e6\u7406\u306e\u6700\u9069\u5316\nconst processBatch = async (items) =&gt; {\n    const batchSize = 25;  \/\/ DynamoDB\u306e\u5236\u9650\n    const batches = [];\n\n    for (let i = 0; i &lt; items.length; i += batchSize) {\n        const batch = items.slice(i, i + batchSize);\n        batches.push(batch);\n    }\n\n    const promises = batches.map(async (batch) =&gt; {\n        const params = {\n            RequestItems: {\n                'TableName': batch.map(item =&gt; ({\n                    PutRequest: {\n                        Item: item\n                    }\n                }))\n            }\n        };\n\n        return ddbClient.batchWrite(params).promise();\n    });\n\n    await Promise.all(promises);\n};<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u52b9\u7387\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u958b\u767a\u901f\u5ea6\u306e\u5411\u4e0a\u3001\u904b\u7528\u30b3\u30b9\u30c8\u306e\u524a\u6e1b\u3001\u305d\u3057\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u306e\u54c1\u8cea\u5411\u4e0a\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002\u7279\u306b\u5927\u898f\u6a21\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u3001\u81ea\u52d5\u5316\u30b9\u30af\u30ea\u30d7\u30c8\u3084\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306e\u6d3b\u7528\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: Undefined array key &#8220;is_admin&#8221; in \/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/ &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":{"0":"post-2434","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-aws","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2434"}],"version-history":[{"count":1,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2434\/revisions"}],"predecessor-version":[{"id":2435,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2434\/revisions\/2435"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}