

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

# 使用 Amazon Redshift 設定 Oracle Database@AWS integrations
<a name="setting-up-zero-etl"></a>

若要設定 Oracle 資料庫與 Amazon Redshift 之間的零 ETL 整合，請完成下列步驟：

1. 在 ODB 網路上啟用零 ETL。

1. 設定 Oracle 資料庫先決條件。

1. 設定 AWS Secrets Manager 和 AWS Key Management Service。

1. 設定 IAM 許可。

1. 設定 Amazon Redshift 資源政策。

1. 建立零 ETL 整合。

1. 在 Amazon Redshift 中建立目標資料庫。

## 步驟 1：為您的 ODB 網路啟用零 ETL
<a name="zero-etl-enable-network"></a>

您可以為與來源 VM 叢集相關聯的 ODB 網路啟用零 ETL 整合。預設會停用此整合。

### 主控台
<a name="ZETLAccess.CON"></a>

**啟用零 ETL 整合**

1. 在 https：//[https://console.aws.amazon.com/odb/](https://console.aws.amazon.com/odb/) 開啟 Oracle Database@AWS console。

1. 在導覽窗格中，選擇 **ODB 網路**。

1. 選取您要啟用零 ETL 整合的 ODB 網路。

1. 選擇 **Modify** (修改)。

1. 選取**零 ETL**。

1. 選擇**繼續**，然後選擇**修改**。

### AWS CLI
<a name="ZETLAccess.CLI"></a>

若要啟用零 ETL 整合，請使用 `update-odb-network`命令搭配 `--zero-etl-access` 參數：

```
aws odb update-odb-network \
  --odb-network-id {{odb-network-id}} \
  --zero-etl-access ENABLED
```

若要為與來源 VM 叢集相關聯的 ODB 網路啟用零 ETL 整合，請使用 `update-odb-network`命令。此命令會設定零 ETL 整合所需的網路基礎設施。

```
aws odb update-odb-network \
  --odb-network-id {{your-odb-network-id}} \
  --zero-etl-access ENABLED
```

## 步驟 2：設定 Oracle 資料庫
<a name="zero-etl-configure-oracle"></a>

完成 Oracle 資料庫組態，如[先決條件](zero-etl-prerequisites.md)中所述：
+ 建立複寫使用者並授予必要的許可。
+ 啟用封存的重做日誌。
+ 設定 SSL （僅限 Oracle Exadata)。
+ 如果適用，請設定 ASM 使用者 （僅限 Oracle Exadata)。

## 步驟 3：設定 AWS Secrets Manager 和 AWS Key Management Service
<a name="zero-etl-setup-secrets"></a>

建立客戶受管金鑰 (CMK) 並存放您的資料庫登入資料。

1. 使用 `create-key`命令在 AWS Key Management Service 中建立 CMK。

   ```
   aws kms create-key \
     --description "ODB Zero-ETL Integration Key" \
     --key-usage ENCRYPT_DECRYPT \
     --key-spec SYMMETRIC_DEFAULT
   ```

1. 將您的資料庫登入資料儲存在 AWS Secrets Manager 中。

   ```
   aws secretsmanager create-secret \
     --name "ODBZeroETLCredentials" \
     --description "Credentials for Oracle Database@AWS Zero-ETL integration" \
     --kms-key-id {{your-cmk-key-arn}} \
     --secret-string file://secret-content.json
   ```

