

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

# 在多儲存庫設定中自動化 AWS Supply Chain 資料湖部署
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes"></a>

*Keshav Ganesh，Amazon Web Services*

## 摘要
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-summary"></a>

此模式提供自動化方法來使用多儲存庫持續整合和持續部署 (CI/CD) 管道來部署和管理 AWS Supply Chain 資料湖。它示範了兩種部署方法：使用 GitHub Actions 工作流程自動部署，或直接使用 Terraform 手動部署。這兩種方法都使用 Terraform for infrastructure as code (IaC)，搭配自動方法新增 GitHub Actions 和 JFrog Artifactory 來增強 CI/CD 功能。

解決方案利用 AWS Supply Chain AWS Lambda和 Amazon Simple Storage Service (Amazon S3) 來建立資料湖基礎設施，同時使用任一部署方法來自動化組態和資源建立。此自動化可消除手動組態步驟，並確保跨環境進行一致的部署。此外， AWS Supply Chain 不需要在擷取、轉換和載入 (ETL) 方面擁有深入的專業知識，並且可以提供採用 Amazon Quick Sight 技術的洞見和分析。

透過實作此模式，組織可以縮短部署時間、將基礎設施維護為程式碼，並透過版本控制的自動化程序來管理供應鏈資料湖。多儲存庫方法提供精細的存取控制，並支援獨立部署不同的元件。團隊可以選擇最適合其現有工具和程序的部署方法。

## 先決條件和限制
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-prereqs"></a>

**先決條件**

