本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
整合 RDS for SQL Server 與 S3 的先決條件
開始之前,請尋找或建立您要使用的 S3 儲存貯體。另外,新增許可,以允許 RDS DB 執行個體存取 S3 儲存貯體。若要設定此存取,請建立 IAM 政策和 IAM 角色。
建立 IAM 政策以存取 Amazon S3
-
在 IAM 管理主控台
的導覽窗格中,選擇 Policies (政策)。 -
建立新政策,並使用 Visual editor (視覺化編輯器) 索引標籤執行下列步驟。
-
針對 Service (服務),輸入
S3
,然後選擇 S3 服務。 -
針對 Actions (動作),選擇下列選項,以授予資料庫執行個體所需的存取:
-
ListAllMyBuckets
– 必要 -
ListBucket
– 必要 -
GetBucketAcl
– 必要 -
GetBucketLocation
– 必要 -
GetObject
– 將 S3 中的檔案下載至 時需要D:\S3\
-
PutObject
– 將D:\S3\
中的檔案上傳至 S3 時需要 -
ListMultipartUploadParts
– 將D:\S3\
中的檔案上傳至 S3 時需要 -
AbortMultipartUpload
– 將D:\S3\
中的檔案上傳至 S3 時需要
-
-
針對 Resources (資源),顯示的選項取決於您在上一步選擇的動作。您看到的選項可能是 bucket (儲存貯體)、object (物件) 或兩者都有。對於每一項,新增適當的 Amazon Resource Name (ARN)。
針對 bucket (儲存貯體),新增您要使用的儲存貯體的 ARN。例如,如果您的儲存貯體名為
amzn-s3-demo-bucket
,請將 ARN 設定為arn:aws:s3:::
。amzn-s3-demo-bucket
針對 object (物件),輸入儲存貯體的 ARN,然後選擇下列其中一個:
-
若要允許存取指定儲存貯體中的所有檔案,對於 Bucket name (儲存貯體) 和 Object name (物件名稱),請都選擇 Any (任何)。
-
若要允許存取儲存貯體中的特定檔案或資料夾,請提供您要讓 SQL Server 存取的特定儲存貯體和物件的 ARN。
-
-
遵循主控台的指示操作,直到完成建立政策。
以上為設定政策的簡略指南。如需建立 IAM 政策的詳細指示,請參閱 IAM 使用者指南中的建立 IAM 政策。
建立 IAM 角色以使用前一個程序中的 IAM 政策
使用以下程序,為 Amazon RDS 授予 Amazon S3 儲存貯體的存取權:
-
建立 IAM 政策以允許 Amazon RDS 存取 S3 儲存貯體。
-
建立 IAM 角色,讓 Amazon RDS 可代表您存取 S3 儲存貯體。
如需更多詳細資訊,請參閱《IAM 使用者指南》中的建立角色以將許可委派給 IAM 使用者。
-
將您建立的 IAM 政策附加至您建立的 IAM 角色。
若要建立 IAM 政策
包含適當動作,以授予資料庫執行個體所需的存取:
-
ListAllMyBuckets
– 必要 -
ListBucket
– 必要 -
GetBucketAcl
– 必要 -
GetBucketLocation
– 必要 -
GetObject
– 將 S3 中的檔案下載至 時需要D:\S3\
-
PutObject
– 將D:\S3\
中的檔案上傳至 S3 時需要 -
ListMultipartUploadParts
– 將D:\S3\
中的檔案上傳至 S3 時需要 -
AbortMultipartUpload
– 將D:\S3\
中的檔案上傳至 S3 時需要
-
下列 AWS CLI 命令會使用這些選項建立名為
rds-s3-integration-policy
的 IAM 政策。它將存取權授予名為amzn-s3-demo-bucket
的儲存貯體。對於 Linux、 macOS或 Unix:
aws iam create-policy \ --policy-name
rds-s3-integration-policy
\ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:ListAllMyBuckets", "Resource": "*" }, { "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetBucketAcl", "s3:GetBucketLocation" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket
" }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:ListMultipartUploadParts", "s3:AbortMultipartUpload" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket
/key_prefix
/*" } ] }'在 Windows 中:
務必將行尾改成您的界面所支援的字元 (
^
而不是\
)。另外,在 Windows 中,您必須以\
逸出所有雙引號。為了避免需要在 JSON 中逸出雙引號,您可以將 JSON 儲存為檔案,然後當作參數傳遞。首先,建立包含下列許可政策的
policy.json
檔案:然後,使用以下命令建立政策:
aws iam create-policy ^ --policy-name
rds-s3-integration-policy
^ --policy-document file://file_path
/assume_role_policy.json -
政策建立後,請記下政策的 Amazon Resource Name (ARN)。後續步驟需要此 ARN。
建立 IAM 角色
-
下列 AWS CLI 命令會為此目的建立
rds-s3-integration-role
IAM 角色。對於 Linux、 macOS或 Unix:
aws iam create-role \ --role-name
rds-s3-integration-role
\ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "rds.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }'在 Windows 中:
務必將行尾改成您的界面所支援的字元 (
^
而不是\
)。另外,在 Windows 中,您必須以\
逸出所有雙引號。為了避免需要在 JSON 中逸出雙引號,您可以將 JSON 儲存為檔案,然後當作參數傳遞。首先,建立包含下列政策的
assume_role_policy.json
檔案:使用以下命令建立 IAM 角色:
aws iam create-role ^ --role-name
rds-s3-integration-role
^ --assume-role-policy-document file://file_path
/assume_role_policy.json範例 使用全域條件內容索引鍵建立 IAM 角色
建議您在資源型政策中使用
aws:SourceArn
和aws:SourceAccount
全域條件內容索引鍵,將服務的許可限定於特定資源。這是防止混淆代理人問題最有效的方式。您可以同時使用全域條件內容索引鍵和包含帳號 ID 的
aws:SourceArn
值。在此情況下,當在相同政策陳述式中使用aws:SourceAccount
值和aws:SourceArn
裡的帳户時,兩者必須使用同樣的帳户 ID。-
如果您想要跨服務存取單一資源,請使用
aws:SourceArn
。 -
如果您想要允許該帳戶中的任何資源與跨服務使用相關聯,請使用
aws:SourceAccount
。
在政策中,請務必使用
aws:SourceArn
全域條件內容索引鍵,其中包含存取角色的資源之完整 Amazon 資源名稱 (ARN)。為進行 S3 整合,請務必包含資料庫執行個體 ARN,如下列範例所示。對於 Linux、 macOS或 Unix:
aws iam create-role \ --role-name
rds-s3-integration-role
\ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "rds.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceArn":"arn:aws:rds:Region
:my_account_ID
:db:db_instance_identifier
" } } } ] }'在 Windows 中:
將全域條件內容索引鍵新增至
assume_role_policy.json
。 -
將 IAM 政策連接至 IAM 角色
-
下列 AWS CLI 命令會將政策連接至名為 的角色
rds-s3-integration-role
。將
替換為您前個步驟記下的政策 ARN。your-policy-arn
對於 Linux、 macOS或 Unix:
aws iam attach-role-policy \ --policy-arn
your-policy-arn
\ --role-namerds-s3-integration-role
在 Windows 中:
aws iam attach-role-policy ^ --policy-arn
your-policy-arn
^ --role-namerds-s3-integration-role