

# Amazon Redshift와 Oracle Database@AWS 통합 설정
<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://console.aws.amazon.com/odb/](https://console.aws.amazon.com/odb/)에서 Oracle Database@AWS 콘솔을 엽니다.

1. 탐색 창에서 **ODB 네트워크**를 선택합니다.

1. 제로 ETL 통합을 활성화하려는 ODB 네트워크를 선택합니다.

1. **수정**을 선택합니다.

1. **제로 ETL**을 선택합니다.

1. **계속**을 선택하고 **수정**을 선택합니다.

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

제로 ETL 통합을 활성화하려면 `--zero-etl-access` 파라미터와 함께 `update-odb-network` 명령을 사용합니다.

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

[사전 조건](zero-etl-prerequisites.md)에 설명된 대로 Oracle 데이터베이스 구성을 완료합니다.
+ 복제 사용자를 생성하고 필요한 권한을 부여합니다.
+ 보관된 다시 실행 로그를 활성화합니다.
+ 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 액세스를 허용합니다.

   ```
   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 리소스 정책에는 암호화된 제로 ETL 통합을 지원하기 위해 Oracle Database@AWS 서비스 위탁자와 Amazon Redshift 서비스 위탁자 모두에 대한 권한이 포함되어야 합니다.

   ```
   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 서비스 액세스를 허용하고 두 번째 문은 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단계: AWS Glue를 사용하여 제로 ETL 통합 생성
<a name="zero-etl-create-integration"></a>

AWS Glue `create-integration` 명령을 사용하여 제로 ETL 통합을 생성합니다. 이 명령에서는 소스 VM 클러스터와 대상 Amazon Redshift 네임스페이스를 지정합니다.

다음 예제에서는 Exadata VM 클러스터에서 실행되고 있는 `pdb1`이라는 PDB와의 통합을 생성합니다. 소스 ARN에서 `cloud-vm-cluster`를 `cloud-autonomous-vm-cluster`로 대체하여 Autonomous 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만 지원됩니다. 데이터 필터는 `include: pdb1.*.*`와 같은 단일 PDB를 지정해야 합니다. 소스는 통합이 생성되는 동일한 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에서 복제 지표를 모니터링합니다(사용 가능한 경우).