{"id":4164,"date":"2025-12-01T17:11:05","date_gmt":"2025-12-01T09:11:05","guid":{"rendered":"https:\/\/aws-oncloudai.com\/?p=4164"},"modified":"2025-12-01T17:11:05","modified_gmt":"2025-12-01T09:11:05","slug":"aws-sam-empowering-enterprises-to-quickly-build-modern-serverless-applications","status":"publish","type":"post","link":"https:\/\/aws-oncloudai.com\/zh_hk\/aws-sam-empowering-enterprises-to-quickly-build-modern-serverless-applications\/","title":{"rendered":"AWS SAM\uff1a\u5354\u52a9\u4f01\u696d\u5feb\u901f\u5efa\u7f6e\u73fe\u4ee3\u5316\u7121\u4f3a\u670d\u5668\u61c9\u7528"},"content":{"rendered":"<p>\u5728\u7576\u4eca\u5feb\u901f\u8b8a\u5316\u7684\u6578\u4f4d\u6642\u4ee3\uff0c\u4f01\u696d\u5c0d\u66f4\u654f\u6377\u3001\u66f4\u5177\u64f4\u5c55\u6027\u7684\u61c9\u7528\u67b6\u69cb\u9700\u6c42\u6108\u767c\u5f37\u70c8\u3002\u4f5c\u70baAmazon Web Services\uff08AWS\uff09\u7684\u5b98\u65b9\u4ee3\u7406\u5546\uff0c\u5728\u96f2\u7aef\u4e0a\u9577\u671f\u70ba\u4f01\u696d\u63d0\u4f9b\u96f2\u7aef\u8aee\u8a62\u8207\u6280\u8853\u652f\u6301\uff0c\u6211\u5011\u6df1\u77e5**\u7121\u4f3a\u670d\u5668\u67b6\u69cb\uff08Serverless\uff09**\u5df2\u6210\u70ba\u61c9\u7528\u73fe\u4ee3\u5316\u7684\u91cd\u8981\u8def\u5f91\u3002<\/p>\n<p>AWS Serverless Application Model\uff08AWS SAM\uff09\u6b63\u662fAWS \u63a8\u51fa\u70ba\u958b\u767c\u8005\u7684\u6838\u5fc3\u67b6\u69cb\u4e4b\u4e00\uff0c\u65e8\u5728\u5354\u52a9\u4f01\u696d\u4ee5\u66f4\u4f4e\u6210\u672c\u3001\u66f4\u9ad8\u6548\u7387\u5efa\u7f6e\u548c\u90e8\u7f72\u7121\u4f3a\u670d\u5668\u61c9\u7528\u3002<\/p>\n<p>\u4ee5\u4e0b\u5167\u5bb9\u5c07\u5f9e\u5be6\u8e10\u8996\u89d2\u70ba\u60a8\u7cfb\u7d71\u4ecb\u7d39AWS SAM \u7684\u80fd\u529b\u8207\u50f9\u503c\u3002<\/p>\n<h4><\/h4>\n<h4>AWS SAM \u7c21\u4ecb\uff1a\u7c21\u5316\u7121\u4f3a\u670d\u5668\u61c9\u7528\u7684\u4e00\u7ad9\u5f0f\u6846\u67b6<\/h4>\n<p>AWS SAM \u662fAWS \u5b98\u65b9\u63a8\u51fa\u7684\u958b\u6e90\u6846\u67b6\uff0c\u7528\u65bc\u7c21\u5316\u7121\u4f3a\u670d\u5668\u61c9\u7528\u7684\u5efa\u7f6e\u3001\u6e2c\u8a66\u8207\u90e8\u7f72\u6d41\u7a0b\u3002<\/p>\n<p>\u501f\u52a9SAM\uff0c\u4f01\u696d\u80fd\u5920\uff1a<\/p>\n<ul>\n<li><strong>\u66f4\u5feb\u901f\u5730\u5b9a\u7fa9\u96f2\u7aef\u4e0a\u8cc7\u6e90<\/strong><\/li>\n<li><strong>\u4ee5\u66f4\u5c11\u7684\u7a0b\u5f0f\u78bc\u5b8c\u6210\u67b6\u69cb\u63cf\u8ff0<\/strong><\/li>\n<li><strong>\u9ad8\u6548\u7387\u7ba1\u7406Lambda\u3001API Gateway\u3001DynamoDB \u7b49\u6838\u5fc3\u670d\u52d9<\/strong><\/li>\n<\/ul>\n<p>SAM \u7bc4\u672c\u4f7f\u7528YAML\/JSON \u63cf\u8ff0\u8cc7\u6e90\uff0c\u662fAWS CloudFormation \u7684\u64f4\u5145\u7248\u672c\uff0c\u8a9e\u6cd5\u66f4\u7cbe\u7c21\u3001\u66f4\u6613\u4e0a\u624b\uff0c\u9069\u5408\u4f01\u696d\u5feb\u901f\u5efa\u7f6e\u7121\u4f3a\u670d\u5668\u5143\u4ef6\u3002<\/p>\n<p>SAM CLI \u5247\u63d0\u4f9b\u4e86\u985eLambda \u7684\u672c\u6a5f\u5075\u932f\u74b0\u5883\uff0c\u8b93\u958b\u767c\u8005\u5728\u672c\u6a5f\u4e0a\u5b8c\u6210\u5efa\u7f6e\u3001\u5075\u932f\u8207\u9810\u90e8\u7f72\u9a57\u8b49\uff0c\u5927\u5e45\u7e2e\u77ed\u958b\u767c\u9031\u671f\u3002<\/p>\n<h4><\/h4>\n<h4>AWS SAM \u7684\u6838\u5fc3\u512a\u52e2<\/h4>\n<h5>1. \u8207\u4e3b\u6d41\u958b\u767c\u5de5\u5177\u6df1\u5ea6\u96c6\u6210<\/h5>\n<p>AWS SAM \u53ef\u8207PyCharm\u3001IntelliJ\u3001VS Code \u7b49\u4e3b\u6d41IDE \u7121\u7e2b\u9023\u63a5\uff0c\u540c\u6642\u6574\u5408AWS \u591a\u9805\u958b\u767c\u670d\u52d9\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>AWS Serverless Application Repository<\/li>\n<li>AWS Cloud9<\/li>\n<li>AWS CodeBuild\u3001CodeDeploy\u3001CodePipeline<\/li>\n<\/ul>\n<p>\u4f01\u696d\u53ef\u4ee5\u5728\u7d71\u4e00\u7684\u5de5\u5177\u93c8\u4e2d\u5b8c\u6210\u958b\u767c\u3001\u6e2c\u8a66\u3001CI\/CD \u4ea4\u4ed8\uff0c\u5be6\u73fe\u9ad8\u6548\u7387\u5354\u540c\u3002<\/p>\n<h5>2. \u5f37\u5927\u7684\u672c\u5730\u6e2c\u8a66\u8207\u8abf\u8a66\u80fd\u529b<\/h5>\n<p>SAM CLI \u63d0\u4f9b\uff1a<\/p>\n<ul>\n<li>Lambda \u7b49\u6548\u57f7\u884c\u74b0\u5883<\/li>\n<li>\u672c\u5730\u4e8b\u4ef6\u89f8\u767c\u6a21\u64ec<\/li>\n<li>\u5feb\u901f\u5efa\u7f6e\u8207\u589e\u91cf\u8abf\u8a66<\/li>\n<li>\u672c\u5730API Gateway \u6a21\u64ec\u670d\u52d9<\/li>\n<\/ul>\n<p>\u9019\u610f\u5473\u8457\u958b\u767c\u5718\u968a\u7121\u9700\u983b\u7e41\u4e0a\u50b3\u90e8\u7f72\uff0c\u5373\u53ef\u76f4\u63a5\u5728\u672c\u5730\u9084\u539f\u751f\u7522\u74b0\u5883\u884c\u70ba\uff0c\u5be6\u73fe\u771f\u6b63\u7684\u654f\u6377\u8fed\u4ee3\u3002<\/p>\n<h5>3. \u57fa\u65bcCloudFormation \u7684\u539f\u751f\u64f4\u5145\u80fd\u529b<\/h5>\n<p>\u4f5c\u70baCloudFormation \u7684\u539f\u751f\u64f4\u5c55\uff0cSAM \u5177\u5099\uff1a<\/p>\n<ul>\n<li>\u5b8c\u6574\u7684IaC\uff08\u57fa\u790e\u8a2d\u65bd\u5373\u7a0b\u5f0f\u78bc\uff09\u80fd\u529b<\/li>\n<li>\u6a21\u677f\u5fa9\u7528\u3001\u53c3\u6578\u5316\u548c\u8cc7\u6e90\u6620\u5c04<\/li>\n<li>\u8207AWS \u5168\u5bb6\u6876\u670d\u52d9\u7684\u6df1\u5ea6\u76f8\u5bb9<\/li>\n<\/ul>\n<p>\u4f01\u696d\u53ef\u4ee5\u7d71\u4e00\u7ba1\u7406\u61c9\u7528\u7a0b\u5f0f\u78bc\u8207\u57fa\u790e\u8a2d\u65bd\u7a0b\u5f0f\u78bc\uff0c\u4f7f\u67b6\u69cb\u7684\u53ef\u7dad\u8b77\u6027\u8207\u4e00\u81f4\u6027\u5927\u5e45\u63d0\u5347\u3002<\/p>\n<h5>4. \u5167\u5efa\u6700\u4f73\u5be6\u8e10\uff0c\u5feb\u901f\u64c1\u6709\u4f01\u696d\u7d1a\u67b6\u69cb\u80fd\u529b<\/h5>\n<p>SAM \u7bc4\u672c\u4e2d\u5df2\u6574\u5408\u591a\u9805AWS \u6700\u4f73\u5be6\u8e10\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5b89\u5168\u90e8\u7f72\u8207\u81ea\u52d5\u56de\u6efe<\/li>\n<li>\u6f38\u9032\u5f0f\u90e8\u7f72\uff08\u7531CodeDeploy \u9a45\u52d5\uff09<\/li>\n<li>\u93c8\u8def\u8ffd\u8e64\uff08AWS X-Ray\uff09<\/li>\n<li>\u6a19\u6e96\u5316\u6b0a\u9650\u7b56\u7565\uff08Policy Templates\uff09<\/li>\n<\/ul>\n<p>\u4f01\u696d\u7121\u9700\u81ea\u884c\u6478\u7d22\uff0c\u5373\u53ef\u76f4\u63a5\u7372\u5f97\u6210\u719f\u7684\u751f\u7522\u7d1a\u67b6\u69cb\u8a2d\u8a08\u3002<\/p>\n<h4><\/h4>\n<h4>AWS SAM \u7684\u5c40\u9650\u6027<\/h4>\n<p>\u4f5c\u70baAWS \u5b98\u65b9\u5de5\u5177\uff0cSAM \u66f4\u9069\u5408\u5728AWS \u751f\u614b\u4e2d\u5efa\u69cb\u61c9\u7528\uff0c\u4f46\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\uff1a<\/p>\n<ul>\n<li><strong>API Gateway \u8a2d\u5b9a\u9748\u6d3b\u5ea6\u7565\u4f4e<\/strong>\uff0c\u4e0d\u5982\u624b\u5de5CloudFormation \u6216Serverless Framework \u81ea\u7531\u3002<\/li>\n<li><strong>\u63d2\u4ef6\u751f\u614b\u8f03\u5c0f<\/strong>\uff0c\u76f8\u8f03Serverless Framework\uff0c\u5176\u793e\u7fa4\u64f4\u5c55\u80fd\u529b\u4ecd\u5728\u767c\u5c55\u4e2d\u3002<\/li>\n<\/ul>\n<p>\u5c0d\u65bc\u4ee5AWS \u70ba\u6838\u5fc3\u96f2\u7aef\u5e73\u53f0\u7684\u4f01\u696d\uff0c\u9019\u4e9b\u9650\u5236\u901a\u5e38\u4e0d\u6703\u69cb\u6210\u4f7f\u7528\u969c\u7919\u3002<\/p>\n<h4><\/h4>\n<h4>\u5982\u4f55\u4f7f\u7528AWS SAM \u5efa\u7f6e\u7121\u4f3a\u670d\u5668\u61c9\u7528<\/h4>\n<h5>1. \u5b89\u88ddSAM CLI<\/h5>\n<p>\u53ef\u900f\u904eHomebrew\u3001pip \u7b49\u65b9\u5f0f\u5feb\u901f\u5b89\u88dd\uff0c\u7121\u9700\u8907\u96dc\u914d\u7f6e\u3002<\/p>\n<h5>2. \u4f7f\u7528\u5b98\u65b9\u7bc4\u4f8b\u5feb\u901f\u5165\u9580<\/h5>\n<p>AWS \u5728GitHub \u4e0a\u63d0\u4f9b\u8c50\u5bcc\u7684\u7bc4\u4f8b\u9805\u76ee\uff0c\u652f\u63f4\u591a\u8a9e\u8a00\u3001\u591a\u67b6\u69cb\u3002<\/p>\n<h5>3. \u5efa\u69cb\u61c9\u7528<\/h5>\n<p>\u900f\u904esam build \u6307\u4ee4\uff0cSAM \u6703\u81ea\u52d5\u5b89\u88dd\u4f9d\u8cf4\u4e26\u7522\u751f\u53ef\u90e8\u7f72\u5957\u4ef6\u3002<\/p>\n<h5>4. \u90e8\u7f72\u61c9\u7528<\/h5>\n<p>SAM \u4f7f\u7528CloudFormation \u4f5c\u70ba\u5e95\u5c64\u90e8\u7f72\u5f15\u64ce\uff0c\u53ea\u9700\u5169\u500b\u6307\u4ee4\u5373\u53ef\u4e0a\u7dda\uff1a<\/p>\n<p>sam package<\/p>\n<p>sam deploy<\/p>\n<p>\u6216\u4f7f\u7528\u7b49\u6548\u7684CloudFormation \u6307\u4ee4\uff1a<\/p>\n<p>aws cloudformation package<\/p>\n<p>aws cloudformation deploy<\/p>\n<p>SAM \u7684\u591a\u7a2e\u8cc7\u6e90\u985e\u578b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>Lambda \u51fd\u6578<\/li>\n<li>API Gateway\uff08REST\/HTTP API\uff09<\/li>\n<li>DynamoDB \u8868<\/li>\n<li>Lambda Layer<\/li>\n<li>Serverless Application Repository \u61c9\u7528<\/li>\n<\/ul>\n<p>\u4e26\u63d0\u4f9bS3\u3001SQS\u3001DynamoDB \u7b49\u6b0a\u9650\u6a21\u677f\uff0c\u5b89\u5168\u8a2d\u5b9a\u66f4\u52a0\u4fbf\u5229\u3002<\/p>\n<h5>5. \u672c\u6a5f\u8207\u96f2\u7aef\u6e2c\u8a66<\/h5>\n<p>\u900f\u904esam local \u53ef\u5728\u672c\u6a5f\u57f7\u884c\u9805\u76ee\uff0c\u4e5f\u53ef\u5728AWS Lambda \u63a7\u5236\u53f0\u5efa\u7acb\u4e8b\u4ef6\u9032\u884c\u96f2\u7aef\u9a57\u8b49\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>Serverless Application Repository\uff1a\u4f01\u696d\u7d1a\u7121\u4f3a\u670d\u5668\u61c9\u7528\u7a0b\u5f0f\u5e02\u5834<\/h4>\n<p>Serverless Application Repository\uff08SAR\uff09\u662fAWS \u63d0\u4f9b\u7684\u7121\u4f3a\u670d\u5668\u61c9\u7528\u4e2d\u5fc3\uff0c\u53ef\u63d0\u4f9b\uff1a<\/p>\n<ul>\n<li>\u53ef\u91cd\u8907\u4f7f\u7528\u7684\u7121\u4f3a\u670d\u5668\u61c9\u7528\u7a0b\u5f0f\u6a21\u677f<\/li>\n<li>\u5718\u968a\/\u4f01\u696d\u9593\u7684\u61c9\u7528\u5206\u4eab\u80fd\u529b<\/li>\n<li>\u4e00\u9375\u5f0f\u90e8\u7f72\uff0c\u7121\u9700\u624b\u52d5\u5efa\u7f6e\u3001\u6253\u5305\u6216\u4e0a\u50b3\u7a0b\u5f0f\u78bc<\/li>\n<li>\u57fa\u65bcIAM \u7684\u8cc7\u6e90\u7d1a\u5b58\u53d6\u63a7\u5236<\/li>\n<\/ul>\n<p>\u4f01\u696d\u53ef\u4ee5\u76f4\u63a5\u5c07\u6700\u4f73\u5be6\u52d9\u5143\u4ef6\u5f15\u5165\u81ea\u8eab\u67b6\u69cb\uff0c\u6e1b\u5c11\u91cd\u8907\u958b\u767c\u6210\u672c\uff0c\u4e26\u63d0\u9ad8\u61c9\u7528\u7a0b\u5f0f\u4ea4\u4ed8\u6548\u7387\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>\u5728\u96f2\u7aef\u4e0a<\/h4>\n<p>\u4f5c\u70baAWS \u5b98\u65b9\u6388\u6b0a\u4ee3\u7406\u5546\uff0c\u6211\u5011\u70ba\u4f01\u696d\u63d0\u4f9b\uff1a<\/p>\n<ul>\n<li>AWS \u67b6\u69cb\u8aee\u8a62\u8207\u8a2d\u8a08<\/li>\n<li>\u7121\u4f3a\u670d\u5668\u61c9\u7528\u958b\u767c\u8207\u9077\u79fb\u6307\u5c0e<\/li>\n<li>\u4f01\u696d\u7d1aCI\/CD \u7ba1\u7dda\u642d\u5efa<\/li>\n<li>\u6210\u672c\u512a\u5316\u3001\u76e3\u63a7\u3001\u7dad\u904b\u670d\u52d9<\/li>\n<li>\u5c08\u696d\u4e0a\u96f2\u57f9\u8a13\u8207\u8a8d\u8b49\u8f14\u5c0e<\/li>\n<\/ul>\n<p>\u5982\u60a8\u5e0c\u671b\u4e86\u89e3\u66f4\u591aServerless \u61c9\u7528\u5be6\u8e10\uff0c\u6b61\u8fce\u96a8\u6642\u806f\u7d61\u6211\u5011\u7684\u6280\u8853\u9867\u554f\u5718\u968a\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728\u7576\u4eca\u5feb\u901f\u8b8a\u5316\u7684\u6578\u4f4d\u6642\u4ee3\uff0c\u4f01\u696d\u5c0d\u66f4\u654f\u6377\u3001\u66f4\u5177\u64f4\u5c55\u6027\u7684\u61c9\u7528\u67b6\u69cb\u9700\u6c42\u6108\u767c\u5f37\u70c8\u3002\u4f5c\u70baAmazon Web Services\uff08AWS\uff09\u7684\u5b98\u65b9\u4ee3\u7406\u5546\uff0c\u5728\u96f2\u7aef\u4e0a\u9577\u671f\u70ba\u4f01\u696d\u63d0\u4f9b\u96f2\u7aef\u8aee\u8a62\u8207\u6280\u8853\u652f\u6301\uff0c\u6211\u5011\u6df1\u77e5**\u7121\u4f3a\u670d\u5668\u67b6\u69cb\uff08Serverless\uff09**\u5df2\u6210\u70ba\u61c9\u7528\u73fe\u4ee3\u5316\u7684\u91cd\u8981\u8def\u5f91\u3002<\/p>","protected":false},"author":1,"featured_media":4165,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4164","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/posts\/4164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/comments?post=4164"}],"version-history":[{"count":1,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/posts\/4164\/revisions"}],"predecessor-version":[{"id":4166,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/posts\/4164\/revisions\/4166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/media\/4165"}],"wp:attachment":[{"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/media?parent=4164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/categories?post=4164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aws-oncloudai.com\/zh_hk\/wp-json\/wp\/v2\/tags?post=4164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}