

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

# 使用二進位方法將內部部署 Go Web 應用程式遷移至 AWS Elastic Beanstalk
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method"></a>

*Suhas Basavaraj 和 Shumaz Mukhtar Kazi，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-summary"></a>

此模式說明如何將內部部署 Go Web 應用程式遷移至 AWS Elastic Beanstalk。應用程式遷移後，Elastic Beanstalk 會建置來源套件的二進位檔，並將其部署至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。

作為重新託管遷移策略，此模式的方法很快，不需要變更程式碼，這表示測試和遷移時間更少。 

## 先決條件和限制
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署 Go Web 應用程式。
+ 包含 Go 應用程式原始碼的 GitHub 儲存庫。如果您不使用 GitHub，還有其他方法可以[為 Elastic Beanstalk 建立應用程式原始碼套件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html)。

**產品版本**
+ Elastic Beanstalk 支援的最新 Go 版本。如需詳細資訊，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)。

## Architecture
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-architecture"></a>

**來源技術堆疊**
+ 內部部署 Go Web 應用程式 

**目標技術堆疊**
+ AWS Elastic Beanstalk
+ Amazon CloudWatch

**目標架構*** *

![\[將 Go 應用程式遷移至 Elastic Beanstalk 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cd8d660d-5621-4ea7-8f97-7a1e321c57d3/images/1df543d9-7073-43d8-abd3-f1f7e57278eb.png)


## 工具
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-tools"></a>
+ [AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html) 可在 AWS 雲端中快速部署和管理應用程式，而使用者不必了解執行這些應用程式的基礎設施。Elastic Beanstalk 可降低管理複雜性而不會限制選擇或控制。
+ [GitHub](https://github.com/) 是一種開放原始碼分散式版本控制系統。

## 史詩
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-epics"></a>

### 建立 Go Web 應用程式原始碼套件 .zip 檔案
<a name="create-the-go-web-application-source-bundle-zip-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Go 應用程式的原始碼套件。 | 開啟包含 Go 應用程式原始碼的 GitHub 儲存庫，並準備原始碼套件。原始碼套件包含根目錄中的`application.go`原始碼檔案，該檔案託管 Go 應用程式的主要套件。如果您不使用 GitHub，請參閱此模式稍早*的先決條件*一節，了解建立應用程式原始碼套件的其他方式。 | 系統管理員、應用程式開發人員 | 
| 建立一個程式組態檔案。 | 在原始碼套件中建立`.ebextensions`資料夾，然後在此資料夾中建立 `options.config` 檔案。如需詳細資訊，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)。 | 系統管理員、應用程式開發人員 | 
|  建立原始碼套件 .zip 檔案。 | 執行下列命令。<pre>git archive -o ../godemoapp.zip HEAD</pre>這會建立原始碼套件 .zip 檔案。下載 .zip 檔案並將其儲存為本機檔案。.zip 檔案不能超過 512 MB，也不能包含父資料夾或頂層目錄。 | 系統管理員、應用程式開發人員 | 

### 將 Go Web 應用程式遷移至 Elastic Beanstalk
<a name="migrate-the-go-web-application-to-elastic-beanstalk"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇 Elastic Beanstalk 應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html)如需如何建立 Elastic Beanstalk 應用程式的指示，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html)。 | 系統管理員、應用程式開發人員 | 
| 啟動 Elastic Beanstalk Web 伺服器環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系統管理員、應用程式開發人員 | 
| 將原始碼套件 .zip 檔案上傳至 Elastic Beanstalk。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系統管理員、應用程式開發人員 | 
| 測試部署的 Go Web 應用程式。 | 系統會將您重新導向至 Elastic Beanstalk 應用程式的概觀頁面。在概觀頂端**的環境 ID** 旁，選擇結尾為 的 URL `elasticbeanstalk.com` 以導覽至您的應用程式。您的應用程式必須在其組態檔案中使用此名稱做為環境變數，並在網頁上顯示它。 | 系統管理員、應用程式開發人員 | 

## 疑難排解
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法透過 Application Load Balancer 存取應用程式。 | 檢查包含 Elastic Beanstalk 應用程式的目標群組。如果運作狀態不佳，請登入您的 Elastic Beanstalk 執行個體並檢查`nginx.conf`檔案組態，以確認其路由至正確的運作狀態 URL。您可能需要變更目標群組運作狀態檢查 URL。 | 

## 相關資源
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-resources"></a>
+ [Elastic Beanstalk 支援的 Go 平台版本](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)
+ [搭配 Elastic Beanstalk 使用組態檔案](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)
+ [在 Elastic Beanstalk 中建立範例應用程式](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html) 