請確定本機電腦上已安裝下列項目：
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) 第 2 版
+ [GitHub CLI](https://docs.github.com/en/get-started/git-basics/set-up-git)
+ [Python](https://www.python.org/downloads/) 3.13 版
+ [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) 1.12 版或更新版本

在部署之前，請確定已備妥下列項目：
+ 作用中 AWS 帳戶。
+ [虛擬私有雲端 (VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html)， AWS 區域 在您的 中選擇的 AWS 帳戶 中有兩個[私有子網路](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html)。
+ 用於部署至下列服務的 AWS Identity and Access Management (IAM) 角色的足夠許可：
  + AWS Supply Chain – 偏好完整存取來部署其元件，例如資料集和整合流程，以及從 存取。 AWS 管理主控台
  + Amazon CloudWatch Logs – 用於建立和管理 CloudWatch 日誌群組。
  + Amazon Elastic Compute Cloud (Amazon EC2) – 適用於 Amazon EC2 安全群組和 Amazon Virtual Private Cloud (Amazon VPC) 端點。
  + Amazon EventBridge – 供 使用 AWS Supply Chain。
  + IAM – 用於建立 AWS Lambda 服務角色。
  + AWS Key Management Service (AWS KMS) – 用於存取 AWS KMS keys 用於 Amazon S3 成品儲存貯體和 Amazon S3 AWS Supply Chain 預備儲存貯體的 。
  + AWS Lambda – 用於建立部署 AWS Supply Chain 元件的 Lambda 函數。
  + Amazon S3 – 用於存取 Amazon S3 成品儲存貯體、伺服器存取記錄儲存貯體和 AWS Supply Chain 預備儲存貯體。如果您使用手動部署，也需要 Amazon S3 Terraform 成品儲存貯體的許可。
  + Amazon VPC – 用於建立和管理 VPC。

如果您偏好使用 GitHub 動作工作流程進行部署，請執行下列動作：
+ 為具有先前提及許可的 IAM 角色設定 [OpenID Connect (OIDC)](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws#configuring-the-role-and-trust-policy)。
+ 建立具有類似許可的 IAM 角色來存取 AWS 管理主控台。如需詳細資訊，請參閱 [IAM 文件中的建立角色以授予許可給 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html)。

如果您偏好手動部署，請執行下列動作：
+ 建立 IAM 使用者以擔任具有先前提及許可的 IAM 角色。如需詳細資訊，請參閱 [IAM 文件中的建立角色以授予許可給 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html)。
+ 在您的本機終端機中[擔任 角色](https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-role.html)。

如果您偏好使用 GitHub 動作工作流程進行部署，請設定下列項目：
+ 取得主機名稱、登入使用者名稱和登入存取權杖的 [JFrog Artifactory 帳戶](https://jfrog.com/artifactory/?utm_source=google&utm_medium=cpc_search&utm_campaign=SearchDSKBrandAPACIN202506&utm_term=jfrog%20cloud&gads_network=g&utm_content=u-bin&gads_campaign_id=22674833884&gads_adgroup_id=184501797241&gads_extension_id=233003714635&gads_target_id=aud-312135645780:kwd-1598615735032&gads_matchtype=b&gad_source=1&gad_campaignid=22674833884&gbraid=0AAAAADqV85U5B37iapTR9IIFHBvydF5AQ&gclid=CjwKCAjwiY_GBhBEEiwAFaghvqdNV-odNLZXPHjT7NAwf8lA-QuMtg666hgvDW1oCJ4nn7wvf869_xoCW4IQAvD_BwE)。
+ 用於存放成品的 [JFrog 專案金鑰和儲存庫](https://docs.jfrog.com/projects/docs/create-a-project)。

**限制**
+  AWS Supply Chain 執行個體不支援複雜的資料轉換技術。
+ AWS Supply Chain 最適合供應鏈網域，因為它提供內建的分析和洞見。對於任何其他網域， AWS Supply Chain 可以用作資料湖架構中的資料存放區。
+ 此解決方案中使用的 Lambda 函數可能需要增強，才能在生產規模部署中處理 API 重試和記憶體管理。
+ 有些 AWS 服務 無法全部使用 AWS 區域。如需區域可用性，請參閱[AWS 依區域的服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

## Architecture
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-architecture"></a>

您可以使用自動化 GitHub 動作工作流程或使用 Terraform 手動部署此解決方案。

**使用 GitHub 動作自動部署**

下圖顯示使用 GitHub 動作工作流程的自動化部署選項。JFrog Artifactory 用於成品管理。它存放資源資訊和輸出，以用於多儲存庫部署。

![\[使用 GitHub Actions 工作流程和 JFrog 的自動化部署選項。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2f0b78b0-a174-4703-b533-d66b3fb005e0/images/d454a5c5-ed51-421c-a87f-ff74cfcb30be.png)


**使用 Terraform 手動部署**

下圖顯示透過 Terraform 的手動部署選項。Amazon S3 用於成品管理，而不是 JFrog Artifactory。

![\[使用 Terraform 和 Amazon S3 的手動部署選項。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2f0b78b0-a174-4703-b533-d66b3fb005e0/images/1130e728-44d5-4ae7-9586-1e497f54352a.png)


**部署工作流程**

圖表顯示下列工作流程：

1. 使用下列其中一種部署方法部署 AWS Supply Chain 服務資料集基礎設施和資料庫：
   + **自動化部署** – 使用 GitHub Actions 工作流程協調所有部署步驟，並使用 JFrog Artifactory 進行成品管理。
   + **手動部署** – 直接針對每個部署步驟執行 Terraform 命令，並使用 Amazon S3 進行成品管理。

1. 建立 AWS Supply Chain 服務操作所需的支援 AWS 資源：
   + Amazon VPC 端點和安全群組
   + AWS KMS keys
   + CloudWatch Logs 日誌群組

1. 建立和部署下列基礎設施資源：
   + 管理 （建立、更新和刪除） AWS Supply Chain 服務執行個體、命名空間和資料集的 Lambda 函數。
   + AWS Supply Chain 暫存 Amazon S3 儲存貯體以進行資料擷取

1. 部署 Lambda 函數，管理預備儲存貯體和 AWS Supply Chain 資料集之間的整合流程。部署完成後，剩餘的工作流程步驟會管理資料擷取和分析。

1. 設定 AWS Supply Chain 暫存 Amazon S3 儲存貯體的來源資料擷取。

1. 將資料新增至 AWS Supply Chain 預備 Amazon S3 儲存貯體後，服務會自動觸發至 AWS Supply Chain 資料集的整合流程。

1. AWS Supply Chain 與 Quick Sight Analytics 整合，以根據擷取的資料產生儀表板。

## 工具
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式的日誌， AWS 服務 以便您可以監控日誌並將其安全地存檔。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您 AWS 服務 透過命令列 shell 中的命令與 互動。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可協助您將應用程式與來自各種來源的即時資料連線。例如， AWS Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他事件匯流排 AWS 帳戶。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html) 可協助您集中管理所有 AWS 帳戶 和雲端應用程式的單一登入 (SSO) 存取。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [Amazon Q](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/qinasc.html) in AWS Supply Chain 是互動式生成式 AI 助理，可透過分析 AWS Supply Chain 資料湖中的資料，協助您更有效率地操作供應鏈。
+ [Amazon Quick Sight](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) 是一種雲端規模的商業智慧 (BI) 服務，可協助您在單一儀表板中視覺化、分析和報告您的資料。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Supply Chain](https://docs.aws.amazon.com/aws-supply-chain/latest/adminguide/getting-started.html) 是以雲端為基礎的受管應用程式，可作為供應鏈網域組織中的資料存放區，可用於產生洞見並對擷取的資料進行分析。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。[Amazon VPC 端點](https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html)是一種虛擬裝置，可協助您將 VPC 私下連線至支援的 ， AWS 服務 而不需要網際網路閘道、NAT 裝置、VPN 連線或 AWS Direct Connect 連線。

**其他工具**
+ [GitHub Actions](https://docs.github.com/en/actions) 是與 GitHub 儲存庫緊密整合的持續整合和持續交付 (CI/CD) 平台。您可以使用 GitHub 動作來自動化建置、測試和部署管道。
+ [HashiCorp Terraform](https://www.terraform.io/) 是一種基礎設施即程式碼 (IaC) 工具，可協助您建立和管理雲端和內部部署資源。
+ [JFrog Artifactory](https://jfrog.com/help/r/jfrog-artifactory-documentation/jfrog-artifactory) 透過應用程式交付程序，提供二進位檔和成品的end-to-end自動化和管理。
+ [Python](https://www.python.org/) 是一種一般用途的電腦程式設計語言。此模式使用 Python 讓 AWS 函數的程式碼與 互動 AWS Supply Chain

  .

## 最佳實務
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-best-practices"></a>
+ 實作此模式時，請盡可能維持最高的安全性。如[先決條件](#automate-the-deployment-of-aws-supply-chain-data-lakes-prereqs)中所述，請確定具有兩個[私有子網路的](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html)[虛擬私有雲端 (VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html) 位於 AWS 區域 您選擇的 AWS 帳戶 中的 中。
+ 盡可能使用 AWS KMS [客戶受管金鑰](https://docs.aws.amazon.com/kms/latest/cryptographic-details/basic-concepts.html)，並授予他們有限的存取許可。
+ 若要設定具有擷取此模式資料所需最低存取權的 IAM 角色，請參閱此模式儲存庫中的[從來源系統安全資料擷取至 Amazon S3](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main?tab=readme-ov-file#secure-data-ingestion-from-source-systems-to-amazon-s3)。

## 史詩
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-epics"></a>

### （兩個選項） 設定本機工作站
<a name="both-options-set-up-local-workstation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製儲存庫。 | 若要複製此模式的儲存庫，請在本機工作站中執行下列命令：<pre>git clone https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment.git<br />cd ASC-Deployment</pre> | AWS DevOps | 
| （自動化選項） 驗證部署的先決條件。 | 請確定自動化部署的[先決條件](#automate-the-deployment-of-aws-supply-chain-data-lakes-prereqs)已完成。 | 應用程式擁有者 | 
| （手動選項） 準備部署 AWS Supply Chain 資料集。 | 若要前往 的`terraform-deployment`目錄`ASC-Datasets`，請執行下列命令：<pre>cd ASC-Datasets/terraform-deployment</pre>若要擔任[在先決條件](#automate-the-deployment-of-aws-supply-chain-data-lakes-prereqs)中建立的角色 ARN，請執行下列命令：<pre>aws sts assume-role --role-arn <enter AWS user role ARN> --role-session-name <your-session-name></pre>若要設定和匯出環境變數，請執行下列命令：<pre># Export Environment variables<br />export REGION=<Enter deployment region><br />export REPO_NAME=<Enter Current ASC Datasets dir name><br />export PROJECT_NAME="asc-deployment-poc"<br />export ACCOUNT_ID=<Enter deployment Account ID><br />export ENVIRONMENT="dev"<br />export LAMBDA_LAYER_TEMP_DIR_TERRAFORM="layerOutput"<br />export LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM="lambdaOutput"<br />export AWS_USER_ROLE=<Enter user role ARN for AWS Console access and deployment><br />export S3_TERRAFORM_ARTIFACTS_BUCKET_NAME="$PROJECT_NAME-$ACCOUNT_ID-$REGION-terraform-artifacts-$ENVIRONMENT"</pre> | AWS DevOps | 
| （手動選項） 準備管理部署中的 AWS Supply Chain 整合流程。 | 若要前往 的`terraform-deployment`目錄`ASC-Integration-Flows`，請執行下列命令：<pre>cd ASC-Integration-Flows/terraform-deployment</pre>若要擔任先前建立的角色 ARN，請執行下列命令：<pre>aws sts assume-role --role-arn <enter AWS user role ARN> --role-session-name <your-session-name></pre>若要設定和匯出環境變數，請執行下列命令：<pre># Export Environment variables<br />export REGION=<Enter deployment region><br />export REPO_NAME=<Enter Current ASC Integration Flows dir name><br />export ASC_DATASET_VARS_REPO=<Enter Current ASC Datasets dir name>  #Must be the same directory name used for ASC Datasets deployment<br />export PROJECT_NAME="asc-deployment-poc"<br />export ACCOUNT_ID=<Enter deployment Account ID><br />export ENVIRONMENT="dev"<br />export LAMBDA_LAYER_TEMP_DIR_TERRAFORM="layerOutput"<br />export LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM="lambdaOutput"<br />export S3_TERRAFORM_ARTIFACTS_BUCKET_NAME="$PROJECT_NAME-$ACCOUNT_ID-$REGION-terraform-artifacts-$ENVIRONMENT"</pre> | 應用程式擁有者 | 

### （自動化選項） 使用 GitHub 動作工作流程部署 AWS Supply Chain 資料集
<a name="automated-option-deploy-supplychain-datasets-using-github-actions-workflows"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 `ASC-Datasets`目錄。 | 若要將`ASC-Datasets`目錄複製到新位置，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-deployment-of-aws-supply-chain-data-lakes.html) | AWS DevOps | 
| 設定 `ASC-Datasets`目錄。 | 若要在您的組織中`ASC-Datasets`將 設定為獨立儲存庫，請執行下列命令：<pre>git init<br />git add .<br />git commit -m "Initial commit: ASC-Datasets standalone repository"<br />git remote add origin <INSERT_ASC_DATASETS_GITHUB_URL><br />git branch -M dev</pre> | AWS DevOps | 
| 在 .github 工作流程檔案中設定分支名稱。 | 在[部署](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Datasets/.github/workflows/asc-datasets.yml)工作流程檔案中設定分支名稱，如下列範例所示：<pre>   on:<br />     workflow_dispatch:<br />     push:<br />       branches:<br />         - dev     #Change to any other branch preferred for deployment</pre> | 應用程式擁有者 | 
| 設定 GitHub 環境並設定環境值。 | 若要在 GitHub 組織中設定 GitHub 環境，請使用此模式儲存庫中[設定 GitHub 環境](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Datasets#setup-github-environments)的指示。若要在工作流程檔案中設定[環境值](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Datasets#setup-environment-values-in-the-workflow-files)，請使用此模式儲存庫[中工作流程檔案中設定環境值](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Datasets#setup-environment-values-in-the-workflow-files)中的指示。 | 應用程式擁有者 | 
| 觸發工作流程。 | 若要將您的變更推送到您的 GitHub 組織並觸發部署工作流程，請執行下列命令：<pre>git push -u origin dev</pre> | AWS DevOps | 

### （自動化選項） 使用 GitHub 動作工作流程部署 AWS Supply Chain 整合流程
<a name="automated-option-deploy-supplychain-integration-flows-using-github-actions-workflows"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 `ASC-Integration-Flows`目錄。 | 若要將`ASC-Integration-Flows`目錄複製到新位置，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-deployment-of-aws-supply-chain-data-lakes.html) | AWS DevOps | 
| 設定 `ASC-Integration-Flows`目錄。 | 若要將`ASC-Integration-Flows`目錄設定為組織中的獨立儲存庫，請執行下列命令：<pre>git init<br />git add .<br />git commit -m "Initial commit: ASC-Integration-Flows standalone repository"<br />git remote add origin <INSERT_ASC_Integration_Flows_GITHUB_URL><br />git branch -M dev</pre> | AWS DevOps | 
| 在 .github 工作流程檔案中設定分支名稱。 | 在[部署](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Integration-Flows/.github/workflows/asc-integration-flows.yml)工作流程檔案中設定分支名稱，如下列範例所示：<pre>   on:<br />     workflow_dispatch:<br />     push:<br />       branches:<br />         - dev     #Change to any other branch preferred for deployment</pre> | 應用程式擁有者 | 
| 設定 GitHub 環境並設定環境值。 | 若要在 GitHub 組織中設定 GitHub 環境，請使用此模式儲存庫中[設定 GitHub 環境](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Integration-Flows#setup-github-environments)的指示。若要在工作流程檔案中設定[環境值](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Integration-Flows#setup-github-environments)，請使用此模式儲存庫[中工作流程檔案中設定環境值](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/tree/main/ASC-Integration-Flows#setup-environment-values-in-the-workflow-files)中的指示。 | 應用程式擁有者 | 
| 觸發工作流程。 | 若要將您的變更推送到您的 GitHub 組織並觸發部署工作流程，請執行下列命令：<pre>git push -u origin dev</pre> | AWS DevOps | 

### （手動選項） 使用 Terraform 部署 AWS Supply Chain 資料集
<a name="manual-option-deploy-supplychain-datasets-using-terraform"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 導覽至 `terraform-deployment ` 目錄。 | 若要前往 的`terraform-deployment`目錄`ASC-Datasets`，請執行下列命令：<pre>cd ASC-Datasets/terraform-deployment</pre> | AWS DevOps | 
| 設定 Terraform 狀態 Amazon S3 儲存貯體。 | 若要設定 Terraform 狀態 Amazon S3 儲存貯體，請使用下列指令碼：<pre># Setup terraform bucket<br />chmod +x ../scripts/setup-terraform.sh<br />../scripts/setup-terraform.sh</pre> | AWS DevOps | 
| 設定 Terraform 成品 Amazon S3 儲存貯體。 | 若要設定 Terraform 成品 Amazon S3 儲存貯體，請使用下列指令碼：<pre># Setup terraform artifacts bucket<br />chmod +x ../scripts/setup-terraform-artifacts-bucket.sh<br />../scripts/setup-terraform-artifacts-bucket.sh</pre> | AWS DevOps | 
| 設定 Terraform 後端和提供者組態。 | 若要設定 Terraform 後端和提供者組態，請使用下列指令碼：<pre># Setup terraform backend and providers config if they don't exist<br />chmod +x ../scripts/generate-terraform-config.sh<br />../scripts/generate-terraform-config.sh</pre> | AWS DevOps | 
| 產生部署計畫。 | 若要產生部署計畫，請執行下列命令：<pre># Run terraform init and validate<br />terraform init<br />terraform validate<br /><br /># Run terraform plan<br />terraform plan \<br />-var-file="tfInputs/$ENVIRONMENT.tfvars" \<br />-var="project_name=$PROJECT_NAME" \<br />-var="environment=$ENVIRONMENT" \<br />-var="user_role=$AWS_USER_ROLE" \<br />-var="lambda_temp_dir=$LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM" \<br />-var="layer_temp_dir=$LAMBDA_LAYER_TEMP_DIR_TERRAFORM" \<br />-parallelism=40 \<br />-out='tfplan.out'</pre> | AWS DevOps | 
| 部署組態。 | 若要部署組態，請執行下列命令：<pre># Run terraform apply<br />terraform apply tfplan.out</pre> | AWS DevOps | 
| 更新其他組態並存放輸出。 | 若要更新 AWS KMS 金鑰政策，並將套用的組態輸出存放在 Terraform 成品 Amazon S3 儲存貯體中，請執行下列命令：<pre># Update AWS Supply Chain KMS Key policy with the service's requirements<br />chmod +x ../scripts/update-asc-kms-policy.sh<br />../scripts/update-asc-kms-policy.sh<br /></pre><pre># Update AWS KMS Keys' policy with IAM roles<br />chmod +x ../scripts/update-kms-policy.sh<br />../scripts/update-kms-policy.sh<br /></pre><pre># Create terraform outputs file to be used as input variables<br />terraform output -json > raw_output.json<br />jq -r 'to_entries | map(<br />  if .value.type == "string" then<br />      "\(.key) = \"\(.value.value)\""<br />  else<br />      "\(.key) = \(.value.value | tojson)"<br />  end<br />) | .[]' raw_output.json > $REPO_NAME-outputs.tfvars<br /></pre><pre># Upload reformed outputs file to Amazon S3 terraform artifacts bucket (For retrieval from other repositories)<br />aws s3 cp $REPO_NAME-outputs.tfvars s3://$S3_TERRAFORM_ARTIFACTS_BUCKET_NAME/$REPO_NAME-outputs.tfvars<br />rm -f raw_output.json<br />rm -f $REPO_NAME-outputs.tfvars<br /></pre> | AWS DevOps | 

### （手動選項） 使用 Terraform 部署 AWS Supply Chain 服務整合流程
<a name="manual-option-deploy-supplychain-service-integration-flows-using-terraform"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 導覽至 `terraform-deployment` 目錄。 | 若要前往 的`terraform-deployment`目錄`ASC-Integration-Flows`，請執行下列命令：<pre>cd ASC-Integration-Flows/terraform-deployment</pre> | AWS DevOps | 
| 設定 Terraform 後端和提供者組態。 | 若要設定 Terraform 後端和提供者組態，請使用下列指令碼：<pre># Setup terraform backend and providers config if they don't exist<br />chmod +x ../scripts/generate-terraform-config.sh<br />../scripts/generate-terraform-config.sh</pre> | AWS DevOps | 
| 產生部署計畫。 | 若要產生部署計畫，請執行下列命令。這些命令會初始化您的 Terraform 環境，將來自 的組態變數`ASC-Datasets`與現有的 Terraform 組態合併，並產生部署計畫。<pre># Run terraform init and validate<br />terraform init<br />terraform validate<br /></pre><pre># Download and merge ASC DATASET tfvars<br />chmod +x ../scripts/download-vars-through-s3.sh<br />../scripts/download-vars-through-s3.sh $ASC_DATASET_VARS_REPO<br /></pre><pre># Run terraform plan<br />terraform plan \<br />-var-file="tfInputs/$ENVIRONMENT.tfvars" \<br />-var="project_name=$PROJECT_NAME" \<br />-var="environment=$ENVIRONMENT" \<br />-var="lambda_temp_dir=$LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM" \<br />-var="layer_temp_dir=$LAMBDA_LAYER_TEMP_DIR_TERRAFORM" \<br />-parallelism=40 \<br />-out='tfplan.out'</pre> | AWS DevOps | 
| 部署組態。 | 若要部署組態，請執行下列命令：<pre># Run terraform apply<br />terraform apply tfplan.out</pre> | AWS DevOps | 
| 更新其他組態。 | 若要更新 AWS KMS 金鑰政策，並將套用的組態輸出存放在 Terraform 成品 Amazon S3 儲存貯體中，請執行下列命令：<pre># Update AWS KMS Keys' policy with IAM roles<br />chmod +x ../scripts/update-kms-policy-through-s3.sh<br />../scripts/update-kms-policy-through-s3.sh $ASC_DATASET_VARS_REPO<br /></pre><pre># Create terraform outputs file to be used as input variables<br />terraform output -json > raw_output.json<br />jq -r 'to_entries | map(<br />  if .value.type == "string" then<br />      "\(.key) = \"\(.value.value)\""<br />  else<br />      "\(.key) = \(.value.value | tojson)"<br />  end<br />) | .[]' raw_output.json > $REPO_NAME-outputs.tfvars<br /></pre><pre># Upload reformed outputs file to Amazon S3 terraform artifacts bucket (For retrieval from other repositories)<br />aws s3 cp $REPO_NAME-outputs.tfvars s3://$S3_TERRAFORM_ARTIFACTS_BUCKET_NAME/$REPO_NAME-outputs.tfvars<br />rm -f raw_output.json<br />rm -f $REPO_NAME-outputs.tfvars<br /></pre> | AWS DevOps | 

### （兩個選項） 擷取資料
<a name="both-options-ingest-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 上傳範例 CSV 檔案。 | 若要上傳資料集的範例 CSV 檔案，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-deployment-of-aws-supply-chain-data-lakes.html) | 資料工程師 | 

### （兩個選項） 設定 AWS Supply Chain 存取權
<a name="both-options-set-up-supplychain-access"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS Supply Chain 存取權。 | 若要從 設定 AWS Supply Chain 存取權 AWS 管理主控台，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-deployment-of-aws-supply-chain-data-lakes.html) | 應用程式擁有者 | 

### （自動化選項） 使用 GitHub 動作工作流程清除所有資源
<a name="automated-option-clean-up-all-resources-using-github-actions-workflows"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 觸發整合流程資源的銷毀工作流程。 | `ASC-Integration-Flows` 從 GitHub 組織中的部署分支觸發 的[銷毀工作流程](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Integration-Flows/.github/workflows/destroy-workflow.yml)。 | AWS DevOps | 
| 觸發資料集資源的銷毀工作流程。 | `ASC-Datasets` 從 GitHub 組織中的部署分支觸發 的[銷毀工作流程](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Datasets/.github/workflows/destroy-workflow.yml)。 | AWS DevOps | 

### （手動選項） 使用 Terraform 清除 AWS Supply Chain 整合流程的資源
<a name="manual-option-clean-up-resources-of-supplychain-integration-flows-using-terraform"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 導覽至 `terraform-deployment` 目錄。 | 若要前往 的`terraform-deployment`目錄`ASC-Integration-Flows`，請執行下列命令：<pre>cd ASC-Integration-Flows/terraform-deployment</pre> | AWS DevOps | 
| 設定 Terraform 後端和提供者組態。 | 若要設定 Terraform 後端和提供者組態，請使用下列指令碼：<pre># Setup terraform backend and providers config if they don't exist<br />chmod +x ../scripts/generate-terraform-config.sh<br />../scripts/generate-terraform-config.sh</pre> | AWS DevOps | 
| 產生基礎設施銷毀計畫。 | 若要透過產生詳細的捨棄計畫來準備 AWS 基礎設施的受控銷毀，請執行下列命令。程序會初始化 Terraform、整合 AWS Supply Chain 資料集組態，並建立銷毀計畫，供您在執行之前檢閱。<pre># Run terraform init and validate<br />terraform init<br />terraform validate<br /></pre><pre># Download and merge ASC DATASET tfvars<br />chmod +x ../scripts/download-vars-through-s3.sh<br />../scripts/download-vars-through-s3.sh $ASC_DATASET_VARS_REPO<br /></pre><pre># Run terraform plan<br />terraform plan -destroy\<br />-var-file="tfInputs/$ENVIRONMENT.tfvars" \<br />-var="project_name=$PROJECT_NAME" \<br />-var="environment=$ENVIRONMENT" \<br />-var="lambda_temp_dir=$LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM" \<br />-var="layer_temp_dir=$LAMBDA_LAYER_TEMP_DIR_TERRAFORM" \<br />-parallelism=40 \<br />-out='tfplan.out'</pre> | AWS DevOps | 
| 執行基礎設施銷毀計畫。 | 若要執行基礎設施的計劃銷毀，請執行下列命令：<pre># Run terraform apply<br />terraform apply tfplan.out</pre> | AWS DevOps | 
| 從 Amazon S3 儲存貯體移除 Terraform 輸出。 | 若要移除部署 期間上傳的輸出檔案`ASC-Integration-Flows`，請執行下列命令：<pre># Delete the outputs file<br />aws s3 rm s3://$S3_TERRAFORM_ARTIFACTS_BUCKET_NAME/$REPO_NAME-outputs.tfvars</pre> | AWS DevOps | 

### （手動選項） 使用 Terraform 清除 AWS Supply Chain 服務資料集的資源
<a name="manual-option-clean-up-resources-of-supplychain-service-datasets-using-terraform"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 導覽至 `terraform-deployment` 目錄。 | 若要前往 的`terraform-deployment`目錄`ASC-Datasets`，請執行下列命令：<pre>cd ASC-Datasets/terraform-deployment</pre> | AWS DevOps | 
| 設定 Terraform 後端和提供者組態。 | 若要設定 Terraform 後端和提供者組態，請使用下列指令碼：<pre># Setup terraform backend and providers config if they don't exist<br />chmod +x ../scripts/generate-terraform-config.sh<br />../scripts/generate-terraform-config.sh</pre> | AWS DevOps | 
| 產生基礎設施銷毀計畫。 | 若要建立銷毀 AWS Supply Chain 資料集資源的計劃，請執行下列命令：<pre># Run terraform init and validate<br />terraform init<br />terraform validate<br /><br /># Run terraform plan<br />terraform plan -destroy\<br />-var-file="tfInputs/$ENVIRONMENT.tfvars" \<br />-var="project_name=$PROJECT_NAME" \<br />-var="environment=$ENVIRONMENT" \<br />-var="user_role=$AWS_USER_ROLE" \<br />-var="lambda_temp_dir=$LAMBDA_FUNCTION_TEMP_DIR_TERRAFORM" \<br />-var="layer_temp_dir=$LAMBDA_LAYER_TEMP_DIR_TERRAFORM" \<br />-parallelism=40 \<br />-out='tfplan.out'</pre> | AWS DevOps | 
| 清空 Amazon S3 儲存貯體。 | 若要清空所有 Amazon S3 儲存貯體 （為 設定的伺服器存取記錄儲存貯體除外`force-destroy`)，請使用下列指令碼：<pre># Delete S3 buckets excluding server access logging bucket<br />chmod +x ../scripts/empty-s3-buckets.sh<br />../scripts/empty-s3-buckets.sh tfplan.out</pre> | AWS DevOps | 
| 執行基礎設施銷毀計畫。 | 若要使用產生的計劃執行 AWS Supply Chain 資料集基礎設施的計劃銷毀，請執行下列命令：<pre># Run terraform apply<br />terraform apply tfplan.out</pre> | AWS DevOps | 
| 從 Amazon S3 Terraform 成品儲存貯體移除 Terraform 輸出。 | 若要完成清除程序，`ASC-Datasets`請執行下列命令，移除部署 期間上傳的輸出檔案：<pre># Delete the outputs file<br />aws s3 rm s3://$S3_TERRAFORM_ARTIFACTS_BUCKET_NAME/$REPO_NAME-outputs.tfvars</pre> | AWS DevOps | 

## 疑難排解
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 由於 AWS Supply Chain 內部錯誤或服務角色的 IAM 許可不足， AWS Supply Chain 資料集或整合流程無法正確部署。 | 首先，清除所有資源。然後，重新部署 AWS Supply Chain [資料集資源](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Datasets/README.md)，然後重新部署 AWS Supply Chain [整合流程資源](https://github.com/aws-samples/sample-automate-aws-supply-chain-deployment/blob/main/ASC-Integration-Flows/README.md)。 | 
|  AWS Supply Chain 整合流程不會擷取為 AWS Supply Chain 資料集上傳的新資料檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-deployment-of-aws-supply-chain-data-lakes.html) | 

## 相關資源
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-resources"></a>

**AWS 文件**
+ [AWS Supply Chain](https://docs.aws.amazon.com/aws-supply-chain/latest/adminguide/getting-started.html)

**其他資源**
+ [了解 GitHub 動作工作流程](https://docs.github.com/en/actions/get-started/understand-github-actions) (GitHub 文件）

## 其他資訊
<a name="automate-the-deployment-of-aws-supply-chain-data-lakes-additional"></a>

此解決方案可以透過 隨附的預先建置儀表板 AWS Supply Chain 或與 Amazon Quick Sight 的自訂整合，複寫更多資料集，並查詢以供進一步分析。此外，您可以使用 Amazon Q 來詢問與 AWS Supply Chain 執行個體相關的問題。

**使用 AWS Supply Chain Analytics 分析資料**

如需設定 AWS Supply Chain Analytics 的說明，請參閱 AWS Supply Chain 文件中的[設定 AWS Supply Chain Analytics](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/setting_analytics.html)。

此模式示範了建立**行事曆**和 **Outbound\$1Order\$1Line** 資料集。若要建立使用這些資料集的分析，請使用下列步驟：

1. 若要分析資料集，請使用**季節性分析**儀表板。若要新增儀表板，請遵循 AWS Supply Chain 文件中[預先建置儀表板](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/prebuilt_dashboards.html)中的步驟。

1. 選擇儀表板以查看以行事曆資料和外撥訂單行資料的範例 CSV 檔案為基礎的分析。

儀表板會根據資料集的擷取資料，提供多年來的需求洞察。您可以進一步指定 ProductID、CustomerID、年份和其他參數進行分析。

**使用 Amazon Q 詢問與 AWS Supply Chain 執行個體相關的問題**

[Amazon Q in AWS Supply Chain](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/qinasc.html) 是互動式生成式 AI 助理，可協助您更有效率地操作供應鏈。Amazon Q 可以執行下列動作：
+ 分析資料湖中的 AWS Supply Chain 資料。
+ 提供營運和財務洞察。
+ 回答您的立即供應鏈問題。

如需使用 Amazon Q 的詳細資訊，請參閱 AWS Supply Chain 文件中的在 [中啟用 AWS Supply Chain](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/enabling_QinASC.html) Amazon Q 和在 [中使用 Amazon Q AWS Supply Chain](https://docs.aws.amazon.com/aws-supply-chain/latest/userguide/using_QinASC.html)。