1) 目标角色
- 在目标S3 存储桶所在的账户中创建必要的 IAM 角色
- 登录到目标账户并为 AWS DataSync 创建一个 IAM 角色
DESTINATION-ROLE:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- datasync.amazonaws.com
Path: '/'
RoleName: DESTINATION-ROLE
DESTINATION-POLICY:
Type: AWS::IAM::Policy
Properties:
PolicyName: DESTINATION-POLICY
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- s3:GetBucketLocation
- s3:ListBucket
- s3:ListBucketMultipartUploads
Effect: Allow
Resource: arn:aws:s3:::SOURCEBUCKET
- Action:
- s3:AbortMultipartUpload
- s3:DeleteObject
- s3:GetObject
- s3:ListMultipartUploadParts
- s3:PutObjectTagging
- s3:GetObjectTagging
- s3:PutObject
Effect: Allow
Resource: arn:aws:s3:::SOURCEBUCKET/*
Roles:
- Ref: DESTINATION-ROLE
2) 来源 S3 政策
- “复制您为源 S3 存储桶位置创建的 IAM 角色的 ARN。
- 现在,登录到源帐户。
- 打开源 S3 存储桶策略并应用以下策略为 IAM 角色授予权限
Version: '2012-10-17'
Statement:
- Sid: BucketPolicyForDataSync
Effect: Allow
Principal:
AWS:
- arn:aws:iam::DEST-ACCOUNT-ID:role/DESTINATION-ROLE
Action:
- s3:GetBucketLocation
- s3:ListBucket
- s3:ListBucketMultipartUploads
- s3:AbortMultipartUpload
- s3:DeleteObject
- s3:GetObject
- s3:ListMultipartUploadParts
- s3:PutObject
- s3:GetObjectTagging
- s3:PutObjectTagging
Resource:
- arn:aws:s3:::SOURCEBUCKET
- arn:aws:s3:::SOURCEBUCKET/*
3) CLI 调用
aws datasync create-location-s3 \
--s3-bucket-arn 'arn:aws:s3:::SOURCEBUCKET' \
--region 'us-east-1' \
--s3-config '
{
"BucketAccessRoleArn":
"arn:aws:iam::DEST-ACCOUNT-ID:role/DESTINATION-ROLE"
}
'
3.1) 错误来源账户
An error occurred (AccessDeniedException) when calling the CreateLocationS3 operation: Cross-account pass role is not allowed.
3.2) 错误目的地账户
An error occurred (InvalidRequestException) when calling the CreateLocationS3 operation: Please provide a bucket in the us-east-1 region where DataSync is currently used.