简体   繁体   English

如何使用 boto3 在 aws 中检查 s3 访问密钥是否可以访问特定存储桶

[英]How to check whether s3 access key has access to a specific bucket or not in aws using boto3

I am trying to copy files from 2 different bucket which are in two different aws account using same access key.我正在尝试使用相同的访问密钥从位于两个不同 aws 帐户中的 2 个不同存储桶中复制文件。 So it provide an error saying 403 forbidden.So what i want to do is, I want to check whether the access key that i am using to copy the file has permission to those bucket before i copy the file using boto3.所以它提供了一个错误,说 403 禁止。所以我想做的是,我想在使用 boto3 复制文件之前检查我用来复制文件的访问密钥是否具有对这些存储桶的权限。 Is there are anyway to do this?有没有办法做到这一点?

If you are copying objects between Amazon S3 buckets that belong to different AWS accounts, then you will need to use a single set of credentials that have:如果您在属于不同 AWS 账户的 Amazon S3 存储桶之间复制对象,那么您将需要使用一组凭证,这些凭证具有:

  • GetObject permission on the source bucket GetObject对源存储桶的权限
  • PutObject permission on the destination bucket目标存储桶的PutObject权限

Also, the CopyObject command should be sent to the destination bucket to avoid problems with object ownership.此外, CopyObject命令发送到destination bucket以避免 object 所有权问题。

Therefore, I would recommend:因此,我建议:

  • Use credentials from the destination account ( dest-IAM-user )使用来自目标账户 ( dest-IAM-user ) 的凭证
  • Add a bucket policy to the source bucket that permits GetObject access by dest-IAM-user存储桶策略添加到允许dest-IAM-user访问GetObject源存储桶

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM