赞
踩
策略(S3MigrationPolicy)示例:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::awsexamplesourcebucket",
"arn:aws:s3:::awsexamplesourcebucket/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::awsexampledestinationbucket",
"arn:aws:s3:::awsexampledestinationbucket/*"
]
}
]
}
角色(S3MigrationRole)示例:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<destination_account>:user/<user_name>"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
使用 AWS CLI 假设S3MigrationRole
aws sts assume-role --role-arn "arn:aws:iam::<destination_account>:role/S3MigrationRole" --role-session-name AWSCLI-Session
这里的 –role-arn 就是上述角色 S3MigrationRole 的 arn
aws sts get-caller-identity
登录到源账户的 AWS mazon 管理控制台,并打开 Amazon S3 控制台。选择您的源 S3 存储桶,然后选择权限。在 “存储桶策略” 下,选择 “编辑”,然后粘贴以下存储桶策略。选择保存。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3Access",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::<destination_account>:role/<RoleName>"},
"Action": ["s3:ListBucket","s3:GetObject"],
"Resource": [
"arn:aws:s3:::awsexamplesourcebucket/*",
"arn:aws:s3:::awsexamplesourcebucket"
]
}
]
}
此基于资源的策略允许目标角色S3MigrationRole访问源账户中的 S3 对象。
⭐️注:此处的 “Principal” 对应的值应该是运行命令 aws sts get-caller-identity 后返回的 arn 的值
复制(有关详细信息,请参阅 AWS CLI 命令参考):
aws s3 cp s3:// DOC-EXAMPLE-BUCKET-SOURCE / \
s3:// DOC-EXAMPLE-BUCKET-TARGET / \
--recursive --source-region SOURCE-REGION-NAME --region DESTINATION-REGION-NAME
同步(有关详细信息,请参阅 AWS CLI 命令参考):
aws s3 sync s3:// DOC-EXAMPLE-BUCKET-SOURCE / \
s3:// DOC-EXAMPLE-BUCKET-TARGET / \
--source-region SOURCE-REGION-NAME --region DESTINATION-REGION-NAME
部分文件在 cp || sync 时报错:An error occurred (AccessDenied) when calling the GetObjectTagging operation: Access Denied
解决办法:
在源桶策略中添加:“s3:GetObjectTagging” 即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。