Register a Data Catalog from another account
You can use Athena's cross-account Amazon Glue catalog feature to register an Amazon Glue catalog from
an account other than your own. After you configure the required IAM permissions for Amazon Glue
and register the catalog as an Athena DataCatalog
resource, you can use Athena to
run cross-account queries. For information about configuring the required permissions, see
Configure cross-account
access to Amazon Glue data catalogs.
The following procedure shows you how to use the Athena to configure an Amazon Glue Data Catalog in an Amazon Web Services account other than your own as a data source.
Register from console
-
Follow the steps in Configure cross-account access to Amazon Glue data catalogs to ensure that you have permissions to query the data catalog in the other account.
Open the Athena console at https://console.amazonaws.cn/athena/
. If the console navigation pane is not visible, choose the expansion menu on the left.
-
Choose Data sources and catalogs.
-
On the upper right, choose Create data source.
-
On the Choose a data source page, for Data sources, choose S3 - Amazon Glue Data Catalog, and then choose Next.
-
On the Enter data source details page, in the Amazon Glue Data Catalog section, for Choose an Amazon Glue Data Catalog, choose Amazon Glue Data Catalog in another account.
-
For Data source details, enter the following information:
-
Data source name – Enter the name that you want to use in your SQL queries to refer to the data catalog in the other account.
-
Description – (Optional) Enter a description of the data catalog in the other account.
-
Catalog ID – Enter the 12-digit Amazon Web Services account ID of the account to which the data catalog belongs. The Amazon Web Services account ID is the catalog ID.
-
-
(Optional) For Tags, enter key-value pairs that you want to associate with the data source. For more information about tags, see Tag Athena resources.
-
Choose Next.
-
On the Review and create page, review the information that you provided, and then choose Create data source. The Data source details page lists the databases and tags for the data catalog that you registered.
-
Choose Data sources and catalogs. The data catalog that you registered is listed in the Data source name column.
-
To view or edit information about the data catalog, choose the catalog, and then choose Actions, Edit.
-
To delete the new data catalog, choose the catalog, and then choose Actions, Delete.
Register using API operations
-
The following
CreateDataCatalog
request body registers an Amazon Glue catalog for cross-account access:# Example CreateDataCatalog request to register a cross-account Glue catalog: { "Description": "
Cross-account Glue catalog
", "Name": "ownerCatalog
", "Parameters": {"catalog-id" : "<catalogid>
" # Owner's account ID }, "Type": "GLUE" } -
The following sample code uses a Java client to create the
DataCatalog
object.# Sample code to create the DataCatalog through Java client CreateDataCatalogRequest request = new CreateDataCatalogRequest() .withName("
ownerCatalog
") .withType(DataCatalogType.GLUE) .withParameters(ImmutableMap.of("catalog-id", "<catalogid>
")); athenaClient.createDataCatalog(request);After these steps, the borrower should see
when it calls the ListDataCatalogs API operation.ownerCatalog
Register using Amazon CLI
Use the followig example CLI command to register an Amazon Glue Data Catalog from another account
aws athena create-data-catalog \ --name cross_account_catalog \ --type GLUE \ --description "
Cross Account Catalog
" \ --parameters catalog-id=<catalogid>
For more information, see Query
cross-account Amazon Glue Data Catalogs using Amazon Athena