

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

# 設定您的 Amazon RDS Custom for Oracle 的環境
<a name="custom-setup-orcl"></a>

在建立 Amazon RDS Custom for Oracle 資料庫執行個體之前，請執行下列任務。

**Topics**
+ [步驟 1：建立或重複使用對稱加密 AWS KMS 金鑰](#custom-setup-orcl.cmk)
+ [步驟 2：下載並安裝 AWS CLI](#custom-setup-orcl.cli)
+ [步驟 3：擷取 RDS Custom for Oracle 的 CloudFormation 範本](#custom-setup-orcl.cf.downloading)
+ [步驟 4：設定 RDS Custom for Oracle 的 IAM](#custom-setup-orcl.iam-vpc)
+ [步驟 5：將所需的許可授予您的 IAM 使用者或角色](#custom-setup-orcl.iam-user)
+ [步驟 6：設定 RDS Custom for Oracle 的 VPC](#custom-setup-orc.vpc-config)

## 步驟 1：建立或重複使用對稱加密 AWS KMS 金鑰
<a name="custom-setup-orcl.cmk"></a>

*客戶受管金鑰* AWS KMS keys 位於您建立、擁有和管理的 AWS 帳戶中。RDS Custom 需要客戶受管對稱加密 KMS 金鑰。建立 RDS Custom for Oracle 資料庫執行個體時，您要提供 KMS 金鑰識別符。如需詳細資訊，請參閱[設定 Amazon RDS Custom for Oracle 的資料庫執行個體](custom-creating.md)。

您有下列選項：
+ 如果您的 中有現有的客戶受管 KMS 金鑰 AWS 帳戶，您可以搭配 RDS Custom 使用。無需採取進一步動作。
+ 若您已為不同的 RDS Custom 引擎建立客戶受管對稱加密 KMS 金鑰，您可以重複使用相同的 KMS 金鑰。無需採取進一步動作。
+ 若您的帳戶中並無現有的客戶受管對稱加密 KMS 金鑰，請藉由遵循《AWS Key Management Service 開發人員指南》**中的[建立金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html#create-symmetric-cmk)來建立 KMS 金鑰。
+ 如果您要建立 CEV 或 RDS Custom 資料庫執行個體，且 KMS 金鑰位於不同的 AWS 帳戶中，請務必使用 AWS CLI。您無法搭配跨帳戶 KMS 金鑰使用 AWS 主控台。

**重要**  
RDS Custom 不支援 AWS 受管 KMS 金鑰。

請確定您的對稱加密金鑰將 `kms:Decrypt`和 `kms:GenerateDataKey`操作的存取權授予 IAM 執行個體描述檔中的 AWS Identity and Access Management (IAM) 角色。若您的帳戶中有新的對稱加密金鑰，則不需要變更。否則，請確定對稱加密金鑰政策授予這些操作的存取權。

如需詳細資訊，請參閱[步驟 4：設定 RDS Custom for Oracle 的 IAM](#custom-setup-orcl.iam-vpc)。

如需設定 RDS Custom for Oracle 的 IAM 的相關詳細資訊，請參閱 [步驟 4：設定 RDS Custom for Oracle 的 IAM](#custom-setup-orcl.iam-vpc)。

## 步驟 2：下載並安裝 AWS CLI
<a name="custom-setup-orcl.cli"></a>

AWS 為您提供命令列界面來使用 RDS Custom 功能。您可以使用 AWS CLI的第 1 版或第 2 版。

如需下載和安裝 的資訊 AWS CLI，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

如果以下任一情況屬實，請略過此步驟：
+ 您計劃只從 存取 RDS Custom AWS 管理主控台。
+ 您已下載 AWS CLI 適用於 Amazon RDS 的 或不同的 RDS Custom 資料庫引擎。

## 步驟 3：擷取 RDS Custom for Oracle 的 CloudFormation 範本
<a name="custom-setup-orcl.cf.downloading"></a>

為了簡化設定，強烈建議您使用 CloudFormation 範本來建立 CloudFormation 堆疊。如果您打算手動設定 IAM 和 VPC，請略過此步驟。

**Topics**
+ [步驟 3a：下載 CloudFormation 範本檔案](#custom-setup-orcl.cf.dl-templates)
+ [步驟 3b：擷取 custom-oracle-iam.json](#custom-setup-orcl.cf.downloading.ca-role)
+ [步驟 3c：擷取 custom-vpc.json](#custom-setup-orcl.cf.downloading.ca-pn)

### 步驟 3a：下載 CloudFormation 範本檔案
<a name="custom-setup-orcl.cf.dl-templates"></a>

CloudFormation 範本是形成堆疊之 AWS 資源的宣告。範本會儲存為 JSON 檔案。

**下載 CloudFormation 範本檔案**

1. 開啟連結 [custom-oracle-iam.zip](samples/custom-oracle-iam.zip) 的內容 (滑鼠右鍵) 功能表，然後選擇 **Save Link As** (另存連結為)。

1. 將檔案儲存到您的電腦。

1. 針對連結 [custom-vpc.zip](samples/custom-vpc.zip) 重複先前的步驟。

   如果您已經為 RDS Custom 設定 VPC，請略過這個步驟。

### 步驟 3b：擷取 custom-oracle-iam.json
<a name="custom-setup-orcl.cf.downloading.ca-role"></a>

開啟您下載的 `custom-oracle-iam.zip` 檔案，然後解壓縮檔案 `custom-oracle-iam.json`。檔案的開頭如下所示。

```
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "EncryptionKey": {
      "Type": "String",
      "Default": "*",
      "Description": "KMS Key ARN for encryption of data managed by RDS Custom and by DB Instances."
    }
  },
  "Resources": {
    "RDSCustomInstanceServiceRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": { "Fn::Sub": "AWSRDSCustomInstanceRole-${AWS::Region}" },
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",		 	 	 
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": "ec2.amazonaws.com"
              }
            }
          ]
        },...
```

### 步驟 3c：擷取 custom-vpc.json
<a name="custom-setup-orcl.cf.downloading.ca-pn"></a>

**注意**  
如果您已經為 RDS Custom for Oracle 設定現有的 VPC，請略過這個步驟。如需詳細資訊，請參閱[為 RDS Custom for Oracle 手動設定 VPC](#custom-setup-orcl.vpc)。

開啟您下載的 `custom-vpc.zip` 檔案，然後解壓縮檔案 `custom-vpc.json`。檔案的開頭如下所示。

```
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "PrivateVpc": {
      "Type": "AWS::EC2::VPC::Id",
      "Description": "Private VPC Id to use for RDS Custom DB Instances"
    },
    "PrivateSubnets": {
      "Type": "List<AWS::EC2::Subnet::Id>",
      "Description": "Private Subnets to use for RDS Custom DB Instances"
    },
    "RouteTable": {
      "Type": "String",
      "Description": "Route Table that must be associated with the PrivateSubnets and used by S3 VPC Endpoint",
      "AllowedPattern": "rtb-[0-9a-z]+"
    }
  },
  "Resources": {
    "DBSubnetGroup": {
      "Type": "AWS::RDS::DBSubnetGroup",
      "Properties": {
        "DBSubnetGroupName": "rds-custom-private",
        "DBSubnetGroupDescription": "RDS Custom Private Network",
        "SubnetIds": {
          "Ref": "PrivateSubnets"
        }
      }
    },...
```

## 步驟 4：設定 RDS Custom for Oracle 的 IAM
<a name="custom-setup-orcl.iam-vpc"></a>

您透過主控台或 AWS CLI，使用 IAM 角色或 IAM 使用者 (也稱為 IAM 實體)，來建立 RDS Custom 資料庫執行個體。此 IAM 實體必須擁有執行個體建立的必要許可。

您可以使用 CloudFormation 或手動步驟來設定 IAM。

**重要**  
我們強烈建議您使用 設定 RDS Custom for Oracle 環境 CloudFormation。這是最簡單且最不容易出錯的方法。

**Topics**
+ [使用 CloudFormation 設定 IAM](#custom-setup-orcl.cf.config-iam)
+ [手動建立 IAM 角色和執行個體設定檔](#custom-setup-orcl.iam)

### 使用 CloudFormation 設定 IAM
<a name="custom-setup-orcl.cf.config-iam"></a>

當您針對 IAM 使用 CloudFormation 範本時，會建立下列必要資源：
+ 名為 `AWSRDSCustomInstanceProfile-region` 的執行個體設定檔
+ 名為 `AWSRDSCustomInstanceRole-region` 的服務角色
+ 名為 `AWSRDSCustomIamRolePolicy` 且連接至服務角色的存取政策

**若要使用 CloudFormation 設定 IAM**

1. 在 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 開啟 CloudFormation 主控台。

1. 啟動「建立堆疊」精靈，然後選擇 **Create Stack** (建立堆疊)。

1. 在 **Create stack** (建立堆疊) 頁面上，執行下列動作：

   1. 針對 **Prepare template** (準備範本)，選擇 **Template is ready** (範本已就緒)。

   1. 針對 **Template source** (範本來源)，選擇 **Upload a template file** (上傳範本檔案)。

   1. 在**選擇檔案**中，導覽並選擇 **custom-oracle-iam.json**。

   1. 選擇**下一步**。

1. 在 **Specify stack details** (指定堆疊詳細資訊) 頁面上，執行下列操作：

   1. 針對**堆疊名稱** 輸入 **custom-oracle-iam**。

   1. 選擇**下一步**。

1. 在 **Configure stack options** (設定堆疊選項) 頁面，選擇 **Next** (下一步)。

1. 在 **Review custom-oracle-iam** (檢閱 custom-oracle-iam) 頁面上，執行下列操作：

   1. 選取 ****I acknowledge that CloudFormation might create IAM resources with custom names**** (確認 CloudFormation 可能使用自訂名稱建立 IAM 資源) 核取方塊。

   1. 選擇**提交**。

   CloudFormation 會建立 RDS Custom for Oracle 需要的 IAM 角色。在左側面板中，當 **custom-oracle-iam** 顯示 **CREATE\$1COMPLETE** 時，請繼續執行下一個步驟。

1. 在左側面板中，選擇 **custom-oracle-iam**。在右側面板中，執行下列作業：

   1. 選擇**堆疊資訊**。您的堆疊具有格式為 **arn:aws:cloudformation:*region*:*account-no*:stack/custom-oracle-iam/*identifier*** 的 ID。

   1. 選擇**資源**。請查看下列事項：
      + 名為 **AWSRDSCustomInstanceProfile-*region*** 的執行個體設定檔
      + 名為 **AWSRDSCustomInstanceRole-*region*** 的服務角色

      建立 RDS Custom 資料庫執行個體時，您必須提供執行個體設定檔 ID。

### 手動建立 IAM 角色和執行個體設定檔
<a name="custom-setup-orcl.iam"></a>

使用 CloudFormation 進行設定是最簡單的方式。或者，您也可以手動設定 IAM。針對手動設定，請執行下列動作：
+ [步驟 1：建立 IAM 角色 AWSRDSCustomInstanceRoleForRdsCustomInstance](#custom-setup-orcl.iam.create-role).
+ [步驟 2：將存取政策新增至 AWSRDSCustomInstanceRoleForRdsCustomInstance](#custom-setup-orcl.iam.add-policy).
+ [步驟 2：將存取政策新增至 AWSRDSCustomInstanceRoleForRdsCustomInstance](#custom-setup-orcl.iam.create-profile).
+ [步驟 4：將 AWSRDSCustomInstanceRoleForRdsCustomInstance 新增至 AWSRDSCustomInstanceProfile](#custom-setup-orcl.iam.add-profile).

#### 步驟 1：建立 IAM 角色 AWSRDSCustomInstanceRoleForRdsCustomInstance
<a name="custom-setup-orcl.iam.create-role"></a>

在此步驟中，您可以使用命名格式 `AWSRDSCustomInstanceRole-region` 來建立角色。使用信任政策，Amazon EC2 可以擔任角色。下列範例假設您已將環境變數 `$REGION` 設為 AWS 區域 ，且您要在其中建立資料庫執行個體。

```
aws iam create-role \
  --role-name AWSRDSCustomInstanceRole-$REGION \
  --assume-role-policy-document '{
    "Version": "2012-10-17",		 	 	 
      "Statement": [
        {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
              "Service": "ec2.amazonaws.com"
          }
        }
      ]
    }'
```

#### 步驟 2：將存取政策新增至 AWSRDSCustomInstanceRoleForRdsCustomInstance
<a name="custom-setup-orcl.iam.add-policy"></a>

當您在 IAM 角色中內嵌內遷政策時，內嵌政策會用來做為角色存取 (許可) 政策的一部分。您可以建立 `AWSRDSCustomIamRolePolicy` 政策，允許 Amazon EC2 傳送和接收訊息以及執行各種動作。

下列範例會建立名為 `AWSRDSCustomIamRolePolicy` 的存取政策，並將其新增至 IAM 角色 `AWSRDSCustomInstanceRole-region`。此範例假設您已設定下列環境變數：

`$REGION`  
將此變數設定為您計劃在 AWS 區域 其中建立資料庫執行個體的 。

`$ACCOUNT_ID`  
將此變數設定為您的 AWS 帳戶 數字。

`$KMS_KEY`  
將此變數設為 AWS KMS key 的 Amazon Resource Name (ARN)，您想要用於 RDS Custom 資料庫執行個體。若要指定一個以上的 KMS 金鑰，請將它新增至陳述式 ID (Sid) 11 的 `Resources` 區段。

```
aws iam put-role-policy \
  --role-name AWSRDSCustomInstanceRole-$REGION \
  --policy-name AWSRDSCustomIamRolePolicy \
  --policy-document '{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Action": [
                "ssm:DescribeAssociation",
                "ssm:GetDeployablePatchSnapshotForInstance",
                "ssm:GetDocument",
                "ssm:DescribeDocument",
                "ssm:GetManifest",
                "ssm:GetParameter",
                "ssm:GetParameters",
                "ssm:ListAssociations",
                "ssm:ListInstanceAssociations",
                "ssm:PutInventory",
                "ssm:PutComplianceItems",
                "ssm:PutConfigurePackageResult",
                "ssm:UpdateAssociationStatus",
                "ssm:UpdateInstanceAssociationStatus",
                "ssm:UpdateInstanceInformation",
                "ssm:GetConnectionStatus",
                "ssm:DescribeInstanceInformation",
                "ssmmessages:CreateControlChannel",
                "ssmmessages:CreateDataChannel",
                "ssmmessages:OpenControlChannel",
                "ssmmessages:OpenDataChannel"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "2",
            "Effect": "Allow",
            "Action": [
                "ec2messages:AcknowledgeMessage",
                "ec2messages:DeleteMessage",
                "ec2messages:FailMessage",
                "ec2messages:GetEndpoint",
                "ec2messages:GetMessages",
                "ec2messages:SendReply"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "3",
            "Effect": "Allow",
            "Action": [
                "logs:PutRetentionPolicy",
                "logs:PutLogEvents",
                "logs:DescribeLogStreams",
                "logs:DescribeLogGroups",
                "logs:CreateLogStream",
                "logs:CreateLogGroup"
            ],
            "Resource": [
                "arn:aws:logs:'$REGION':'$ACCOUNT_ID':log-group:rds-custom-instance*"
            ]
        },
        {
            "Sid": "4",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": [
                "arn:aws:s3:::do-not-delete-rds-custom-*/*"
            ]
        },
        {
            "Sid": "5",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": [
                "*"
            ],
            "Condition": {
                "StringEquals": {
                    "cloudwatch:namespace": [
                        "RDSCustomForOracle/Agent"
                    ]
                }
            }
        },
        {
            "Sid": "6",
            "Effect": "Allow",
            "Action": [
                "events:PutEvents"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "7",
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue",
                "secretsmanager:DescribeSecret"
            ],
            "Resource": [
                "arn:aws:secretsmanager:'$REGION':'$ACCOUNT_ID':secret:do-not-delete-rds-custom-*",
                "arn:aws:secretsmanager:'$REGION':'$ACCOUNT_ID':secret:rds-custom!oracle-do-not-delete-*"
            ]
        },
        {
           "Sid": "8",
           "Effect": "Allow",
           "Action": [
             "s3:ListBucketVersions"
           ],
           "Resource": [
             "arn:aws:s3:::do-not-delete-rds-custom-*"
           ]
         },
         {
            "Sid": "9",
            "Effect": "Allow",
            "Action": "ec2:CreateSnapshots",
            "Resource": [
                "arn:aws:ec2:*:*:instance/*",
                "arn:aws:ec2:*:*:volume/*"
            ],
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/AWSRDSCustom": "custom-oracle"
                }
            }
          },
          {
            "Sid": "10",
            "Effect": "Allow",
            "Action": "ec2:CreateSnapshots",
            "Resource": [
                "arn:aws:ec2:*::snapshot/*"
            ]
          },
          {
            "Sid": "11",
            "Effect": "Allow",
            "Action": [
              "kms:Decrypt",
              "kms:GenerateDataKey"
            ],
            "Resource": [
              "arn:aws:kms:'$REGION':'$ACCOUNT_ID':key/'$KMS_KEY'"
            ]
          },
          {
            "Sid": "12",
            "Effect": "Allow",
            "Action": "ec2:CreateTags",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "ec2:CreateAction": [
                        "CreateSnapshots"
                    ]
                }
            }
        },
        {
            "Sid": "13",
            "Effect": "Allow",
            "Action": [
                "sqs:SendMessage",
                "sqs:ReceiveMessage",
                "sqs:DeleteMessage",
                "sqs:GetQueueUrl"
            ],
            "Resource": "arn:aws:sqs:'$REGION':'$ACCOUNT_Id':do-not-delete-rds-custom-*",
            "Condition": {
                "StringLike": {
                    "aws:ResourceTag/AWSRDSCustom": "custom-oracle"
                }
            }
        }
    ]
}'
```

#### 步驟 3：建立 RDS Custom 執行個體設定檔 AWSRDSCustomInstanceProfile
<a name="custom-setup-orcl.iam.create-profile"></a>

執行個體設定檔是包含單一 IAM 角色的容器。RDS Custom 會使用執行個體設定檔，將角色傳遞到執行個體。

如果您使用 CLI 建立角色，則建立角色與執行個體設定檔為不同動作，且可以使用不同名稱。依照下列方式建立 IAM 執行個體設定檔，並以格式 `AWSRDSCustomInstanceProfile-region` 命名。下列範例假設您已將環境變數設定為要在 AWS 區域 其中建立資料庫執行個體`$REGION`的 。

```
aws iam create-instance-profile \
    --instance-profile-name AWSRDSCustomInstanceProfile-$REGION
```

#### 步驟 4：將 AWSRDSCustomInstanceRoleForRdsCustomInstance 新增至 AWSRDSCustomInstanceProfile
<a name="custom-setup-orcl.iam.add-profile"></a>

將 IAM 角色新增至先前建立的執行個體設定檔。下列範例假設您已將環境變數設定為要在 AWS 區域 其中建立資料庫執行個體`$REGION`的 。

```
aws iam add-role-to-instance-profile \
    --instance-profile-name AWSRDSCustomInstanceProfile-$REGION \
    --role-name AWSRDSCustomInstanceRole-$REGION
```

## 步驟 5：將所需的許可授予您的 IAM 使用者或角色
<a name="custom-setup-orcl.iam-user"></a>

確保建立 CEV 或 RDS Custom 資料庫執行個體的 IAM 主體 (使用者或角色) 具有以下其中一個政策：
+ `AdministratorAccess` 政策
+ 具有 Amazon S3 和 AWS KMS、CEV 建立和資料庫執行個體建立所需許可`AmazonRDSFullAccess`的政策

**Topics**
+ [Amazon S3 和 所需的 IAM 許可 AWS KMS](#custom-setup-orcl.s3-kms)
+ [建立 CEV 所需的 IAM 許可](#custom-setup-orcl.cev)
+ [從 CEV 建立資料庫執行個體所需的 IAM 許可](#custom-setup-orcl.db)

### Amazon S3 和 所需的 IAM 許可 AWS KMS
<a name="custom-setup-orcl.s3-kms"></a>

若要建立 CEV 或 RDS Custom for Oracle 資料庫執行個體，您的 IAM 主體需要存取 Amazon S3 和 AWS KMS。以下範例 JSON 政策授予必要許可。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "CreateS3Bucket",
            "Effect": "Allow",
            "Action": [
                "s3:CreateBucket",
                "s3:PutBucketPolicy",
                "s3:PutBucketObjectLockConfiguration",
                "s3:PutBucketVersioning"
            ],
            "Resource": "arn:aws:s3:::do-not-delete-rds-custom-*"
        },
        {
            "Sid": "CreateKmsGrant",
            "Effect": "Allow",
            "Action": [
                "kms:CreateGrant",
                "kms:DescribeKey"
            ],
            "Resource": "*"
        }
    ]
}
```

------

如需 `kms:CreateGrant` 許可的詳細資訊，請參閱 [AWS KMS key 管理](Overview.Encryption.Keys.md)。

### 建立 CEV 所需的 IAM 許可
<a name="custom-setup-orcl.cev"></a>

若要建立 CEV，您的 IAM 主體需要以下額外許可：

```
s3:GetObjectAcl
s3:GetObject
s3:GetObjectTagging
s3:ListBucket
mediaimport:CreateDatabaseBinarySnapshot
```

以下範例 JSON 政策授予額外的必要許可，以存取儲存貯體 *my-custom-installation-files* 及其內容。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AccessToS3MediaBucket",
            "Effect": "Allow",
            "Action": [
                "s3:GetObjectAcl",
                "s3:GetObject",
                "s3:GetObjectTagging",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::my-custom-installation-files",
                "arn:aws:s3:::my-custom-installation-files/*"
            ]
        },
        {
            "Sid": "PermissionForByom",
            "Effect": "Allow",
            "Action": [
                "mediaimport:CreateDatabaseBinarySnapshot"
            ],
            "Resource": "*"
        }
    ]
}
```

------

您可以使用 S3 儲存貯體政策，將 Amazon S3 的類似許可授予呼叫者的帳戶。

### 從 CEV 建立資料庫執行個體所需的 IAM 許可
<a name="custom-setup-orcl.db"></a>

若要從現有 CEV 建立 RDS Custom for Oracle 資料庫執行個體，IAM 主體需要下列額外許可。

```
iam:SimulatePrincipalPolicy
cloudtrail:CreateTrail
cloudtrail:StartLogging
```

下列範例 JSON 政策授予 AWS CloudTrail驗證 IAM 角色和日誌資訊所需的必要許可。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "ValidateIamRole",
            "Effect": "Allow",
            "Action": "iam:SimulatePrincipalPolicy",
            "Resource": "*"
        },
        {
            "Sid": "CreateCloudTrail",
            "Effect": "Allow",
            "Action": [
                "cloudtrail:CreateTrail",
                "cloudtrail:StartLogging"
            ],
            "Resource": "arn:aws:cloudtrail:*:*:trail/do-not-delete-rds-custom-*"
        }
    ]
}
```

------

## 步驟 6：設定 RDS Custom for Oracle 的 VPC
<a name="custom-setup-orc.vpc-config"></a>

根據 Amazon VPC 服務，您的 RDS Custom 資料庫執行個體位於虛擬私有雲端 (VPC)，就像是 Amazon EC2 執行個體或 Amazon RDS 執行個體。您可以提供和設定您自己的 VPC。與 RDS Custom for SQL Server 不同，RDS Custom for Oracle 不會建立存取控制清單或安全群組。您必須連接自己的安全群組、子網路和路由表。

您可以使用 CloudFormation 或手動程序來設定虛擬私有雲端 (VPC)。

**重要**  
我們強烈建議您使用 設定 RDS Custom for Oracle 環境 CloudFormation。這是最簡單且最不容易出錯的方法。

**Topics**
+ [使用 CloudFormation 設定 VPC (建議)](#custom-setup-orcl.cf.config-vpc)
+ [為 RDS Custom for Oracle 手動設定 VPC](#custom-setup-orcl.vpc)

### 使用 CloudFormation 設定 VPC (建議)
<a name="custom-setup-orcl.cf.config-vpc"></a>

若您已經為不同的 RDS Custom 引擎設定 VPC，且要重複使用現有 VPC，請略過此步驟。此區段假設如下：
+ 您已經使用 CloudFormation 建立您的 IAM 執行個體設定檔和角色。
+ 您知道您的路由表 ID。

  若要私有化資料庫執行個體，其須位於私有子網路。若要私有化子網路，則其不能與具有預設網際網路閘道的路由表相關聯。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的[設定路由表](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html)。

當您針對 VPC 使用 CloudFormation 範本時，會建立下列資源：
+ 私有 VPC
+ 名為 `rds-custom-private` 的子網路群組
+ 資料庫執行個體用來與相依 AWS 服務通訊時，必須具有下列 VPC 端點：
  + `com.amazonaws.region.ec2messages`
  + `com.amazonaws.region.events`
  + `com.amazonaws.region.logs`
  + `com.amazonaws.region.monitoring`
  + `com.amazonaws.region.s3`
  + `com.amazonaws.region.secretsmanager`
  + `com.amazonaws.region.ssm`
  + `com.amazonaws.region.ssmmessages`

  如果您要建立多可用區域部署：
  + `com.amazonaws.region.sqs`
**注意**  
對於具有現有帳戶的複雜聯網設定，如果存取尚未存在，建議您手動設定相依服務的存取。如需詳細資訊，請參閱[確保您的 VPC 可以存取相依性 AWS 服務](#custom-setup-orcl.vpc.endpoints)。

**若要使用 CloudFormation 設定 VPC**

1. 開啟位於 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 的 CloudFormation 主控台。

1. 啟動「建立堆疊」精靈，選擇**建立堆疊**，然後選擇**使用新資源 (標準)**。

1. 在 **Create stack** (建立堆疊) 頁面上，執行下列動作：

   1. 針對 **Prepare template** (準備範本)，選擇 **Template is ready** (範本已就緒)。

   1. 針對 **Template source** (範本來源)，選擇 **Upload a template file** (上傳範本檔案)。

   1. 針對 **Choose file** (選擇檔案)，導覽並選擇 `custom-vpc.json`。

   1. 選擇**下一步**。

1. 在 **Specify stack details** (指定堆疊詳細資訊) 頁面上，執行下列操作：

   1. 針對**堆疊名稱** 輸入 **custom-vpc**。

   1. 針對 **Parameters** (參數)，選擇要用於 RDS Custom 資料庫執行個體的私有子網路。

   1. 選擇要用於 RDS Custom 資料庫執行個體的私有 VPC ID。

   1. 輸入與私有子網路相關聯的路由表。

   1. 選擇**下一步**。

1. 在 **Configure stack options** (設定堆疊選項) 頁面，選擇 **Next** (下一步)。

1. 在**檢閱 custom-vpc** 頁面上，選擇**提交**。

   CloudFormation 會設定您的私有 VPC。在左側面板中，當 **custom-vpc** 顯示 **CREATE\$1COMPLETE** 時，請繼續執行下一個步驟。

1. (選用) 檢閱私有 VPC 的詳細資訊。在**堆疊**窗格中，選擇 **custom-vpc**。在右側窗格中，執行下列作業：

   1. 選擇**堆疊資訊**。您的堆疊具有格式為 **arn:aws:cloudformation:*region*:*account-no*:stack/custom-vpc/*identifier*** 的 ID。

   1. 選擇**資源**。您應該會看到名為 **rds-custom-private** 的子網路群組，以及多個使用 **vpce-*string*** 命名格式的 VPC 端點。每個端點對應至 RDS Custom 需要與 AWS 服務 之通訊的 。如需詳細資訊，請參閱[確保您的 VPC 可以存取相依性 AWS 服務](#custom-setup-orcl.vpc.endpoints)。

   1. 選擇**參數**。您應該會看到私有子網路、私有 VPC 和您在建立堆疊時指定的路由表。在建立資料庫執行個體時，您需要提供 VPC ID 和子網路群組。

### 為 RDS Custom for Oracle 手動設定 VPC
<a name="custom-setup-orcl.vpc"></a>

除了使用 自動建立 VPC 之外 CloudFormation，您也可以手動設定 VPC。當您擁有使用現有資源的複雜聯網設定時，這可能是最佳選項。

**Topics**
+ [確保您的 VPC 可以存取相依性 AWS 服務](#custom-setup-orcl.vpc.endpoints)
+ [設定個體中繼資料服務](#custom-setup-orcl.vpc.imds)

#### 確保您的 VPC 可以存取相依性 AWS 服務
<a name="custom-setup-orcl.vpc.endpoints"></a>

RDS Custom 會將通訊從您的資料庫執行個體傳送到其他 AWS 服務。請確定可從您建立 RDS Custom 資料庫執行個體的子網路存取下列服務：
+ Amazon CloudWatch (`com.amazonaws.region.monitoring`)
+ Amazon CloudWatch Logs (`com.amazonaws.region.logs`)
+ Amazon CloudWatch Events (`com.amazonaws.region.events`)
+ Amazon EC2 (`com.amazonaws.region.ec2` 和 `com.amazonaws.region.ec2messages`)
+ Amazon S3 (`com.amazonaws.region.s3`)
+ AWS Secrets Manager (`com.amazonaws.region.secretsmanager`)
+ AWS Systems Manager (`com.amazonaws.region.ssm` 和 `com.amazonaws.region.ssmmessages`)

若建立多可用區域部署
+ Amazon Simple Queue Service (`com.amazonaws.region.sqs`)

如果 RDS Custom 無法與必要服務進行通訊，則會發佈下列事件：

```
Database instance in incompatible-network. SSM Agent connection not available. Amazon RDS can't connect to the dependent AWS services.
```

```
Database instance in incompatible-network. Amazon RDS can't connect to dependent AWS services. Make sure port 443 (HTTPS) allows outbound connections, and try again. "Failed to connect to the following services: s3 events"
```

若要避免`incompatible-network`錯誤，請確定涉及 RDS Custom 資料庫執行個體之間通訊的 VPC 元件，並 AWS 服務 滿足下列要求：
+ 資料庫執行個體會在連接埠 443 上對其他 AWS 服務進行傳出連線。
+ VPC 允許對來自您 RDS Custom 資料庫執行個體的請求進行傳入回應。
+ RDS Custom 可以正確解析每個 AWS 服務的端點網域名稱。

若您已經為不同的 RDS Custom 資料庫引擎設定 VPC，您可重複使用該 VPC 並略過此程序。

#### 設定個體中繼資料服務
<a name="custom-setup-orcl.vpc.imds"></a>

請確定您的執行個體可以執行下列操作：
+ 使用執行個體中繼資料服務版本 2 (IMDSv2) 存取執行個體中繼資料服務。
+ 允許透過連接埠 80 (HTTP) 與 IMDS 連結 IP 地址進行傳出通訊。
+ 從 `http://169.254.169.254` (IMDSv2 連結) 要求執行個體中繼資料。

如需詳細資訊，請參閱《Amazon EC2 使用者指南》**中的[使用 IMDSv2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html)。

RDS Custom for Oracle 自動化預設會藉由在基礎 Amazon EC2 執行個體上設定 `HttpTokens=enabled` 來使用 IMDSv2。不過，您也可以根據需要使用 IMDSV1。如需詳細資訊，請參閱《Amazon EC2 使用者指南》**中的[設定執行個體中繼資料選項](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html)。