Amazon Redshift, DynamoDB, Aurora PostgreSQL, and RDS for Oracle
When you connect these databases to AWS Context, agents can find their tables through metadata from AWS Glue Data Catalog and query the data in them through AWS Glue connections that you create.
-
Metadata – AWS Glue sends the databases' metadata to AWS Context by using the connection’s ingestion role. AWS Context doesn’t connect to the database to collect metadata.
-
Queries – To read a database’s data at retrieval time, AWS Context queries the database through an AWS Glue connection that you create for it. Your data stays in your databases. AWS Context doesn’t copy or move it, so every query runs against the current data where it’s stored.
-
AWS Glue connections – An AWS Glue connection is different from an AWS Context connection. The AWS Glue connection holds the network and authentication details for one database. The AWS Context connection points at the catalog and links each database in its scope to that database’s AWS Glue connection. You don’t need a separate AWS Context connection for each database.
Agents can query the following databases:
-
Amazon Redshift provisioned clusters and Amazon Redshift Serverless workgroups
-
Amazon DynamoDB tables
-
Amazon Aurora PostgreSQL-Compatible Edition clusters
-
Amazon RDS for Oracle DB instances
For Amazon RDS for PostgreSQL, Amazon RDS for MySQL, Amazon RDS for MariaDB, and Amazon RDS for SQL Server, AWS Context ingests metadata only and agents can’t query their data. For more information, see Other AWS services.
After you create the connection, add it to one or more Agent Contexts. For more information, see Create a data mapping.
Prerequisites
-
AWS Glue sends metadata to AWS Context only for an account that has turned on auto-discovery in AWS Glue. The same prerequisite applies to these databases. For more information, see the prerequisites in AWS Glue tables and S3 tables.
To connect these databases, complete the following steps. Steps 1–5 set up resources outside AWS Context. Step 6 creates the AWS Context connection. Each step notes where Amazon DynamoDB differs.
Step 1: Choose how AWS Glue authenticates to the database
Amazon DynamoDB: Not required. A DynamoDB AWS Glue connection uses IAM authentication.
Choose how AWS Glue authenticates to the database. The following table compares IAM authentication and basic authentication.
| Setting | IAM authentication | Basic authentication (AWS Secrets Manager) |
|---|---|---|
|
Engines |
Amazon Redshift, Aurora PostgreSQL |
Amazon Redshift, Aurora PostgreSQL, RDS for Oracle |
|
AWS Glue connection |
No secret. |
A |
|
Additional VPC endpoint (no NAT gateway) |
|
|
|
Database setup |
For Amazon Redshift, grants to the role’s database user. For Aurora PostgreSQL, a database user with the |
Grants to the database user in the secret. |
Step 2: Set up the network and VPC endpoints
Amazon DynamoDB: Not required. A DynamoDB AWS Glue connection needs no VPC.
Set up the security groups as follows:
-
The security group of the AWS Glue connection must have an inbound rule that allows TCP traffic on port 443 from itself.
-
The database’s security group must allow inbound traffic on the database port from the AWS Glue connection’s security group. Refer to the security group by ID instead of a CIDR range. Don’t open the database port to
0.0.0.0/0.
The AWS Glue connection runs in its subnet and doesn’t receive a public IP address, so it can’t use an internet gateway. If the subnet has no route to a NAT gateway, create the following VPC endpoints (AWS PrivateLink) in the database’s VPC.
| Service name | Endpoint type | When |
|---|---|---|
|
|
Interface |
Always |
|
|
Interface |
Always |
|
|
Interface |
Always |
|
|
Interface |
Always |
|
|
Gateway |
Always |
|
|
Interface |
Amazon Redshift provisioned cluster with IAM authentication |
|
|
Interface |
Amazon Redshift Serverless with IAM authentication |
|
|
Interface |
Basic authentication |
Aurora PostgreSQL with IAM authentication needs no extra VPC endpoint, because the authentication token is generated locally without an API call. The AWS KMS endpoint in the always-required list is still required.
The following example creates the AWS KMS endpoint. Create the other interface endpoints the same way. For the Amazon S3 endpoint, use --vpc-endpoint-type Gateway and --route-table-ids with the route table of the connection’s subnet.
aws ec2 create-vpc-endpoint --region region \ --vpc-id vpc-0abcd1234example \ --vpc-endpoint-type Interface \ --service-name com.amazonaws.region.kms \ --subnet-ids subnet-0abcd1234example \ --security-group-ids sg-0abcd1234example \ --private-dns-enabled
Replace region and the example VPC, subnet, and security group IDs with your own values.
When you create the endpoints, consider the following:
-
The endpoint’s security group must allow inbound TCP traffic on port 443 from the AWS Glue connection’s security group. You can reuse the connection’s security group, because it allows traffic from itself. Don’t open port 443 to
0.0.0.0/0. -
Turn on
enableDnsSupportandenableDnsHostnamesfor the VPC before you create the endpoints. Otherwise--private-dns-enabledfails. -
Private DNS applies to the whole VPC: every call to the service from the VPC goes through the endpoint. Make sure that other workloads in the VPC that call the service use a security group that the endpoint allows.
Step 3: Set up the IAM roles
Set up the following roles:
-
The IAM role for the AWS Glue connection – AWS Glue uses this role for the AWS Glue connection that you create in Step 4.
-
The ingestion role – AWS Glue assumes this role to send catalog metadata to AWS Context. For the trust policy and the permissions policy, see Ingestion role. When you create the connection in the console, the console can create the ingestion role for you.
-
The data access role (optional) – AWS Context assumes this role to query the data. If you omit the data access role, AWS Context queries the data with the caller’s own credentials, so callers reach only what their own IAM permissions allow. The AWS Context console can’t create a data access role for these databases. Create it yourself, or use caller credentials.
The IAM role for the AWS Glue connection
ROLE_ARN names the IAM role for the AWS Glue connection. The role’s trust policy must allow glue.amazonaws.com to assume it. Its permissions policy must allow ec2:CreateNetworkInterface, ec2:DeleteNetworkInterface, ec2:DescribeNetworkInterfaces, ec2:DescribeSubnets, ec2:DescribeSecurityGroups, ec2:DescribeVpcs, and ec2:CreateTags. For basic authentication, also allow secretsmanager:GetSecretValue on the secret, and kms:Decrypt on the secret’s customer managed key.
The data access role
The data access role is optional. If you specify it, AWS Context assumes the role to read the catalog and to query the database, for every caller. If you omit the data access role, AWS Context queries the database with the caller’s own credentials, and the caller needs the following permissions instead. Start with the trust policy in Permissions for AWS Glue tables and Amazon S3 Tables. Then add the following statements to the role’s permissions policy.
{ "Sid": "UseGlueManagedConnector", "Effect": "Allow", "Action": "glue:ManagedConnector", "Resource": "*" }, { "Sid": "ValidateGlueConnection", "Effect": "Allow", "Action": "glue:GetConnection", "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:connection/redshift-sales" ] }
Replace the Region us-east-1, the account ID 111122223333, and the connection name redshift-sales with your own values.
glue:GetConnection needs both the catalog ARN and each connection ARN. Add one connection ARN for each AWS Glue connection that the role uses. glue:ManagedConnector doesn’t support resource-level permissions, so specify "*".
Then add the statement for your engine and authentication type:
-
Amazon Redshift provisioned cluster with IAM authentication – Allow the role to get temporary database credentials:
{ "Sid": "RedshiftIamAuthentication", "Effect": "Allow", "Action": "redshift:GetClusterCredentialsWithIAM", "Resource": "arn:aws:redshift:us-east-1:111122223333:dbname:examplecluster/dev" }Replace the Region
us-east-1, the account ID111122223333, the cluster nameexamplecluster, and the database namedevwith your own values. -
Amazon Redshift Serverless with IAM authentication – Allow the role to get temporary database credentials for the workgroup. The role also needs access to the database named in the AWS Glue connection.
{ "Sid": "RedshiftServerlessIamAuthentication", "Effect": "Allow", "Action": "redshift-serverless:GetCredentials", "Resource": "arn:aws:redshift-serverless:us-east-1:111122223333:workgroup/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" }Replace the Region
us-east-1, the account ID111122223333, and the workgroup IDa1b2c3d4-5678-90ab-cdef-EXAMPLE22222with your own values. -
Aurora PostgreSQL with IAM authentication – Allow the role to connect as the database user:
{ "Sid": "PostgreSqlIamAuthentication", "Effect": "Allow", "Action": "rds-db:connect", "Resource": "arn:aws:rds-db:us-east-1:111122223333:dbuser:cluster-ABCDEFGHIJKL01234/context_reader" }Replace the Region
us-east-1, the account ID111122223333, the cluster resource IDcluster-ABCDEFGHIJKL01234, and the database user namecontext_readerwith your own values. The resource ID in the ARN isn’t the cluster name. To get it, runaws rds describe-db-clusters --db-cluster-identifier.example-cluster--query 'DBClusters[0].DbClusterResourceId' -
Basic authentication – Allow
secretsmanager:GetSecretValueon the secret, andkms:Decrypton the key if the secret is encrypted with a customer managed key.
Amazon DynamoDB data access role
The data access role is optional for DynamoDB. If you specify it, AWS Context assumes the role to query the tables, for every caller. If you omit it, AWS Context queries the tables with the caller’s own credentials, and the caller needs the following permissions instead. Use the trust policy in Permissions for AWS Glue tables and Amazon S3 Tables. Add the common UseGlueManagedConnector and ValidateGlueConnection statements from Step 3: Set up the IAM roles, and then the following statements.
{ "Sid": "QueryDynamoDBTables", "Effect": "Allow", "Action": [ "dynamodb:DescribeTable", "dynamodb:GetItem", "dynamodb:BatchGetItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:PartiQLSelect" ], "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/orders" }, { "Sid": "ListDynamoDBTables", "Effect": "Allow", "Action": "dynamodb:ListTables", "Resource": "*" }
Replace the Region us-east-1, the account ID 111122223333, and the table name orders with your own values. Add one table ARN to the QueryDynamoDBTables statement for each table that AWS Context queries.
Step 4: Create the AWS Glue connections
Amazon DynamoDB: Different. Create one AWS Glue connection of type DYNAMODB instead. For the settings, see Amazon DynamoDB at the end of this step.
Create one AWS Glue connection for each Amazon Redshift provisioned cluster or Amazon Redshift Serverless workgroup, and one for each Aurora or RDS database. Use the connection type for the engine: REDSHIFT, POSTGRESQL, or ORACLE. AWS Context rejects a connection whose type is JDBC. Set HOST to the cluster, workgroup, or DB instance endpoint, without the port.
The AWS Glue connection must be a unified connection (ConnectionSchemaVersion 2) and must be in the READY state before you use it. For Aurora and RDS, the connection’s DATABASE property must match the rdsDatabase value in the AWS Context connection, including case.
The following example creates a connection to an Amazon Redshift provisioned cluster with IAM authentication.
aws glue create-connection --region region --connection-input '{ "Name": "redshift-sales", "ConnectionType": "REDSHIFT", "ConnectionProperties": { "HOST": "examplecluster.abc123xyz789.region.redshift.amazonaws.com", "PORT": "5439", "DATABASE": "dev", "ENFORCE_SSL": "true", "ROLE_ARN": "arn:aws:iam::111122223333:role/GlueConnectionRole" }, "PhysicalConnectionRequirements": { "SubnetId": "subnet-0abcd1234example", "SecurityGroupIdList": [ "sg-0abcd1234example" ], "AvailabilityZone": "az" }, "AuthenticationConfiguration": { "AuthenticationType": "IAM" } }'
Replace region, the account ID 111122223333, and the example name, endpoint, database, subnet, security group, and Availability Zone with your own values.
AWS Glue sets ConnectionSchemaVersion when it creates the connection. Don’t include it in --connection-input. To confirm that the connection is version 2 and READY, run the following command.
aws glue get-connection --region region --name redshift-sales \ --query 'Connection.[ConnectionSchemaVersion,Status]'
The output must be 2 and "READY".
For other engines, change the following properties.
| Engine and authentication | Changes |
|---|---|
|
Amazon Redshift, basic authentication |
Keep |
|
Aurora PostgreSQL, IAM authentication |
|
|
Aurora PostgreSQL, basic authentication |
|
|
RDS for Oracle, basic authentication |
|
For Aurora PostgreSQL, set HOST to the cluster endpoint (writer, reader, or custom) or an RDS Proxy endpoint. Custom DNS names aren’t accepted. The connector enforces TLS with full certificate verification.
You don’t need to set CATALOG_CASING_FILTER. It defaults to LOWERCASE_ONLY for PostgreSQL and UPPERCASE_ONLY for Oracle, and you can’t change it after you create the AWS Glue connection.
For every property of a connection type, run aws glue describe-connection-type --connection-type POSTGRESQL, or see Connecting to data in the
AWS Glue User Guide.
The ROLE_ARN property names the IAM role for the AWS Glue connection from Step 3.
Amazon DynamoDB
Create the AWS Glue connection first, with the AWS Glue console or API. AWS Context doesn’t create it for you.
Create a unified AWS Glue connection with ConnectionType
DYNAMODB, empty ConnectionProperties ({}), and AuthenticationConfiguration.AuthenticationType
IAM. The connection needs no VPC and no secret. It must be READY, and in the same account and Region as the AWS Context connection. AWS Context doesn’t support a DynamoDB connection across Regions.
Step 5: Set up the database
Amazon DynamoDB: Not required.
Give the database user for AWS Context read access to the schemas that you want AWS Context to read.
These grants determine what AWS Context can read from the database. With basic authentication (AWS Secrets Manager), every AWS Context query reaches the database as the database user in the secret, regardless of which end user asked the question. Grant only the schemas and tables that AWS Context should be able to read.
Amazon Redshift with IAM authentication
For provisioned clusters and Amazon Redshift Serverless, Amazon Redshift creates the database user the first time AWS Context connects. Its name is IAMR: followed by the name of the role that reads the connection, for example IAMR:ContextDataAccessRole for a data access role, and it starts with only PUBLIC privileges. After that first connection, run the following statements as a superuser for each schema.
GRANT USAGE ON SCHEMA sales TO "IAMR:ContextDataAccessRole"; GRANT SELECT ON ALL TABLES IN SCHEMA sales TO "IAMR:ContextDataAccessRole"; ALTER DEFAULT PRIVILEGES IN SCHEMA sales GRANT SELECT ON TABLES TO "IAMR:ContextDataAccessRole";
Replace the schema name sales and the role name ContextDataAccessRole with your own values. Keep the double quotes around the user name, because it contains a colon.
Instead of granting privileges to the user, you can tag the role that reads the connection, the data access role or the caller’s role, with RedshiftDbRoles so that Amazon Redshift maps the user to database roles when it signs in. For Amazon Redshift Serverless, see Defining database roles to grant to federated users in Amazon Redshift Serverless in the Amazon Redshift Management Guide.
Aurora PostgreSQL with IAM authentication
First, turn on IAM database authentication on the cluster.
aws rds modify-db-cluster --db-cluster-identifier example-cluster \ --enable-iam-database-authentication --apply-immediately
Replace the cluster identifier example-cluster with your own value.
Then, as the database’s admin user, create the database user and grant it the rds_iam role. The user has no password.
CREATE USER context_reader; GRANT rds_iam TO context_reader;
Instead of CREATE USER, you can run CREATE ROLE context_reader LOGIN;. Then grant the user read access to each schema.
GRANT USAGE ON SCHEMA public TO context_reader; GRANT SELECT ON ALL TABLES IN SCHEMA public TO context_reader; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO context_reader;
Replace the schema name public and the user name context_reader with your own values.
Basic authentication (Amazon Redshift and Aurora PostgreSQL)
For basic authentication, AWS Context signs in as the user in your secret. Grant that user read access to each schema.
GRANT USAGE ON SCHEMA public TO context_reader; GRANT SELECT ON ALL TABLES IN SCHEMA public TO context_reader; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO context_reader;
Replace the schema name public and the user name context_reader with your own values. In both Amazon Redshift and Aurora PostgreSQL, ALTER DEFAULT PRIVILEGES applies only to tables created later by the user who runs it. If another user creates tables in the schema, add FOR USER with the name of that user.
RDS for Oracle
Grant the user in your secret SELECT on the tables that AWS Context should read.
Step 6: Create the AWS Context connection
Amazon DynamoDB: Different. The connection’s data source is the DynamoDB AWS Glue connection, and DynamoDB needs a connection of its own. For details, see Amazon DynamoDB at the end of this step.
AWS Context has no separate connection type for Amazon Redshift, Amazon Aurora, or Amazon RDS. You connect these databases with a connection whose dataSource.type is GLUE_DATA_CATALOG.
To create the connection (console)
-
Open the AWS Context console.
-
In the navigation pane, choose Connections.
-
Choose Create connection.
-
On the Choose a data source page, choose Amazon Redshift, Aurora and RDS, or Amazon DynamoDB, and then choose Next.
-
On the Configure connection page, for Connection name, enter a name.
-
Under Data scope, for Data source location, choose This AWS account.
-
Under Available data, select the data to include:
-
For Amazon Redshift, expand Namespaces, and then select namespaces, databases, or schemas.
-
For Aurora and RDS, expand the DB instances or DB clusters, and then select databases or schemas.
-
For Amazon DynamoDB, select Amazon DynamoDB to include all of its tables, including tables that are added later.
-
-
(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, under IAM permissions, for Ingestion role, choose Create and use a new service role and enter a Service role name, or choose Use an existing service role.
-
Under Data access, choose Use caller credentials (recommended) or Use a data access role. If you choose a data access role, choose an existing role.
-
In the table, for each resource, choose its AWS Glue connection. The list shows only AWS Glue connections that are
READYand unified. For Aurora and RDS, the AWS Glue connection is optional; a database without one is ingested as metadata only. If you create an AWS Glue connection while the wizard is open, choose the reload button to refresh the list. Create AWS Glue connection opens the AWS Glue console; the AWS Context console doesn’t create AWS Glue connections. -
Choose Next.
-
On the Review and create page, review your choices, and then choose Create connection.
To create the connection (API)
Create a GLUE_DATA_CATALOG connection with your account’s AWS Glue Data Catalog ARN as dataSource. In scope, select the databases to ingest. In glueConnectionMappings, link each one to its AWS Glue connection.
| Engine |
scope path |
glueConnectionMappings path |
|---|---|---|
|
Amazon Redshift |
|
|
|
Aurora and RDS |
|
|
Map every Amazon Redshift resource of a connection the same way, either by [redshiftNamespace] or by [redshiftNamespace, redshiftDatabase]. Each Amazon Redshift namespace or database in scope needs a mapping. When you map by database, AWS Context compares the AWS Glue connection’s DATABASE property with redshiftDatabase case-insensitively. For Amazon Redshift Serverless, the namespace ARN has the form arn:aws:redshift-serverless:.region:111122223333:namespace/namespace-id
For Aurora and RDS, a mapping is optional. A database without a mapping is ingested as metadata only, and agents can’t query its data. An Aurora or RDS mapping uses an AWS Glue connection of type POSTGRESQL for an Aurora PostgreSQL cluster, or of type ORACLE for an RDS for Oracle DB instance.
The following example connects one Amazon Redshift schema and one Aurora PostgreSQL database.
{ "name": "sales-databases", "dataSource": { "type": "GLUE_DATA_CATALOG", "location": { "arn": "arn:aws:glue:region:111122223333:catalog" } }, "scope": { "selectors": [ { "path": [ { "level": "redshiftNamespace", "id": "arn:aws:redshift:region:111122223333:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, { "level": "redshiftDatabase", "id": "dev" }, { "level": "redshiftSchema", "id": "sales" } ] }, { "path": [ { "level": "rdsInstance", "id": "arn:aws:rds:region:111122223333:cluster:example-cluster" }, { "level": "rdsDatabase", "id": "appdb" } ] } ] }, "glueConnectionMappings": [ { "path": [ { "level": "redshiftNamespace", "id": "arn:aws:redshift:region:111122223333:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ], "glueConnectionArn": "arn:aws:glue:region:111122223333:connection/redshift-sales" }, { "path": [ { "level": "rdsInstance", "id": "arn:aws:rds:region:111122223333:cluster:example-cluster" }, { "level": "rdsDatabase", "id": "appdb" } ], "glueConnectionArn": "arn:aws:glue:region:111122223333:connection/aurora-appdb" } ], "accessConfig": { "iamRole": { "roleArn": "arn:aws:iam::111122223333:role/ContextDataAccessRole" } }, "ingestionConfig": { "roleArn": "arn:aws:iam::111122223333:role/ContextIngestionRole" } }
Replace region, the account ID 111122223333, and the example namespace, database, schema, cluster, connection, and role names with your own values.
The example uses a data access role. To read the source with the caller’s credentials instead, omit accessConfig.
Each glueConnectionMappings entry needs its own AWS Glue connection in the same account and Region as the connection. A connection can have at most 20 entries, and AWS Context rejects a duplicate glueConnectionArn.
When CreateConnection succeeds, the connection is ACTIVE, but ingestion runs later and asynchronously:
-
Databases, schemas, tables, and columns arrive after AWS Glue Data Catalog syncs the database’s catalog. It’s expected for an Agent Context to be empty right after you add the connection to it.
-
For an Aurora or RDS database, AWS Context identifies the database engine separately, after the first sync.
-
For an Aurora or RDS database, metadata collection runs on the database itself. To avoid affecting your workload, collection runs only when the database has enough spare capacity: idle CPU and memory, CPU credits on burstable instances, and, for Aurora Serverless v2, a maximum capacity at least 4 Aurora capacity units (ACUs) above the minimum capacity. For the same reason, changes to schema and table metadata can take up to 24 hours to arrive.
Amazon DynamoDB
You don’t map a DynamoDB table through glueConnectionMappings. Instead, the AWS Context connection points directly at an AWS Glue connection of type DYNAMODB. Set dataSource.type to GLUE_DATA_CATALOG and dataSource.location.arn to the AWS Glue connection ARN, arn:aws:glue:.region:111122223333:connection/connection-name
A connection whose data source is a DynamoDB AWS Glue connection accepts only DynamoDB selectors. To include every table, use a selector whose path is [ { "level": "glueService", "id": "DYNAMODB" } ]. To include one table, add a dynamoDbTable segment whose id is the table ARN.
"selectors": [ { "path": [ { "level": "glueService", "id": "DYNAMODB" }, { "level": "dynamoDbTable", "id": "arn:aws:dynamodb:region:111122223333:table/orders" } ] } ]
Replace the Region region, the account ID 111122223333, and the table name orders with your own values. AWS Context rejects a DynamoDB selector on a connection whose data source is a catalog ARN.
In the AWS Context console, if no DynamoDB AWS Glue connection exists in the Region, the console tells you to create one and reload the list.
Query behavior for Amazon DynamoDB
A DynamoDB query returns at most 50 rows. AWS Context runs a DynamoDB Query only when the query filters the partition key with =. Any other filter reads the whole table with a Scan. Filter on the partition key where you can.