Snowflake
A Snowflake connection ingests metadata about a Snowflake database into your Agent Contexts. AWS Context reaches Snowflake through an AWS Glue connection. You create the AWS Glue connection in AWS Glue, and the connection in AWS Context refers to it.
Prerequisites
Set up the following before you create a Snowflake connection.
-
An AWS Glue connection of type Snowflake to your Snowflake account, in the same AWS account and Region as the AWS Context connection. The AWS Glue connection must be ready and must have an IAM role. For what that IAM role must allow, see IAM role for the AWS Glue connection.
-
The IAM principal that calls AWS Context
CreateConnectionneedsglue:CreateCatalog. See Permissions for the principal that creates the connection. -
The AWS Glue connection must name the Snowflake database that you select in the scope of the connection.
-
In the AWS Glue connection, set Table depth to 3 (database.schema.table) (connection property
TABLE_DEPTHwith the value3). AWS Glue has no default for this setting, and the AWS Glue console shows it as optional. If it’s missing or set to another value, catalog synchronization fails with the messageSyncConfiguration on SNOWFLAKE connections requires TABLE_DEPTH 3. -
For
ingestionConfig.roleArn, specify the ingestion role, which AWS Glue assumes to send the connection’s metadata to your Agent Contexts. For the role’s trust policy and permissions policy, see Ingestion role. -
A Snowflake connection doesn’t require a data access role.
Ingestion role
A Snowflake connection uses an ingestion role, which AWS Glue assumes to send the connection’s metadata to your Agent Contexts. It is required when you create the connection and on every update. The ingestion role must be in the same AWS account as the connection. The principal that creates or updates the connection needs iam:PassRole for the role, with glue.amazonaws.com as the value of iam:PassedToService if your policy uses that condition key. A Snowflake connection doesn’t use a data access role.
The role’s trust policy must allow the AWS Glue service principal glue.amazonaws.com to assume the role. To limit the role to your account, add the condition key aws:SourceAccount with your account ID. Replace 111122223333 with your account ID.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "glue.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "111122223333" } } } ] }
The role’s permissions policy is the same as for an AWS Glue Data Catalog connection. For the policy, see Permissions for AWS Glue tables and Amazon S3 Tables. That policy includes glue:SendMetadata on your account’s root catalog ARN (arn:aws:glue:), which is required for Snowflake connections too. If the role doesn’t allow region:111122223333:catalogglue:SendMetadata, AWS Glue doesn’t deliver the connection’s metadata to your Agent Contexts and doesn’t report an error. Metadata that AWS Glue skipped isn’t sent again on a later sync, which sends only changes. After you fix the role, delete the connection and create it again so that AWS Glue sends the full catalog. The role needs kms:Decrypt if your Data Catalog is encrypted with a customer managed AWS KMS key, even though the metadata comes from Snowflake. You can use the same ingestion role for AWS Glue Data Catalog, Databricks, and Snowflake connections.
IAM role for the AWS Glue connection
The AWS Glue connection’s IAM role is the role that the AWS Glue managed crawlers run as when they synchronize assets and lineage from the source. AWS Context also uses it to register the AWS Glue connection with AWS Lake Formation if it isn’t registered yet, and grants the role DESCRIBE on the catalog that it creates. You don’t grant AWS Lake Formation permissions to this role yourself.
The role’s trust policy must allow AWS Glue and AWS Lake Formation to assume the role.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "glue.amazonaws.com", "lakeformation.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] }
Give the role the following permissions:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ReadGlueConnection", "Effect": "Allow", "Action": "glue:GetConnection", "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:connection/my-snowflake-glue-connection" ] }, { "Sid": "ReadFederatedCatalog", "Effect": "Allow", "Action": [ "glue:GetCatalog", "glue:GetCatalogs", "glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables" ], "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:catalog/*", "arn:aws:glue:us-east-1:111122223333:database/*", "arn:aws:glue:us-east-1:111122223333:table/*" ] }, { "Sid": "ReadConnectionSecret", "Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:my-snowflake-key-pair-AbCdEf" }, { "Sid": "PublishLineageEvents", "Effect": "Allow", "Action": "glue:PostLineageEvent", "Resource": "*" } ] }
Replace the Region us-east-1, the account ID 111122223333, the connection name my-snowflake-glue-connection, and the secret name my-snowflake-key-pair-AbCdEf with your own values. If the secret is encrypted with a customer managed AWS KMS key, also add kms:Decrypt on the key. glue:PostLineageEvent doesn’t support resource-level permissions, so specify *. Without glue:PostLineageEvent, AWS Glue can’t publish lineage events, so AWS Context doesn’t collect lineage, but asset synchronization still works. The role doesn’t need Amazon S3 permissions.
The principal that creates the AWS Context connection needs permission to register the AWS Glue connection with AWS Lake Formation and to grant permissions on it: lakeformation:DescribeResource, lakeformation:RegisterResource, and lakeformation:GrantPermissions, and iam:PassRole for the AWS Glue connection’s role to lakeformation.amazonaws.com. Without these permissions, CreateConnection is denied.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "RegisterGlueConnectionWithLakeFormation", "Effect": "Allow", "Action": [ "lakeformation:DescribeResource", "lakeformation:RegisterResource", "lakeformation:GrantPermissions" ], "Resource": "*" }, { "Sid": "PassGlueConnectionRole", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::111122223333:role/ContextGlueSourceRole", "Condition": { "StringEquals": { "iam:PassedToService": "lakeformation.amazonaws.com" } } } ] }
Replace the account ID 111122223333 and the role name ContextGlueSourceRole with your own values.
Permissions for the principal that creates the connection
When you publish a Snowflake connection, AWS Context creates a federated catalog in AWS Glue. The IAM principal that calls AWS Context CreateConnection needs glue:CreateCatalog on two resources: the regional root Glue Data Catalog and the new federated catalog. This IAM requirement also applies to AWS Lake Formation data lake administrators. Permissions on the crawler role or the ingestion role do not grant this access to the caller. See CreateCatalog in the Service Authorization Reference.
A AWS Lake Formation data lake administrator in the Glue connection’s account and Region already has the required AWS Lake Formation permissions. For any other caller, ask an authorized grantor to grant these AWS Lake Formation permissions without the grant option:
-
CREATE_CATALOGon the Data Catalog of the Region. In the AWS Lake Formation console, choose Catalog creators, and then choose Grant. -
DATA_LOCATION_ACCESSon the ARN of the registered AWS Glue connection. In the AWS Lake Formation console, choose Permissions, Data locations, and then Grant. Grant this permission for each AWS Glue connection that you plan to use.
If you use explicit AWS Lake Formation grants, verify that the grants name the caller and the resources listed above. For more information, see Prerequisites for connecting the Data Catalog to external data sources in the AWS Lake Formation Developer Guide.
Create a Snowflake connection
A connection that you create in the console or with the API uses an AWS Glue connection that you create. Whether that connection queries data as each end user depends on the AWS Glue connection, not on how you create the AWS Context connection.
Per-user access to data requires Credential Broker settings on the AWS Glue connection. Without them, AWS Context synchronizes metadata but can’t query the source’s data. The AWS Glue console doesn’t support these settings. To add them, create the AWS Glue connection with the AWS CLI or an AWS SDK (AWS Glue CreateConnection). In ConnectionInput.AuthenticationConfiguration, set CredentialBrokerProperties with CredentialProviderArn (the credential provider ARN, in the same account and Region), OAuth2GrantType set to AUTHORIZATION_CODE, and Scopes:
"AuthenticationConfiguration": { "CredentialBrokerProperties": { "CredentialProviderArn": "arn:aws:credentialbroker:region:111122223333:credentialproviderpool/pool-id/credentialprovider/provider-id", "OAuth2GrantType": "AUTHORIZATION_CODE", "Scopes": [ "session:role:ANALYST", "refresh_token" ] } }
Keep the other authentication settings that the connection type needs, which are the credentials that AWS Glue uses to synchronize metadata. Users must authorize again if you change the scopes. For more information, see CreateConnection in the AWS Glue API Reference.
After the AWS Glue connection has these settings, an AWS Context connection that uses it queries data as each end user, whether you create the AWS Context connection in the console or with the API. For more information, see Identity and per-user access.
To create a Snowflake connection (console)
-
Open the AWS Context console.
-
In the navigation pane, choose Connections.
-
Choose Create connection.
-
On the Choose a data source page, choose Snowflake, and then choose Next.
-
On the Configure connection page, for Connection name, keep the generated name or enter a name.
-
Under Data scope, in Available data, choose what to ingest from one database:
-
To ingest the whole database, including schemas that are added later, select the database.
-
To ingest only some schemas, expand the database and select those schemas, or select the database and then clear the schemas that you don’t want. Schemas that are added later aren’t included.
Available data lists the Snowflake databases, and their schemas, that AWS Glue has indexed in the AWS Glue Data Catalog. If no database is indexed, the console shows No Snowflake resources in AWS Glue. To refresh the list, choose the refresh button next to Available data. You can’t choose individual tables.
-
-
(Optional) Add tags to the connection.
To add tags, you need permission for
context:TagResourcein addition tocontext:CreateConnection. Otherwise, AWS Context denies the request and doesn’t create the connection. For more information, see Permissions to create tagged resources. -
Choose Next.
-
On the Set permissions page, for Ingestion access, choose the IAM role that AWS Glue assumes to write metadata to your agent contexts.
-
Under Data access, in the Snowflake row, for AWS Glue connection, choose the AWS Glue connection to that Snowflake database. The list shows only AWS Glue connections whose database is the database that you selected. You can’t choose an AWS Glue connection that isn’t ready or that has no IAM role.
-
If the confirmation check box appears, select it to confirm that the AWS Glue connection reads the Snowflake account that the console shows.
-
Choose Next.
-
On the Review and create page, review your choices, and then choose Create connection.
The console shows a message that the connection was created and opens the Connections page. While AWS Glue sets up catalog synchronization, the connection’s status is Creating. While the Connections page or the connection’s details page is open, the console continues the setup until the status is Active or Failed.
To create a Snowflake connection (API)
To create the connection, call CreateConnection. Set dataSource.type to SNOWFLAKE and dataSource.location.arn to the ARN of the AWS Glue connection. In scope, name one Snowflake database with a snowflakeDatabase segment. To ingest only some of its schemas, add one selector for each schema, with a snowflakeDatabase segment followed by a snowflakeSchema segment. A scope has at most 100 selectors.
The following JSON example shows the request parameters for CreateConnection. Replace region, the account ID 111122223333, and the names with your own values.
{ "name": "snowflake-sales", "dataSource": { "type": "SNOWFLAKE", "location": { "arn": "arn:aws:glue:region:111122223333:connection/my-snowflake-glue-connection" } }, "scope": { "selectors": [ { "path": [ { "level": "snowflakeDatabase", "id": "SALES_DB" } ] } ] }, "ingestionConfig": { "roleArn": "arn:aws:iam::111122223333:role/ContextIngestionRole" } }
To ingest only some schemas, use one selector per schema, for example { "path": [ { "level": "snowflakeDatabase", "id": "SALES_DB" }, { "level": "snowflakeSchema", "id": "PUBLIC" } ] }.
A connection must be ACTIVE before you can add it to an Agent Context. For a Snowflake connection, ACTIVE means that the data source is reachable and that AWS Glue has set up synchronization. It doesn’t mean that a synchronization run has started or finished.
AWS Glue starts the first synchronization shortly after it sets up catalog synchronization, so you don’t wait a day for the first run. After that, AWS Glue synchronizes once a day. The first synchronization of a large catalog can take some time.
If setup doesn’t finish within the request, CreateConnection returns the connection with the status CREATING. subStatus shows the last setup step that was reached, for example, GLUE_CONNECTION_VALIDATED or SYNC_JOB_CREATED. The connection doesn’t continue setup on its own, and GetConnection only reports its status. To continue setup, call UpdateConnection with connectionId and the same ingestionConfig, and with no other changes. If you created the connection with publish set to false, also set publish to true. Wait between calls, and repeat the call until the status is ACTIVE or FAILED. Use the same ingestion role in each call. The console does this for you while the Connections page or the connection’s details page is open.
The status becomes FAILED if AWS Glue can’t validate the AWS Glue connection, if the AWS Glue connection no longer exists or has no IAM role, or if AWS Glue can’t set up catalog synchronization.
If CreateConnection returns an error, call GetConnection or ListConnections to check whether the connection exists. If AWS Context removed the connection, the error message says so; fix the cause, and then call CreateConnection again with a new client token. If the connection still exists with the status CREATING, fix the cause, and then call UpdateConnection as described earlier. If UpdateConnection returns an error, the connection remains; fix the cause, and then call UpdateConnection again.
If the error identifies glue:CreateCatalog and HTTP 403 (access denied), check the caller’s IAM and AWS Lake Formation permissions. See Permissions for the principal that creates the connection.
If the status is FAILED, failure.code identifies why the connection failed, for example GLUE_CONNECTION_UNAVAILABLE. AWS Context might add more codes, so handle a code that you don’t recognize. Use failure.code, not failure.message, to decide how to respond. A FAILED connection can’t be updated. Delete the connection and create it again.
Keeping metadata current
syncSchedule for a Snowflake connection must be DAILY, or omit it (the default is DAILY). AWS Glue requires an interval of at least one day, so a connection with HOURLY fails. AWS Context rejects WEEKLY, MONTHLY, and cron expressions when you publish the connection.
Identity and per-user access
Per-user access queries Snowflake as the end user who sent the request, instead of with the connection’s shared credentials. AWS Glue obtains each user’s token from an AWS IAM Credential Broker credential provider through the OAuth 2.0 authorization code grant. AWS Context doesn’t pass or store a user’s token. Per-user access depends on the following.
-
Per-user access needs a trusted end-user identity on the request: a session from IAM Identity Center with trusted identity propagation, or an IAM federation session (a SAML or OIDC identity provider with trusted identity propagation turned on). For federated users, the
Subjecttype must beuser. A request without a user identity gets no data from the catalog. For setup, see IAM Identity Center for workforce users and SSO federation through corporate IdPs. -
For an IAM Identity Center session that an application creates, the application creates an identity-enhanced role session: it passes the user’s identity context to
AssumeRoleinProvidedContexts, with the context provider ARNarn:aws:iam::aws:contextProvider/IdentityCenter. For more information, see IAM Identity Center for workforce users. -
Per-user access uses an AWS IAM Credential Broker credential provider (OAuth, authorization code grant) in the same AWS account and Region as the connection. You set it on the AWS Glue connection in
CredentialBrokerProperties, as described earlier in this topic. Add the AWS Context console’s session binding URL (the console URL for the Region, followed by/session_binding) to the provider’s allowed session binding URLs. For more information, see AWS IAM Credential Broker, Obtain a token on behalf of a user with the authorization code grant, and Understand session binding in the IAM User Guide. -
In Snowflake, register an OAuth client for the credential provider, with its redirect URL set to the provider’s callback URL, and scopes that include
refresh_tokenfor a refresh token. Add asession:rolescope to set the role that queries use; a role that Snowflake blocks for OAuth, such as ACCOUNTADMIN, can’t be used. For more information, see Configure Snowflake OAuth for custom clientsin the Snowflake documentation. -
Each user signs in once. The first time a request needs this database’s data for a user,
AgenticRetrievereturnsauthorizationRequiredwith a single-use authorization URL. The user signs in to Snowflake there, and Snowflake applies that account’s permissions. AWS Context doesn’t map IAM principals to Snowflake users. For more information, see Snowflake and Databricks: identity mapping. Until a user completes the one-time sign-in, queries for that user return no rows from the source. Only the AWS Glue crawlers use the connection’s stored credentials. An administrator who hasn’t signed in through the authorization URL can’t browse the database’s schemas and tables in AWS Glue or query the source. The Available data list in the AWS Context console isn’t affected. -
The IAM principal of each end user needs
glue:GetConnectionon the AWS Glue connection and on the Data Catalog of the account,glue:ManagedConnectoron*,secretsmanager:GetSecretValueon the AWS Secrets Manager secret that stores the credential provider’s client secret (andkms:Decrypton a customer managed key), andcredentialbroker:GetOAuthToken,credentialbroker:StartOAuthSession,credentialbroker:CompleteOAuthSessionBinding, andcredentialbroker:GetCredentialProvideron the credential provider. For more information, see Control access to AWS IAM Credential Broker in the IAM User Guide.
Semantic views
AWS Context ingests metric definitions from semantic views in Snowflake. AWS Context ingests the definitions only, not metric values or query results.
Semantic views are ingested together with the other metadata of the connection. A connection has no setting that is specific to metric definitions. A semantic view is ingested only if the schema that contains it is within the scope of the connection, because the scope selects databases or schemas and can’t include or exclude an individual view. If you set data filtering when you add the connection to an Agent Context, the view must also be within that selection. Data filtering treats a semantic view as a table: if you filter at the database or schema level, the views in the selected schemas are included, and if you choose individual tables, a view is ingested only if you also choose the view itself. In the API, name the view at the snowflakeTable level of connectionMappings[].pathSegments.
Add the connection to an Agent Context
A connection must be ACTIVE before you can add it to an Agent Context. To ingest only some tables of the database into an Agent Context, use data filtering when you add the connection to that Agent Context. In the API, set connectionMappings[].pathSegments with the levels snowflakeDatabase, snowflakeSchema, and snowflakeTable. For more information, see Filters and scoping a connection. An Agent Context can have at most 20 connection mappings.
Change or delete the connection
To change the name or the scope, call UpdateConnection with connectionId, the member to change, and ingestionConfig. ingestionConfig is required on every update. If the connection’s status doesn’t allow the update, AWS Context rejects the request. Check the status with GetConnection.
You can’t change the scope while an Agent Context uses the connection.
You can’t delete a connection while an Agent Context still uses it.
Considerations
Keep the following in mind for a Snowflake connection.
-
A Snowflake connection covers one Snowflake database.
-
nameis required. It has 3–63 characters, starts with a letter, and contains only letters, digits, and hyphens. -
clientTokenis optional. AWS Context remembers a token for a limited time. For a Snowflake connection, a retry within that time with the same token and an identical request returnsConflictExceptioninstead of the original connection. CallListConnectionsto find the connection. -
publishis optional and defaults totrue. -
If you specify
tags, you also need permission forcontext:TagResource. For more information, see Permissions to create tagged resources. -
An Agent Context can have at most 20 connection mappings.