'Athena queries between tables in different accounts

I can individually access two different Athena tables using two different IAM roles because each lie in different accounts.

Is there a way to run a single query that pulls from both (ie. INNER JOIN)?



Solution 1:[1]

Under the hood, Athena table data is in S3 bucket.

Athena supports cross-account S3 bucket access.

Assume you've Account A & B and Athena table TableA and TableB respectively.

Steps to run query from AccountA Athena (access cross-account data):

  1. Provide AccountA IAM Role read access on AccountB S3 bucket Policy (where TableB data resides).

  2. Create TableB in AccountA Athena, referring to S3 bucket data in AccountB.

  3. Use TableA & and TableB in AccountA and do Inner join

Ref (cross-account access): https://aws.amazon.com/athena/faqs/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ash