

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 AWS 将 Bitbucket 存储库与 AWS Amplify 集成 CloudFormation
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation"></a>

*Alwin Abraham，Amazon Web Services*

## Summary
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-summary"></a>

AWS Amplify 可帮助您快速部署和测试静态网站，无需设置通常所需基础设施。如果您的组织想要使用 Bitbucket 进行源代码控制，无论是迁移现有应用程序代码还是构建新应用程序，都可部署这种模式的方法。通过使用 AWS CloudFormation 自动设置 Amplify，您可以查看自己使用的配置。

此模式描述了如何使用 AWS 将 Bitbucket 存储库与 AWS Amplify 集成， CloudFormation 从而创建前端持续集成和持续部署 (CI/CD) 管道和部署环境。此模式方法意味着你可以为可重复的部署构建 Amplify 前端管道。

## 先决条件和限制
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-prereqs"></a>

**先决条件**** **
+ 活跃 Amazon Web Services (AWS) 账户
+ 含管理员访问权限的活跃 Bitbucket 账户
+ 访问使用 [cURL](https://curl.se/) 或 [Postman](https://www.postman.com/) 应用程序的终端
+ 熟悉 Amplify
+ 熟悉 AWS CloudFormation
+ 熟悉 YAML 格式的文件

## 架构
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-architecture"></a>

![\[Diagram showing user interaction with Bitbucket repository connected to AWS Amplify in AWS 云 region.\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/24ae87ed-aa5d-4114-9c5d-bdcb4d40a78b/images/25d73a9d-d2ae-40bc-9ebc-57f9bd13884a.png)


**技术堆栈**
+ Amplify
+ AWS CloudFormation
+ Bitbucket

## 工具
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-tools"></a>
+ [AWS Amplify](https://docs.aws.amazon.com/amplify/) — Amplify 帮助开发人员开发和部署基于云的移动与网络应用程序。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) — AWS CloudFormation 是一项服务，可帮助您建模和设置 AWS 资源，这样您就可以减少管理这些资源的时间，将更多时间集中在在 AWS 中运行的应用程序上。
+ [Bitbucket](https://bitbucket.org/) – Bitbucket 是一款专为专业团队设计的 Git 存储库管理解决方案。它为你提供了集中位置来管理 Git 存储库、协作处理源代码以及指导你完成开发流程。

 

**代码**

该`bitbucket-amplify.yml`文件（附后）包含此模式的 AWS CloudFormation 模板。

## 操作说明
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-epics"></a>

### 配置 Bitbucket 存储库
<a name="configure-the-bitbucket-repository"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| （可选）创建 Bitbucket 存储库。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html)您也可以使用现有的 Bitbucket 存储库。 | DevOps 工程师 | 
| 打开工作区设置。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html) | DevOps 工程师 | 
| 创建 OAuth 消费者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html) | DevOps 工程师 | 
| 获取 OAuth 访问令牌。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html)`curl -X POST -u "KEY:SECRET" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials `用之前录制的密钥和私密密钥替换 `KEY` 和 `SECRET`。 2. 在不使用引号的情况下，记录访问令牌。该令牌仅在有限时间内有效，默认时间为两个小时。您必须在此时间范围内运行 AWS CloudFormation 模板。 | DevOps 工程师 | 

### 创建和部署 AWS CloudFormation 堆栈
<a name="create-and-deploy-the-aws-cloudformation-stack"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
|  下载 AWS CloudFormation 模板。 | 下载 A `bitbucket-amplify.yml` WS CloudFormation 模板（附后）。除了 Amplify 项目和分支之外，此模板还在 Amplify 中创建 CI/CD 管道。 |  | 
| 创建并部署 AWS CloudFormation 堆栈。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html)5. 选择**下一步**，然后选择**创建堆栈**。 | DevOps 工程师 | 

### 测试 CI/CD 管道
<a name="test-the-ci-cd-pipeline"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 将代码部署到存储库中的分支。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html)有关这方面的更多信息，请参阅 Bitbucket 文档中的 [Basic Git 命令](https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html)。  | 应用程序开发人员 | 

## 相关资源
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation-resources"></a>

[身份验证方法](https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication)（Atlassian 文档）

## 附件
<a name="attachments-24ae87ed-aa5d-4114-9c5d-bdcb4d40a78b"></a>

要访问与此文档相关联的其他内容，请解压以下文件：[attachment.zip](samples/p-attach/24ae87ed-aa5d-4114-9c5d-bdcb4d40a78b/attachments/attachment.zip)