{"id":32568,"date":"2023-12-07T16:05:28","date_gmt":"2023-11-24T23:47:18","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/"},"modified":"2024-05-04T12:32:02","modified_gmt":"2024-05-04T04:32:02","slug":"%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/","title":{"rendered":"\u5728Sam\u4e2d\u90e8\u7f72Lambda"},"content":{"rendered":"<h1>\u76ee\u5f55 (m\u00f9 l\u00f9)<\/h1>\n<p>\u30fbSam\u7684\u5b89\u88c5<br \/>\n\u30fb\u521d\u59cb\u5316Sam<br \/>\n\u30fb\u6784\u5efaSam<br \/>\n\u30fb\u521b\u5efasamconfig.toml\u6587\u4ef6<br \/>\n\u30fb\u90e8\u7f72Sam<\/p>\n<h1>\u5c71\u59c6\u7684\u5f15\u8fdb de<\/h1>\n<p>\u4f7f\u7528brew\u8fdb\u884c\u5b89\u88c5<\/p>\n<pre class=\"post-pre\"><code>$ brew tap aws\/tap\r\n$ brew install aws-sam-cli\r\n<\/code><\/pre>\n<p>\u6216\u8005\u901a\u8fc7pip\u5b89\u88c5<\/p>\n<pre class=\"post-pre\"><code>$ pip install aws-sam-cli\r\n<\/code><\/pre>\n<h1>\u4f7f\u7528sam init<\/h1>\n<p>\u6211\u4f1a\u4ee5\u5bf9\u8bdd\u5f62\u5f0f\u6765\u521b\u5efa\u9879\u76ee\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sam init\r\nWhich template source would you like to use?\r\n        1 - AWS Quick Start Templates\r\n        2 - Custom Template Location\r\nChoice: 1\r\nWhat package type would you like to use?\r\n        1 - Zip (artifact is a zip uploaded to S3)\r\n        2 - Image (artifact is an image uploaded to an ECR image repository)\r\nPackage type: 1\r\n\r\nWhich runtime would you like to use?\r\n        1 - nodejs14.x\r\n        2 - python3.8\r\n        3 - ruby2.7\r\n        4 - go1.x\r\n        5 - java11\r\n        6 - dotnetcore3.1\r\n        7 - nodejs12.x\r\n        8 - nodejs10.x\r\n        9 - python3.7\r\n        10 - python3.6\r\n        11 - python2.7\r\n        12 - ruby2.5\r\n        13 - java8.al2\r\n        14 - java8\r\n        15 - dotnetcore2.1\r\nRuntime: 1\r\n\r\nProject name [sam-app]: Test\r\n\r\nCloning from https:\/\/github.com\/aws\/aws-sam-cli-app-templates\r\n\r\nAWS quick start application templates:\r\n        1 - Hello World Example\r\n        2 - Step Functions Sample App (Stock Trader)\r\n        3 - Quick Start: From Scratch\r\n        4 - Quick Start: Scheduled Events\r\n        5 - Quick Start: S3\r\n        6 - Quick Start: SNS\r\n        7 - Quick Start: SQS\r\n        8 - Quick Start: Web Backend\r\nTemplate selection: 1\r\n\r\n    -----------------------\r\n    Generating application:\r\n    -----------------------\r\n    Name: Test\r\n    Runtime: nodejs14.x\r\n    Dependency Manager: npm\r\n    Application Template: hello-world\r\n    Output Directory: .\r\n\r\n    Next steps can be found in the README file at .\/Test\/README.md\r\n<\/code><\/pre>\n<h1>\u7528\u672c\u5730\u73af\u5883\u8c03\u7528sam<\/h1>\n<p>\u56e0\u4e3a\u542f\u52a8\u4e86\u4e00\u4e2a\u7b80\u6613\u7684\u9879\u76ee\uff0c\u6240\u4ee5\u6211\u4f1a\u7acb\u523b\u8bd5\u7740\u8fd0\u884c\u5b83\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sam local invoke\r\n{\"statusCode\":200,\"body\":\"{\\\"message\\\":\\\"hello world\\\"}\"}\r\n<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Docker\u5728\u672c\u5730\u73af\u5883\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sam local invoke -e path\/event.json\r\n<\/code><\/pre>\n<p>\u5f53\u60a8\u6307\u5b9a-e\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9alambda\u5728\u6267\u884c\u65f6\u8981\u4f7f\u7528\u7684\u4e8b\u4ef6\u4fe1\u606f\u8fdb\u884c\u6267\u884c\u3002<\/p>\n<h1>\u521b\u5efasamconfig.toml\u3002<\/h1>\n<pre class=\"post-pre\"><code>$ sam deploy --guided\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u5bf9\u8bdd\u5f62\u5f0f\u521b\u5efa\u90e8\u7f72\u8bbe\u7f6e\u6587\u4ef6samconfig.toml\u3002<\/p>\n<h1>\u90e8\u7f72Sam<\/h1>\n<pre class=\"post-pre\"><code>$ cd .aws-sam\/build\r\n$ sam deploy\r\n<\/code><\/pre>\n<p>\u5982\u679c\u90e8\u7f72\u6210\u529f\uff0c\u90a3\u5c31\u6ca1\u95ee\u9898\u4e86\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u4eceCloudFormation\u7684\u7ba1\u7406\u63a7\u5236\u53f0\u4e2d\u786e\u8ba4\u90e8\u7f72\u60c5\u51b5\u3002<br \/>\n\u6b64\u5916\uff0c\u5728Lambda\u4e2d\u60a8\u4e5f\u53ef\u4ee5\u5bf9\u51fd\u6570\u8fdb\u884c\u6d4b\u8bd5\u6267\u884c\u3002<\/p>\n<p>\u56e0\u4e3a\u53ef\u4ee5\u5c1d\u8bd5\u8bb8\u591a\u4e0d\u540c\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u4e00\u65e6\u6709\u4e86\u4fe1\u606f\u7684\u6574\u7406\uff0c\u6211\u4f1a\u8fdb\u884c\u66f4\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 (m\u00f9 l\u00f9) \u30fbSam\u7684\u5b89\u88c5 \u30fb\u521d\u59cb\u5316Sam \u30fb\u6784\u5efaSam \u30fb\u521b\u5efasamconfig.toml\u6587\u4ef6 \u30fb [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32568","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728Sam\u4e2d\u90e8\u7f72Lambda - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728sam\u4e2d\u90e8\u7f72lambda\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728Sam\u4e2d\u90e8\u7f72Lambda\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 (m\u00f9 l\u00f9) \u30fbSam\u7684\u5b89\u88c5 \u30fb\u521d\u59cb\u5316Sam \u30fb\u6784\u5efaSam \u30fb\u521b\u5efasamconfig.toml\u6587\u4ef6 \u30fb [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728sam\u4e2d\u90e8\u7f72lambda\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-24T23:47:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T04:32:02+00:00\" \/>\n<meta name=\"author\" content=\"\u79d1, \u96c5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u96c5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/\",\"name\":\"\u5728Sam\u4e2d\u90e8\u7f72Lambda - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-11-24T23:47:18+00:00\",\"dateModified\":\"2024-05-04T04:32:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728Sam\u4e2d\u90e8\u7f72Lambda\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\",\"name\":\"\u79d1, \u96c5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u96c5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728Sam\u4e2d\u90e8\u7f72Lambda - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728sam\u4e2d\u90e8\u7f72lambda\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728Sam\u4e2d\u90e8\u7f72Lambda","og_description":"\u76ee\u5f55 (m\u00f9 l\u00f9) \u30fbSam\u7684\u5b89\u88c5 \u30fb\u521d\u59cb\u5316Sam \u30fb\u6784\u5efaSam \u30fb\u521b\u5efasamconfig.toml\u6587\u4ef6 \u30fb [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728sam\u4e2d\u90e8\u7f72lambda\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-11-24T23:47:18+00:00","article_modified_time":"2024-05-04T04:32:02+00:00","author":"\u79d1, \u96c5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u96c5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/","name":"\u5728Sam\u4e2d\u90e8\u7f72Lambda - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-11-24T23:47:18+00:00","dateModified":"2024-05-04T04:32:02+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728Sam\u4e2d\u90e8\u7f72Lambda"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a","name":"\u79d1, \u96c5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","caption":"\u79d1, \u96c5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8sam%e4%b8%ad%e9%83%a8%e7%bd%b2lambda\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=32568"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32568\/revisions"}],"predecessor-version":[{"id":98336,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32568\/revisions\/98336"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=32568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=32568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=32568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}