Amazon Athena 跨账户访问

Amazon Athena Cross Account Access

我可以在我的帐户内的 Athena 服务中创建数据库和 table 以访问另一个帐户中的 S3 数据吗?

我查看了下面的内容 link 并且我假设根据此文档,Amazon Athena 和 S3 存储桶必须在同一个账户中,并且在另一个账户中向用户提供访问权限。

https://console.aws.amazon.com/athena/home?force&region=us-east-1#query

来自Access Control Policies - Amazon Athena

To run queries in Athena, you must have the appropriate permissions for:

  • The Athena actions.
  • The Amazon S3 locations where the underlying data is stored that you are going to query in Athena.
  • ...

因此,执行 Athena 查询的 IAM 用户 似乎需要访问 Amazon S3 位置。

这可以通过向允许 IAM 用户访问存储桶的其他帐户中的 S3 存储桶添加存储桶策略来完成。

为了更好地解释:

  • Account-AIAM-User-A 和 AWS Athena
  • Account-BBucket-B 的存储桶策略授予对 IAM-User-A
  • 的访问权限

此答案涉及以下附加信息:

  • Account-A 中的 Lambda 函数必须能够在 Account-B
  • 中的 Amazon Athena 中创建 table

我还没有测试过,但我想你会需要:

  • Role-A in Account-A 对于 Lambda 函数:
    • 允许 AssumeRole Role-B
  • Role-BAccount-B 中:
    • 允许访问 Amazon Athena 和 Amazon S3 中的源存储桶
    • 信任Role-A

Lambda 函数将 运行 和 Role-A。然后它将使用来自 Role-A 的凭据在 Role-B 上调用 AssumeRole。这将 return 一组新的凭据,可用于在 Account-B 中调用 Amazon Athena。