1. 將資源政策連接至秘密，以允許 Oracle Database@AWS access。

   ```
   aws secretsmanager put-resource-policy \
     --secret-id "ODBZeroETLCredentials" \
     --resource-policy file://secret-resource-policy.json
   ```

   在上述命令中， `secret-resource-policy.json`包含下列 JSON。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "zetl.odb.amazonaws.com"
         },
         "Action": [
           "secretsmanager:GetSecretValue",
           "secretsmanager:DescribeSecret"
         ],
         "Resource": "*"
       }
     ]
   }
   ```

------

1. 將資源政策連接至 CMK。CMK 資源政策必須包含 Oracle Database@AWS service 主體和 Amazon Redshift 服務主體的許可，以支援加密的零 ETL 整合。

   ```
   aws kms put-key-policy \
     --key-id {{your-cmk-key-arn}} \
     --policy-name default \
     --policy file://cmk-resource-policy.json
   ```

   `cmk-resource-policy.json` 檔案應包含下列政策陳述式。第一個陳述式允許 Oracle Database@AWS service 存取，第二個陳述式允許 Amazon Redshift 在 KMS 金鑰上為加密的資料操作建立授予。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "Allow ODB service access",
         "Effect": "Allow",
         "Principal": {
           "Service": "zetl.odb.amazonaws.com"
         },
         "Action": [
           "kms:Decrypt",
           "kms:GenerateDataKey",
           "kms:CreateGrant"
         ],
         "Resource": "*"
       },
       {
         "Sid": "Allows the Redshift service principal to add a grant to a KMS key",
         "Effect": "Allow",
         "Principal": {
           "Service": "redshift.amazonaws.com"
         },
         "Action": "kms:CreateGrant",
         "Resource": "*",
         "Condition": {
           "StringEquals": {
             "kms:EncryptionContext:{context-key}": "{context-value}"
           },
           "ForAllValues:StringEquals": {
             "kms:GrantOperations": [
               "Decrypt",
               "GenerateDataKey",
               "CreateGrant"
             ]
           }
         }
       }
     ]
   }
   ```

------

## 步驟 4：設定 IAM 許可
<a name="zero-etl-setup-iam"></a>

建立並連接允許零 ETL 整合操作的 IAM 政策。

```
aws iam create-policy \
  --policy-name "ODBZeroETLIntegrationPolicy" \
  --policy-document file://odb-zetl-iam-policy.json

aws iam attach-user-policy \
  --user-name {{your-iam-username}} \
  --policy-arn {{policy-arn}}
```

下列政策會授予必要的許可。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ODBGlueIntegrationAccess",
      "Effect": "Allow",
      "Action": [
        "glue:CreateIntegration",
        "glue:ModifyIntegration",
        "glue:DeleteIntegration",
        "glue:DescribeIntegrations",
        "glue:DescribeInboundIntegrations"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ODBZetlOperations",
      "Effect": "Allow",
      "Action": "odb:CreateOutboundIntegration",
      "Resource": "*"
    },
    {
      "Sid": "ODBRedshiftFullAccess",
      "Effect": "Allow",
      "Action": [
        "redshift:*",
        "redshift-serverless:*",
        "ec2:DescribeAccountAttributes",
        "ec2:DescribeAddresses",
        "ec2:DescribeAvailabilityZones",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSubnets",
        "ec2:DescribeVpcs",
        "ec2:DescribeInternetGateways",
        "sns:CreateTopic",
        "sns:Get*",
        "sns:List*",
        "cloudwatch:Describe*",
         "cloudwatch:Get*",
        "cloudwatch:List*",
        "cloudwatch:PutMetricAlarm",
        "cloudwatch:EnableAlarmActions",
        "cloudwatch:DisableAlarmActions",
        "tag:GetResources",
        "tag:UntagResources",
        "tag:GetTagValues",
        "tag:GetTagKeys",
        "tag:TagResources"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ODBRedshiftDataAPI",
      "Effect": "Allow",
      "Action": [
        "redshift-data:ExecuteStatement",
        "redshift-data:CancelStatement",
        "redshift-data:ListStatements",
        "redshift-data:GetStatementResult",
        "redshift-data:DescribeStatement",
        "redshift-data:ListDatabases",
        "redshift-data:ListSchemas",
        "redshift-data:ListTables",
        "redshift-data:DescribeTable"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ODBKMSAccess",
      "Effect": "Allow",
      "Action": [
        "kms:CreateKey",
        "kms:DescribeKey",
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:GenerateDataKey",
        "kms:ListKeys",
        "kms:CreateAlias",
        "kms:ListAliases"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ODBSecretsManagerAccess",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:GetSecretValue",
        "secretsmanager:PutSecretValue",
        "secretsmanager:CreateSecret",
        "secretsmanager:UpdateSecret",
        "secretsmanager:DeleteSecret",
        "secretsmanager:DescribeSecret",
        "secretsmanager:ListSecrets",
        "secretsmanager:GetResourcePolicy",
        "secretsmanager:PutResourcePolicy",
        "secretsmanager:ValidateResourcePolicy"
      ],
      "Resource": "*"
    }
  ]
}
```

------

## 步驟 5：設定 Amazon Redshift 資源政策
<a name="zero-etl-setup-redshift"></a>

在 Amazon Redshift 叢集上設定資源政策，以授權傳入整合。

```
aws redshift put-resource-policy \
  --no-verify-ssl \
  --resource-arn "{{your-redshift-cluster-arn}}" \
  --policy '{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {
          "Service": "redshift.amazonaws.com"
        },
        "Action": [
          "redshift:AuthorizeInboundIntegration"
        ],
        "Condition": {
          "StringEquals": {
            "aws:SourceArn": "{{your-vm-cluster-arn}}"
          }
        }
      },
      {
        "Effect": "Allow",
        "Principal": {
          "AWS": "{{your-account-id}}"
        },
        "Action": [
          "redshift:CreateInboundIntegration"
        ]
      }
    ]
  }' \
  --region us-west-2
