

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 AWS CloudFormation 將 Bitbucket 儲存庫與 AWS Amplify 整合
<a name="integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation"></a>

*Alwin Abraham，Amazon Web Services*

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

AWS Amplify 可協助您快速部署和測試靜態網站，而無需設定通常需要的基礎設施。如果您的組織想要使用 Bitbucket 進行來源控制，無論是遷移現有的應用程式程式碼還是建立新的應用程式，都可以部署此模式的方法。透過使用 AWS CloudFormation 自動設定 Amplify，您可以查看所使用的組態。

此模式說明如何使用 AWS CloudFormation 將 Bitbucket 儲存庫與 AWS Amplify 整合，以建立前端持續整合和持續部署 (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 格式的檔案

## Architecture
<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_tw/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 可協助開發人員開發和部署雲端驅動的行動和 Web 應用程式。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) – AWS CloudFormation 是一項服務，可協助您建立和設定 AWS 資源的模型，以減少管理這些資源的時間，並有更多時間專注於在 AWS 中執行的應用程式。
+ [Bitbucket](https://bitbucket.org/) – Bitbucket 是專為專業團隊設計的 Git 儲存庫管理解決方案。它可讓您集中管理 Git 儲存庫、協作您的原始程式碼，並引導您完成開發流程。

 

**Code**

`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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| （選用） 建立 Bitbucket 儲存庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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_tw/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_tw/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 ``SECRET` 將 `KEY`和 取代為您先前記錄的金鑰和秘密。 2. 不使用引號記錄存取字符。字符僅在有限時間內有效，預設時間為兩小時。您必須在此時間範圍內執行 AWS CloudFormation 範本。 | DevOps 工程師 | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  下載 AWS CloudFormation 範本。 | 下載 `bitbucket-amplify.yml` AWS CloudFormation 範本 （已連接）。除了 Amplify 專案和分支之外，此範本還會在 Amplify 中建立 CI/CD 管道。 |  | 
| 建立和部署 AWS CloudFormation 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將程式碼部署到儲存庫中的分支。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-a-bitbucket-repository-with-aws-amplify-using-aws-cloudformation.html)如需詳細資訊，請參閱 Bitbucket 文件中的[基本 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)