1 Answer
- Newest
- Most votes
- Most comments
0
The issue you're facing is likely due to the resource policy you've set up for AWS Glue. In your policy, you're allowing access to databases with the prefix "glue*". However, the GetDatabasesRequest without any additional parameters will return all databases within the AWS account.
To get the list of databases with the prefix "glue*", you need to add a filter to the GetDatabasesRequest. Here's how you can modify your code:
try { // Create the request GetDatabasesRequest request = new GetDatabasesRequest(); request.withResourceShareType("ALL"); // Add this line to get databases across all resource shares // Add a prefix filter for "glue*" request.setCatalogId("<your_aws_account_id>"); // Replace with your AWS account ID request.withResourceShareType("ALL"); // Add this line to get databases across all resource shares request.setDatabaseNamePrefix("glue"); // Set the prefix filter // Get the list of databases GetDatabasesResult response = amazonGlueClient.getDatabases(request); // Process the response List<Database> databases = response.getDatabaseList(); if (databases.isEmpty()) { System.out.println("No databases found matching the prefix 'glue*'."); } for (Database database : databases) { System.out.println("Database name: " + database.getName()); } } catch (AWSGlueException e) { System.err.println("Error occurred while retrieving databases: " + e.getErrorMessage()); e.printStackTrace(); }
In the modified code:
- We set the
CatalogIdto your AWS account ID, which is required for the prefix filter to work correctly. - We add the
withResourceShareType("ALL")parameter to get databases across all resource shares. - We set the
DatabaseNamePrefixto "glue" to filter the databases based on the prefix.
With these changes, you should be able to retrieve the list of databases starting with "glue*" based on the resource policy you've set up.
Note: Make sure to replace <your_aws_account_id> with your actual AWS account ID.

Hi @Giovanni Lauria, setDatabaseNamePrefix is not an API call in SDK V1.x. I am restricted to using this SDK as of now in my organization. Besides, if the policy is restricting to selected databases, then wouldn't getDatabases give out only those databases ?