Athena
PrerequisitesRequires permission to create IAM roles and policies in AWS, or to attach policies to your Monte Carlo agent's role.
Before configuring your Athena query engine, make sure your metastore (e.g., Glue or Hive Metastore) is connected, as Monte Carlo requires it to map query engine activity to data lake assets.
Monte Carlo runs Athena queries with an IAM policy that you control. There are two authentication options:
- IAM assume role (default): you create an IAM role with the Athena policy, and Monte Carlo assumes it. You give Monte Carlo the role ARN and, if you use one, the external ID. This option works with the deployment hosted by Monte Carlo and with the AWS agent, including the proxied AWS agent.
- IAM (agent's role): you attach the same Athena policy to the IAM role your Monte Carlo agent already runs as. There is no role to assume, so you don't enter a role ARN or an external ID. This option is available only when the integration uses an AWS agent, including the proxied AWS agent, and only in the Monte Carlo UI with the AWS Glue & Athena integration. See Using the agent's IAM role.
A generic agent uses neither option: it uses customer-managed credentials, and can still use its own IAM role. See Generic agent: customer-managed credentials.
With either option, you also give Monte Carlo the region and, optionally, the workgroup.
To connect Monte Carlo to Athena for query logs and data health queries with an assumable role:
- If you're using Athena with a Glue metastore, you can configure both together using a shared setup flow in the Monte Carlo UI. Follow the steps outlined in the Glue integration documentation.
- If you're using Athena with other metastores (e.g., Hive), follow these steps:
- Install the CLI, it will be used in the next steps.
- Create a workgroup for Monte Carlo queries.
- Create an IAM role that allows Athena access for Monte Carlo's data collector.
- Provide the role's information to Monte Carlo to validate and complete the integration.
Installing the CLI
Please follow this guide to install and configure the CLI.
Creating a workgroup for Monte Carlo queries
Create a workgroup for Monte Carlo to use to perform queries, see instructions here. An S3 location (bucket and folder) to which query results will be written must be designated. It is recommended that the bucket be in the same region as the catalog that Athena uses.
Creating an IAM role for Athena access
In order to provide access to Athena, you will create an IAM role with the necessary API permissions:
- Create a JSON file on your computer with the following content, replacing the placeholders:
The CLI command
athena-policy-gencan be used auto-generate this policy.
<region>: you can specify the Athena AWS region or*for the default region.<account-id>: the Athena AWS account id.<data-bucket>: the S3 bucket storing the data for your Athena tables - if more than one bucket, just add the others to the resource list as well.<database-name>: you can specify one or more database names or use*to give Monte Carlo access to all Athena databases.<montecarlo-workgroup>: the workgroup created on the previous step.<results-bucket>: the bucket configured for the workgroup.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::<data-bucket>",
"arn:aws:s3:::<results-bucket>"
]
},
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::<data-bucket>/*",
"arn:aws:s3:::<results-bucket>/*"
]
},
{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": [
"arn:aws:s3:::<results-bucket>/*"
]
},
{
"Effect": "Allow",
"Action": [
"athena:StartQueryExecution",
"athena:StopQueryExecution",
"athena:GetQueryResults"
],
"Resource": "arn:aws:athena:<region>:<account-id>:workgroup/<montecarlo-workgroup>"
},
{
"Effect": "Allow",
"Action": "athena:ListWorkGroups",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "athena:ListDatabases",
"Resource": [
"arn:aws:athena:<region>:<account-id>:datacatalog/*"
]
},
{
"Effect": "Allow",
"Action": "glue:GetDatabases",
"Resource": [
"arn:aws:glue:<region>:<account-id>:catalog",
"arn:aws:glue:<region>:<account-id>:database/<database-name>"
]
},
{
"Effect": "Allow",
"Action": [
"athena:GetQueryExecution",
"athena:BatchGetQueryExecution",
"athena:ListQueryExecutions",
"athena:GetWorkGroup"
],
"Resource": [
"arn:aws:athena:<region>:<account-id>:workgroup/*",
"arn:aws:athena:<region>:<account-id>:datacatalog/*"
]
},
{
"Effect": "Allow",
"Action": [
"glue:GetTables",
"glue:GetTable",
"glue:GetPartitions",
"glue:GetPartition"
],
"Resource": [
"arn:aws:glue:<region>:<account-id>:catalog",
"arn:aws:glue:<region>:<account-id>:database/<database-name>",
"arn:aws:glue:<region>:<account-id>:table/<database-name>/*"
]
}
]
}- Please follow the steps outlined here to create an IAM role with the policy from step 1. The role ARN and external ID should be saved to be used in the next step. To use the agent's role instead, skip this step and follow Using the agent's IAM role.
Recommendation - use infrastructure as codeThe CLI command
cf-role-gencan be used to help create a Data Collector compatible IAM role by generating a CloudFormation template with one or more IAM policies.
Providing role information to Monte Carlo
Please use the command montecarlo integrations add-athena to set up Athena connectivity. The CLI supports the IAM assume role option only: add-athena requires --role. To use the agent's role, use the Monte Carlo UI. For reference, see help for this command below:
$ montecarlo integrations add-athena --help
Usage: montecarlo integrations add-athena [OPTIONS]
Setup an Athena integration. For query logs and health queries.
Options:
--catalog TEXT Glue data catalog. If not specified the AwsDataCatalog
is used.
--workgroup TEXT Workbook for running queries and retrieving logs. If
not specified the primary is used.
--region TEXT Athena cluster region. If not specified the region the
collector is deployed in is used.
--name TEXT Friendly name of the warehouse which the connection
will belong to.
--role TEXT Assumable role ARN to use for accessing AWS resources.
[required]
--external-id TEXT An external id, per assumable role conditions.
--collector-id UUID ID for the data collector. To disambiguate accounts
with multiple collectors.
--skip-validation Skip all connection tests. This option cannot be used
with 'validate-only'.
--validate-only Run connection tests without adding. This option cannot
be used with 'skip-validation'.
--auto-yes Skip any interactive approval.
--option-file FILE Read configuration from FILE.
--help Show this message and exit.Using the agent's IAM role
With the IAM (agent's role) option, Monte Carlo runs Athena queries as the IAM role your agent already runs as. You attach the Athena policy to that role, and there is no role for Monte Carlo to assume.
When you can use it
- The integration must use an AWS agent, including the proxied AWS agent.
- A generic agent can't use this option. It uses customer-managed credentials, which can also use the agent's own role.
- You set it up in the Monte Carlo UI, where Athena is added with the AWS Glue & Athena integration. If you use Athena with another metastore, such as Hive, use the IAM assume role option and the CLI.
- A deployment hosted by Monte Carlo can't use the agent's role. It always uses an assumable role.
- The agent's role runs Athena in the agent's own AWS account. If your Athena workgroup and Glue catalog are in another account, use the IAM assume role option.
- Create a workgroup for Monte Carlo queries, if you don't have one.
- Find the agent's role: the Lambda function execution role for the AWS agent, or the role attached to the agent's infrastructure (for example the ECS task role) for the proxied AWS agent. See Find the agent's role.
- Attach the Athena policy to the agent's role, replacing the placeholders. You don't need a trust policy, an external ID, or the
MonteCarloDatatag. - In Monte Carlo, add Athena with the AWS Glue & Athena integration, as described in Use the agent's IAM role on the Glue page, or from the details page of your existing Glue integration. Select the AWS agent deployment, choose IAM (agent's role) for Authentication type, and enter the region, workgroup, data catalog, and results location. You don't enter a role ARN or an external ID.
- Test the connection, then save.
To move an existing Athena connection to the agent's role, edit the connection and change Authentication type.
If the agent reaches AWS through private networking (a VPC without internet access), the agent's VPC needs VPC endpoints with private DNS for Athena (com.amazonaws.<region>.athena), Glue (com.amazonaws.<region>.glue), and S3 (com.amazonaws.<region>.s3). STS (com.amazonaws.<region>.sts) is needed only when a role is assumed (the IAM assume role option, or a role ARN in a customer-managed secret), or when the agent gets its credentials through EKS IRSA; the agent calls the regional STS endpoint. Customer-managed credentials stored in AWS Secrets Manager also need a Secrets Manager endpoint (com.amazonaws.<region>.secretsmanager).
Generic agent: customer-managed credentials
A generic agent can't use the IAM assume role or IAM (agent's role) options, because Monte Carlo doesn't hold credentials for integrations on a generic agent. Instead, you store the connection settings in a secret that the agent reads at runtime, as described in Self-hosted credentials.
The secret decides which role the agent uses:
- No role ARN in the secret: the agent uses its own IAM role. This is the direct option for a generic agent: attach the Athena policy to the agent's role.
- A role ARN (and, if you use one, an external ID) in the secret: the agent assumes that role. Create the role with the Athena policy, and allow the agent's role to assume it.
- Create a workgroup for Monte Carlo queries, if you don't have one.
- Find the generic agent's role, as described in Find the generic agent's role.
- Attach the Athena policy to that role, or to the role named in the secret, replacing the placeholders. If you store the secret in AWS Secrets Manager, the agent's role also needs
secretsmanager:GetSecretValueon the secret, as described in Self-hosted credentials. - Store the connection settings in a secret store the agent supports. It is the same secret as for Glue, described in Store the connection settings:
connect_argswithaws_region, andassumable_roleandexternal_idonly to assume a role. The workgroup and data catalog don't go in the secret. - In Monte Carlo, add Athena with the AWS Glue & Athena integration or from the details page of your existing Glue integration. Select Customer managed credentials and the generic agent deployment, choose the secret store, and enter the secret's reference. Enter the workgroup, data catalog, and results location in the form.
- Test the connection, then save.
Troubleshooting
Access denied for the agent's role
The connection test checks the Athena permissions, so a missing permission fails the test with an AccessDenied that names the action, such as athena:ListDatabases, athena:ListWorkGroups, athena:StartQueryExecution, or glue:GetDatabases. When the agent uses its own role (the IAM (agent's role) option, or customer-managed credentials with no role ARN), an error such as User: arn:aws:sts::123456789012:assumed-role/<agent-role>/<session> is not authorized to perform: athena:StartQueryExecution means the agent's role is missing a permission. Check that:
- The Athena policy is attached to the agent's role. On ECS, attach it to the task role, not the task execution role. For a generic agent on EKS, attach it to the service account's role, not the node role.
- The policy's account ID, region, workgroup, database names, data buckets, and results bucket match your resources.
- No resource policy, permission boundary, or service control policy denies access.
The test fails right after you change IAM policies or create VPC endpoints
AWS takes a short time to apply these changes: usually seconds for an IAM policy, and a few minutes for a new VPC endpoint. A test run in that window can fail with an access or connection error. Wait, then run the test again.
IAM (agent's role) is not available for this deployment
The IAM (agent's role) option works only with an AWS agent, including the proxied AWS agent. It is not available on the deployment hosted by Monte Carlo or on a generic agent.
- Deployment hosted by Monte Carlo: use the IAM assume role option.
- Generic agent: use customer-managed credentials. With no role ARN in the secret, the agent uses its own IAM role.
FAQ
Why don't some of my Athena tables have freshness?
Monte Carlo works out when a Glue table's data was updated from Athena's query logs, or from S3 event notifications if you've set them up. Glue's own update time only changes when the table's schema changes, so it isn't used. Tables loaded by something other than Athena, such as Glue jobs, have no Athena write queries, so they get no freshness unless S3 event notifications are set up. To track volume on them instead, turn on row count monitoring for those tables.
Updated about 17 hours ago