```

**提示**  
或者，您可以使用 主控台中的 AWS **「為我修正」**選項。此選項會自動設定所需的 Amazon Redshift 政策，而不需要手動執行。

## 步驟 6：使用 建立零 ETL 整合 AWS Glue
<a name="zero-etl-create-integration"></a>

使用 命令建立零 ETL AWS Glue `create-integration`整合。在此命令中，您可以指定來源 VM 叢集和目標 Amazon Redshift 命名空間。

下列範例會建立與名為 在 Exadata VM 叢集中`pdb1`執行之 PDB 的整合。您也可以在來源 ARN `cloud-autonomous-vm-cluster`中將 取代`cloud-vm-cluster`為 ，以建立自治 VM 叢集。指定 KMS 金鑰是選用的。如果您指定金鑰，它可以與您在 中建立的金鑰不同[步驟 3：設定 AWS Secrets Manager 和 AWS Key Management Service](#zero-etl-setup-secrets)。

```
aws glue create-integration \
  --integration-name "MyODBZeroETLIntegration" \
  --source-arn "arn:aws:odb:{{region}}:{{account}}:cloud-vm-cluster/{{cluster-id}}" \
  --target-arn "arn:aws:redshift:{{region:account}}:namespace/{{namespace-id}}" \
  --data-filter "include: {{pdb1}}.*.*" \
  --integration-config '{
      "RefreshInterval": "10",
      "IntegrationMode": "DEFAULT",
      "SourcePropertiesMap": {
        "secret-arn": "arn:aws:secretsmanager:{{region}}:{{account}}:secret:{{secret-name}}"
      }
    }' \
  --description "Zero-ETL integration for Oracle to Amazon Redshift" \
  --kms-key-id "arn:aws:kms:{{region:account}}:key/{{key-id}}"
```

命令會傳回整合 ARN，並將狀態設定為 `creating`。您可以使用 `describe-integrations`命令監控整合狀態。

```
aws glue describe-integrations \
  --integration-identifier {{integration-id}}
```

**重要**  
每個整合僅支援一個 PDB。資料篩選條件必須指定單一 PDB，例如 `include: pdb1.*.*`。來源必須位於建立整合的相同 AWS 區域和帳戶中。

## 步驟 7：在 Amazon Redshift 中建立目標資料庫
<a name="zero-etl-create-target-database"></a>

整合處於作用中狀態後，請在 Amazon Redshift 叢集中建立目標資料庫。

```
-- Connect to your Amazon Redshift cluster
psql -h {{your-redshift-endpoint}} -U {{username}} -d {{database}}

-- Create database from integration
CREATE DATABASE {{target_database_name}} 
FROM INTEGRATION '{{integration-id}}' 
DATABASE "{{source_pdb_name}}";
```

建立目標資料庫之後，您可以查詢複寫的資料。

```
-- List databases to verify creation
\l

-- Connect to the new database
\c {{target_database_name}}

-- List tables to see replicated data
\dt
```

## 驗證零 ETL 整合
<a name="zero-etl-verify-setup"></a>

透過在 中查詢整合狀態， AWS Glue 並確保您的 Oracle 變更正在複寫至 Amazon Redshift 來驗證整合是否正常運作。

**驗證您的零 ETL 整合是否正常運作**

1. 檢查整合狀態。

   ```
   aws glue describe-integrations \
     --integration-identifier {{integration-id}}
   ```

   狀態應為 `ACTIVE`或 `REPLICATING`。

1. 在 Oracle 資料庫中進行變更並檢查資料複寫是否出現在 Amazon Redshift 中，以驗證資料複寫。

1. 在 Amazon CloudWatch 中監控複寫指標 （如果可用）。