Ama*_*hik 5 amazon-s3 amazon-web-services aws-lambda
我创建了两个配置文件(一个用于源,一个用于目标存储桶)并使用以下命令进行复制:
aws s3 cp --profile source_profile s3://source_bucket/file.txt --profile target_profile s3://target_profile/
Run Code Online (Sandbox Code Playgroud)
但它会低于错误.
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
Run Code Online (Sandbox Code Playgroud)
看起来我们不能使用aws命令使用多个配置文件.
最简单的方法是通过存储桶策略授予权限。
假设你有:
在Bucket-B上添加桶策略:
{
"Id": "CopyBuckets",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "GrantAccessToUser-A",
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucket-b",
"arn:aws:s3:::bucket-b/*"
],
"Principal": {
"AWS": [
"arn:aws:iam::<account-a-id>:user/user-a"
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后以 User-A 身份复制文件。
另请参阅:aws sync不同 AWS 账户上的 S3 存储桶之间
不可以,您不能在一个 AWS CLI 命令中使用多个配置文件。可能的解决方案:
1)将文件下载到本地磁盘,然后使用单独的命令将其上传到目标存储桶。
2) 允许第一个帐户访问目标存储桶。为此,您必须在源账户中创建跨账户角色,并在目标账户中为其分配适当的权限。这样,您将使用一个角色/一个配置文件,但该角色将在第二个帐户中被授予权限。请参阅https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html
| 归档时间: |
|
| 查看次数: |
911 次 |
| 最近记录: |