<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Rhea Xiao - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ freeCodeCamp 是一个免费学习编程的开发者社区，涵盖 Python、HTML、CSS、React、Vue、BootStrap、JSON 教程等，还有活跃的技术论坛和丰富的社区活动，在你学习编程和找工作时为你提供建议和帮助。 ]]>
        </description>
        <link>https://www.freecodecamp.org/chinese/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Rhea Xiao - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/chinese/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 09 May 2026 13:42:14 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/chinese/news/author/rhea/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ 如何通过参与开源项目提升技术写作能力 ]]>
                </title>
                <description>
                    <![CDATA[ 你是否在 Hashnode [https://hashnode.com/about] 或者 Dev.to [http://dev.to/]  上写过技术帖子，又是否总想尝试新东西呢？如果是这样的话，有一件事情能帮你一解心头之痒：为开源项目做贡献。 我知道，我知道你肯定已经无数次在 Discord 群组里或在技术相关的社交媒体帖子中听到“为开源做贡献！”的呼吁。但是相信我，身为一名技术写作者，这真的是一个你积累经验的好方式。 一方面，你能参与一些公开展示的项目，这能帮助你向技术写作专业人士展现你的能力。 另一方面，和大家的普遍认识不同，实际上编写代码并不是为开源项目做贡献的唯一方式，你也可以利用自己的写作技能帮助项目维护者进行文档优化。 除此之外，为开源项目做贡献能够帮助你学习新的技术语言和软件，而这被美国劳工统计局描述为 技术写作者的重要技能之一 [https://www.bls.gov/ooh/media-and-communication/technical-writers.htm#tab-4]。 还是无法说服你？没关系，在此指南中，我会探讨如何寻找需要技术写作者的开源项 ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/improve-tech-writing-skills-by-contributing-to-open-source/</link>
                <guid isPermaLink="false">64afa75a486c7406702c8f80</guid>
                
                    <category>
                        <![CDATA[ 科技写作 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Rhea Xiao ]]>
                </dc:creator>
                <pubDate>Fri, 14 Jul 2023 02:00:00 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2023/07/Blog-post-cover-for-FCC---3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>原文：</strong> <a href="https://www.freecodecamp.org/news/improve-tech-writing-skills-by-contributing-to-open-source/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">How to Improve Your Technical Writing Skills by Contributing to Open Source Projects</a>
      </p><!--kg-card-begin: markdown--><p>你是否在 <a href="https://hashnode.com/about">Hashnode</a> 或者 <a href="http://dev.to/">Dev.to</a> 上写过技术帖子，又是否总想尝试新东西呢？如果是这样的话，有一件事情能帮你一解心头之痒：为开源项目做贡献。</p>
<p>我知道，我知道你肯定已经无数次在 Discord 群组里或在技术相关的社交媒体帖子中听到“为开源做贡献！”的呼吁。但是相信我，身为一名技术写作者，这真的是一个你积累经验的好方式。</p>
<p>一方面，你能参与一些公开展示的项目，这能帮助你向技术写作专业人士展现你的能力。</p>
<p>另一方面，和大家的普遍认识不同，实际上编写代码并不是为开源项目做贡献的唯一方式，你也可以利用自己的写作技能帮助项目维护者进行文档优化。</p>
<p>除此之外，为开源项目做贡献能够帮助你学习新的技术语言和软件，而这被美国劳工统计局描述为 <a href="https://www.bls.gov/ooh/media-and-communication/technical-writers.htm#tab-4">技术写作者的重要技能之一</a>。</p>
<p>还是无法说服你？没关系，在此指南中，我会探讨如何寻找需要技术写作者的开源项目，也会介绍通过技术写作能为开源项目做什么贡献，并且就如何公开展示这些贡献提出建议。</p>
<h2 id="">如何寻找需要技术写作贡献的开源项目</h2>
<p>许多开源项目在文档方面都需要帮助，而你需要根据自己的兴趣、技术写作水平以及贡献机会来选择你将参与贡献的项目。</p>
<p>在寻找需要贡献的开源项目时，我强烈建议你向同事询问他们参与的项目。与朋友合作+参与开源项目，这难道不是一举两得吗！:) 在选择了项目之后，我建议你做这些事情：</p>
<ol>
<li>前往项目仓库的 <strong>Issues</strong> 选项卡。</li>
</ol>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/picking-an-issue--part-1-.png" alt="黄色箭头指向 Issues 选项卡" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>黄色箭头指向 Issues 选项卡</figcaption>
</figure>
<ol start="2">
<li>单击 <strong>Label</strong> 选项</li>
</ol>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/Picking-a-issue--part-2--1.png" alt="橙色箭头指向 Label 选项" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>橙色箭头指向 Label 选项</figcaption>
</figure>
<ol start="3">
<li>在文本框中输入 "documentation"，就可以啦！</li>
</ol>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/picking-an-issue--part-3-.png" alt="documentation 显示在文本框中" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>"documentation" 显示在文本框中</figcaption>
</figure>
<p>现在如果你想寻找一些更具体的项目，我在这里列出了一些重点关注文档的开源项目：</p>
<h3 id="thegooddocsproject">The Good Docs Project</h3>
<p>如果你正在寻找开源项目来积累文档写作的入门经验，我强烈建议你加入 <a href="https://thegooddocsproject.dev/">这个群组</a>. :) 他们有多个工作组，且关注不同类型的写作，包括创作文档模板供其他开发者在自己的开源项目中使用、优化组织的网站内容以及为社群成员已创建的模板做 QA （质量验证）。</p>
<h3 id="codecademy">Codecademy</h3>
<p>如果你精通某种特定的编程语言并想向其他人分享相关知识，我强烈建议你为 Codecademy 的 <a href="https://github.com/Codecademy/docs">文档</a> 和 <a href="https://github.com/Codecademy/ugc">文章</a> 仓库做贡献。他们基于不同需求提供模板，比如为特定章节提供新条目并更新/编辑现有条目。</p>
<h3 id="astro">Astro</h3>
<p>如果你是 Astro 的狂热用户, 那你可以在他们的 <a href="https://github.com/withastro/docs">docs repo</a> 中分享该软件的使用建议，他们的文档组非常乐于与拥有不同经验水平的成员合作。</p>
<p>选择项目仅仅是其中一步，接下来让我们看看技术写作者为开源项目做贡献的不同方式。</p>
<h2 id="">技术写作者为开源做贡献的不同方式</h2>
<p>恭喜！你已经选择了自己的贡献项目。现在，你需要决定如何利用自己的技术写作技能做贡献。</p>
<p>我知道这一步很难，但不要担心。现在，我们将讨论你能做出哪些不同类型的贡献。</p>
<h3 id="readme">修改 README 文件中的拼写错误和其他语法错误</h3>
<p>README 文件是开源项目的重要基础，其中会描述项目的目标和贡献步骤，因此 README 文件应该尽可能表达清晰。</p>
<p>如果你在阅读 README 文件时发现逗号缺失或者句子表述不清，你可以向项目维护者发起 issue 并进行编辑（当然，前提是他们通过你发起的 issue）。</p>
<p>我在刚加入 EddieHub 社区的时候就是通过这种方式做贡献。这不仅仅是一种很好的自我介绍方式，也教会我根据特定受众来定制文档。当然，这不是为开源项目做文档贡献的唯一方式，让我们来看看另外一种方式！:)</p>
<h3 id="">创建内部文档风格指南</h3>
<p>这需要创建一个指南，其中将定义某个开源项目文档的写作和格式标准，从而指导贡献者有效地进行开源项目的文档写作。</p>
<p>在该文档中，你将看见一些诸如标点符号的正确和错误书写方式、代码块格式化的特定方法以及产品文档的语气语调等信息。</p>
<p><a href="https://developers.google.com/style/contractions">Google 开发者文档中的缩写形式</a> 便是一个很好的例子。</p>
<p>在看到 <a href="https://www.youtube.com/live/t-Tz6QzH8YA?feature=share">Document Write 的 YouTube 频道</a> 中 Portia 的一则视频后，我决定撰写 <a href="https://linkfree.io/docs/docs-style-guide">一份针对 EddieHub 的 Linkfree 项目的文档风格指南</a>。她在视频中谈论了开源贡献者，尤其想要将技术写作作为职业的贡献者，如何从这些风格指南中受益。</p>
<p>通过创建这份风格指南，我学到以下知识：</p>
<ol>
<li><strong>以新的风格或语言编写:</strong> 由于 Linkfree 的主要受众来自英国，项目维护者希望使用英式英语来撰写风格指南。我之前从来没有使用过英式英语，所以需要重新学习单词的拼写、大写以及标点符号的使用，这是一个非常有趣的过程。</li>
<li><strong>使用新的技术工具或框架:</strong> <a href="https://mdxjs.com/">MDX (Markdown X)</a> 是贡献者用于维护 Linkfree 文档的一种技术语言。简单来说，你能在 Markdown 文档中使用 <a href="https://facebook.github.io/jsx/">JSX</a> （让你将 HTML 代码嵌入 JavaScript 的语法）。我曾短暂地使用过 Markdown，所以我能更轻松地使用这种语言来创建文档指南。</li>
</ol>
<p>当然，撰写风格指南也只是为开源项目做文档贡献的其中一种方式，让我们再来看看另外一种方式吧！:)</p>
<h3 id="">添加产品教程</h3>
<p>如果你善于指导他人，或者你在阅读开源软件教程时发现关键信息缺失，你可以考虑通过这种方式来做贡献。</p>
<p>Audacity 网站上的 <a href="https://support.audacityteam.org/community/contributing/tutorials">tutorial 章节</a> 就是一个很好的例子，而 Audacity 是一个免费的录音及音频编辑的开源软件。</p>
<p>作为开源社区的新人，我发现大多数入门级的内容并没有提供关于贡献者如何在找工作或面试时利用开源贡献经验的建议。因此，我在 Github 上浏览  OpenSauced 的仓库时，发现这些内容对于他们的 Intro to Open Source 免费课程很有帮助。</p>
<p>于是，我将这种想法传达给了公司的用户体验经理 <a href="https://twitter.com/BekahHW">Bekah</a>，创建了一个拉取请求，并且最终 <a href="https://github.com/open-sauced/intro/pull/5">它被合并啦</a>！</p>
<p>我强烈推荐你去做这种类型的贡献，因为练习的绝佳方式就是简化技术文档，使之便于全球不同技术水平的读者阅读。同时，这也能培养你注重细节的能力。</p>
<p>那么，在你着手通过参与开源贡献来积累技术写作经验之前，你现在还需要考虑一件事。</p>
<h2 id="">展示你的作品</h2>
<p>当谈及展示作品的重要性时，Austin Kielon 说得最好：“展示你的作品吧”。</p>
<p>我想说的是，我们是大声疾呼的作者，通过文字展示内容是刻在我们骨子里的东西，那为什么不展示自己的作品呢？</p>
<p>你可以通过撰写博客、在社交媒体上发帖子，或者录制一集播客来展示你参与的项目。</p>
<p>如果你想通过一种更系统化的方式来展示作品，我推荐你使用 <a href="https://opensauced.pizza/#features">OpenSauced</a> 免费的 Chrome 拓展插件。利用这款工具，你能追踪你正在做贡献以及计划做贡献的 GitHub 开源仓库。</p>
<p>除此之外，这款工具还具备 “Highlights” 功能，你可以选择将某些贡献发布到个人档案，并将它分享在领英和推特上。了解详细操作信息，请查阅 <a href="https://github.com/open-sauced/intro/blob/main/06-the-secret-sauce.md#develop-your-open-source-resume">教程</a>。</p>
<p>在你参加工作面试时，这些能作为你很好的作品参考。除此，这也能为其他开源贡献者提供灵感。在将我为 Linkfree 创建的文档风格指南分享到推特后，我的一位同事非常喜欢它，所以她认为为她的项目也创建一份文档风格指南是一个不错的做法。于是在她的邀请下，[我创建了一份文档风格指南]。(<a href="https://github.com/AccessibleForAll/AccessibleWebDev/blob/main/docs-style-guide.md">https://github.com/AccessibleForAll/AccessibleWebDev/blob/main/docs-style-guide.md</a>)! :) 所以，永远不要低估展示作品的力量！</p>
<p>朋友们，这就是我为你们提供的关于如何通过参与开源贡献提升技术写作能力的指南。我知道，你在真正动手做的时候可能会害怕，尤其在刚开始的时候。但是，根据这些建议来实践并保持积极的态度，我相信你会成功的！</p>
<h2 id="">鸣谢</h2>
<p><a href="https://uxwing.com/opensource-icon">UXwing</a> 提供的开源标志</p>
<p>Ylivdesign 在 <a href="https://www.dreamstime.com/technical-writing-icon-outline-style-technical-writing-icon-outline-technical-writing-vector-icon-web-design-isolated-white-image214934937">Dreamstime</a>上提供的技术写作图标</p>
<!--kg-card-end: markdown--> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 如何使用 AWS API Gateway 向用户提供自定义 API ]]>
                </title>
                <description>
                    <![CDATA[ 在云计算领域和 serverless 架构中，AWS API Gateway 是一款强大的工具，能帮助您搭建强大、安全且可拓展的 API。 在本教程中，首先我将介绍 API 网关是什么，并解释使用 API 网关的好处。接下来，我将展示如何创建、部署一个 Rest API, 并创建使用计划以提供 API 密钥。那么，我们现在就开始吧！ 什么是 API 网关？ AWS API Gateway 是 Amazon Web Services (AWS) 提供的一项全托管服务，可帮助您轻松搭建、部署和管理任意规模的 API。 它充当应用程序的前门，允许您创建充当客户端和后端服务之间桥梁的 API，以便实现安全有效的通信。 为什么需要 API 网关？ AWS API Gateway 可为企业和开发者提供诸多好处，下方列出了一些使用 API 网关的好处。 可拓展性和高可用性 借助 AWS API Gateway，您可以更轻松地进行 API 拓展。通过底层基础设施自动拓展， AWS API ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/how-to-offer-custom-apis-to-your-users-aws-api-gateway/</link>
                <guid isPermaLink="false">64af9123486c7406702c8ed7</guid>
                
                    <category>
                        <![CDATA[ 云计算 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ API ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Rhea Xiao ]]>
                </dc:creator>
                <pubDate>Thu, 13 Jul 2023 06:13:58 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2023/07/AWS-API-Gateway-Banner-3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>原文：</strong> <a href="https://www.freecodecamp.org/news/how-to-offer-custom-apis-to-your-users-aws-api-gateway/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">How to Offer Custom APIs to Your Users with AWS API Gateway</a>
      </p><!--kg-card-begin: markdown--><p>在云计算领域和 serverless 架构中，AWS API Gateway 是一款强大的工具，能帮助您搭建强大、安全且可拓展的 API。</p>
<p>在本教程中，首先我将介绍 API 网关是什么，并解释使用 API 网关的好处。接下来，我将展示如何创建、部署一个 Rest API, 并创建使用计划以提供 API 密钥。那么，我们现在就开始吧！</p>
<h2 id="api">什么是 API 网关？</h2>
<p>AWS API Gateway 是 Amazon Web Services (AWS) 提供的一项全托管服务，可帮助您轻松搭建、部署和管理任意规模的 API。</p>
<p>它充当应用程序的前门，允许您创建充当客户端和后端服务之间桥梁的 API，以便实现安全有效的通信。</p>
<h2 id="api">为什么需要 API 网关？</h2>
<p>AWS API Gateway 可为企业和开发者提供诸多好处，下方列出了一些使用 API 网关的好处。</p>
<h3 id="">可拓展性和高可用性</h3>
<p>借助 AWS API Gateway，您可以更轻松地进行 API 拓展。通过底层基础设施自动拓展， AWS API Gateway 可以无缝处理流量高峰，以确保高可用性并避免服务中断。</p>
<h3 id="">安全与认证</h3>
<p>API 网关提供强大的安全功能，包括内置的身份验证和授权机制。</p>
<p>它支持通过 IAM 角色对内部应用程序进行用户身份验证，通过 Cognito 对外部应用程序进行身份验证，并且支持自定义授权者。</p>
<h3 id="aws">与其他 AWS 服务集成</h3>
<p>作为 AWS 生态系统的一部分， API 网关与一系列其他 AWS 服务无缝集成，这意味着您能利用 AWS Lambda 函数、用于用户管理的 AWS Cognito，以及用于监管和日志记录的 AWS CloudWatch 等其他功能。</p>
<h3 id="api">API 生命周期管理</h3>
<p>利用 API 网关，您能轻松对不同阶段的 API 进行版本控制、部署及管理。这简化了发布更新、测试新功能以及管理不同环境（比如开发、预生产和生产）的过程。</p>
<p>我希望现在您已经了解了 API 网关是什么以及它为何如此重要。接下来让我们一起来创建自己的 API 网关吧！</p>
<h2 id="awsapigateway">如何创建 AWS API Gateway</h2>
<p>在本节中，我们将：</p>
<ul>
<li>采用 GET 方法创建 Rest API</li>
<li>将其与简单的 hello world lambda 函数集成并进行部署</li>
</ul>
<p>让我们从创建 lambda 函数开始吧</p>
<h2 id="awslambda">如何创建 AWS Lambda 函数</h2>
<p>登录 AWS Management <a href="https://console.aws.amazon.com/">控制台</a> 并在控制台搜索栏中搜索 "Lambda"。然后，单击 Create Function 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-145.png" alt="导航至 AWS Lambda 控制台" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>导航至 AWS Lambda 控制台</figcaption>
</figure>
<p>选择 "Author from scratch" 选项，输入 lambda 函数名称，选择 "Python" Runtime，然后单击右下方的 Create Function 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-146.png" alt="创建一个 AWS Lambda Function" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>创建一个 AWS Lambda Function</figcaption>
</figure>
<p>函数创建成功后，请更新下方代码并部署更改：</p>
<pre><code class="language-Python">import json

def lambda_handler(event, context):
    body = "Hello from 5minslearn!"
    statusCode = 200
    return {
        "statusCode": statusCode,
        "body": json.dumps(body),
        "headers": {
            "Content-Type": "application/json"
        }
    }
</code></pre>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-147.png" alt="部署 Lambda Function" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>部署 Lambda Function</figcaption>
</figure>
<p>恭喜! 您已成功创建 AWS Lambda 函数，接下来让我们来创建 Rest API。</p>
<h2 id="restapiawslambda">如何创建 Rest API 并将其与 AWS Lambda 集成</h2>
<p>在搜索栏搜索 API Gateway，然后在 REST API 版块中单击 Build 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-183.png" alt="创建 Rest API" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>创建 Rest API</figcaption>
</figure>
<p>选择协议为 Rest，并在 Create new API 选项中选择 New API。在设置选项中输入您选择的 API 名称，并保留 Endpoint Type 的默认选项。然后，单击 Create API 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-148.png" alt="配置创建 Rest API" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>配置创建 Rest API</figcaption>
</figure>
<p>首先单击左上方的 Actions 按钮，然后单击 Method 并选择 GET 方法，再单击勾选图标。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-149.png" alt="创建 Method" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>创建 Method</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-150.png" alt="选择 " get"="" 方法"="" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>选择 "GET" 方法</figcaption>
</figure>
<p>选择 Lambda Function 作为 Integration type，并输入已创建的 Lambda 函数名称。然后，保存此函数。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-151.png" alt="选择 Method 配置" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>选择 Method 配置</figcaption>
</figure>
<p>单击保存后， 屏幕中将弹出 "Add Permission to Lambda Function"消息提示确认，这就意味着您将允许 API Gateway 调用 Lambda 函数（在本例中指的就是 "DemoFunction" Lambda 函数）。请同意确认，并继续下一步。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-152.png" alt="image-152" width="600" height="400" loading="lazy"></p>
<p>同意授权通过 API 网关调用 Lambda Function</p>
<p>单击 Test，您将来到一个新页面。单击 "Test" 按钮，此时您能在右侧面板上看到 Lambda 函数做出的响应。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-153.png" alt="我们的 API 架构" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>我们的 API 架构</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-184.png" alt="测试我们的 API 网关" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>测试我们的 API 网关</figcaption>
</figure>
<p>在成功测试 API 后，您就能部署 API 了。要部署 API，请再次单击 Actions 按钮，然后单击 Deploy API。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-185.png" alt="部署 API 网关" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>部署 API 网关</figcaption>
</figure>
<p>此时屏幕上将弹出 Deploy API 的对话框，请选择 New Stage 作为 Deployment stage，并对其进行命名。然后，单击 Deploy 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-155.png" alt="配置 API 网关部署" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>配置 API 网关部署</figcaption>
</figure>
<p>单击页面顶部的 Invoke URL，您将看到 Lambda 做出的响应。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-156.png" alt="API 网关创建成功" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>API 网关创建成功</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-186.png" alt="测试我们的 API" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>测试我们的 API</figcaption>
</figure>
<p>真棒! 我们已经成功创建了 Rest API，将其与 Lambda 函数集成并进行了部署。</p>
<p>但是，您可以通过市场中提供的多种服务来实现这个目标，那为什么要选择 AWS API Gateway 呢？</p>
<p>嗯，这是一个有趣的问题。首先，您可以利用 AWS API Gateway 为自己的 API 配置使用计划，而其中最突出的一点就是您无需为此编写任何代码。</p>
<p>现在就让我们来创建一个使用计划，生成一个 API 密钥，并仅通过在标头中传递 API 密钥来访问 Rest API。</p>
<h2 id="apigateway">如何创建 API Gateway 使用计划</h2>
<p>在左侧边栏中单击 Usage Plans，然后单击 Create 按钮。输入您的计划名称，这里我选择了 "Basic"。根据您的需求在 Throttling 和 Quota 选项中输入相应数值，然后单击 Next。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-159.png" alt="创建 AWS API Gateway 使用计划" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>创建 AWS API Gateway 使用计划</figcaption>
</figure>
<p>单击 Add API Stage 按钮，并选择相应的 API 及其 Stage。然后，单击右上角的勾选图标，并选择 Next。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/Screenshot-from-2023-06-19-10-46-19.png" alt="为我们的 API 创建一个 Stage" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>为我们的 API 创建一个 Stage</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-164.png" alt="为我们的 API 创建一个 Stage" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>为我们的 API 创建一个 Stage</figcaption>
</figure>
<p>单击 "Create API Key and add to Usage Plan"，屏幕上将弹出一个对话框，请输入 API 密钥名称。而关于 API 密钥，我这里选择了 Auto Generate （自动生成），当然您也可以进行自定义。然后，单击 Save 按钮。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-160.png" alt="创建 API 密钥以访问服务" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>创建 API 密钥以访问服务</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-161.png" alt="配置 API 密钥" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>配置 API 密钥</figcaption>
</figure>
<p>从侧边栏选择 Resources，单击已创建的 GET API，然后单击 Method Request。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-162.png" alt="选择方法" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>选择方法</figcaption>
</figure>
<p>在设置选项中，将 API Key Required 字段更新为 "true" 并单击勾选图标。更新后，务必点击 Actions 下拉菜单以部署更改。否则，变更将不会更新。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-187.png" alt="启用 API Key Required 字段" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>启用 API Key Required 字段</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-165.png" alt="部署 API" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>部署 API</figcaption>
</figure>
<p>现在点击相同的 URL，你会发现神奇的事发生了。</p>
<p>Forbidden （禁止访问）！</p>
<p>因为现在我们的 API 层已受保护，您必须在标头中传递 API 密钥才能访问数据。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-163.png" alt="image-163" width="600" height="400" loading="lazy"></p>
<p>若未提供 API 密钥，则禁止访问。</p>
<p>现在单击侧边栏中的 Usage Plans，选择您的计划并导航至 API 密钥选项卡。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-166.png" alt="访问您的 API 密钥" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>访问您的 API 密钥</figcaption>
</figure>
<p>单击您在步骤 3 中创建的 API 密钥，然后单击 Show， 并复制此 API 密钥。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-188.png" alt="API 密钥列表" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>API 密钥列表</figcaption>
</figure>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2023/06/image-167.png" alt="显示您的 API 密钥" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>显示您的 API 密钥</figcaption>
</figure>
<p>您必须在 'x-api-key' 标头中传递密钥。现在，让我们切换至终端来测试一下。</p>
<p>首先，测试一下在不传递 API 密钥的情况下 Rest API 的响应。打开终端，然后输入下方的 curl 命令。此时，您将再次看到“禁止访问”的消息。</p>
<pre><code class="language-bash">curl --location --request GET '[enter your invoke url]'
--header 'Content-Type: application/json
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-189.png" alt="image-189" width="600" height="400" loading="lazy"></p>
<p>终端中未提供 API 密钥的情况下禁止访问</p>
<p>现在再进行一次测试，在标头中传递 API 密钥，并运行下方 curl 命令：</p>
<pre><code class="language-bash">curl --location --request GET '[your invoke url]' \
--header 'x-api-key: [your api key]' \
--header 'Content-Type: application/json' \
--data-raw ''
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-190.png" alt="image-190" width="600" height="400" loading="lazy"></p>
<p>在 x-api-key 标头中传递 API 密钥时获取的数据</p>
<p>因为在标头中传递了 'x-api-key'，所以您能看到 Lambda 函数输出的结果。</p>
<p>真棒! 您已经成功创建了使用计划，生成了 API 密钥，并将其附加到 Rest API 方法中以及验证了集成。</p>
<h2 id="">总结</h2>
<p>在本教程中，您学习了 AWS API gateway 是什么，以及如何为 Rest API 创建使用计划。</p>
<p>如果您想学习更多关于 AWS Services 的知识，可以订阅我的 <a href="https://5minslearn.gogosoon.com/?ref=fcc_aws_api_gateway">email newsletter</a> (<a href="https://5minslearn.gogosoon.com/?ref=fcc_aws_api_gateway">https://5minslearn.gogosoon.com/</a>) 并在社交媒体上关注我。</p>
<!--kg-card-end: markdown--> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
