Tutorial: Integration with Amazon S3 Tables
This is preview documentation for the Aurora PostgreSQL integration with Amazon S3
Tables. Before using this capability, review the Betas and Previews terms in
the AWS Service
Terms
In this tutorial, you set up an Aurora PostgreSQL integration with Amazon S3 Tables from start to finish. You create an Aurora DB cluster and an Amazon S3 Tables table bucket, replicate a table from the DB cluster to the table bucket, and query the replicated data.
This tutorial uses the US East (N. Virginia) Region (us-east-1). Configure
the AWS CLI to use this Region. The commands in this tutorial are for a Linux,
macOS, or Unix shell. To avoid charges, delete the
resources that you create when you finish. For more information, see Clean up.
Topics
Prerequisites
Before you begin, make sure that you have the following:
-
An AWS account with permission to create Aurora DB clusters, table buckets, table bucket resource policies, and integrations. You also need permission to create and read the master user secret in AWS Secrets Manager (
secretsmanager:CreateSecret,secretsmanager:TagResource,secretsmanager:GetSecretValue, andkms:DescribeKey). For the permissions that creating an integration requires, see Required permissions. -
The AWS CLI, installed and configured.
-
A virtual private cloud (VPC) with at least two public subnets in different Availability Zones, with DNS hostnames and DNS resolution turned on. You also need a DB subnet group that contains the subnets, and a VPC security group that allows inbound TCP traffic on port 5432 from your IP address. For more information, see Working with a DB cluster in a VPC.
-
The
psqlclient, to connect to the DB cluster. -
Permission to turn on integration with AWS analytics services (
glue:CreateCatalogandglue:PassConnection), and permission to query the replicated tables in Amazon Athena. With AWS Identity and Access Management (IAM) access control, you need AWS Glue Data Catalog read permissions. You also need Amazon S3 Tables read permissions, such ass3tables:GetTableBucket,s3tables:GetNamespace,s3tables:GetTable,s3tables:GetTableMetadataLocation, ands3tables:GetTableData. If you use Lake Formation access control, you need Lake Formation permissions on the catalog and namespace instead. For more information, see Register S3 table bucket catalogs and query Tables from Athena in the Amazon Athena User Guide. -
An Amazon Athena query result location in Amazon S3, or a workgroup that sets one. For more information, see Specify a query result location in the Amazon Athena User Guide.
Step 1: Create a custom DB cluster parameter group
Create a DB cluster parameter group, and then set the following parameters: turn on logical replication
(rds.logical_replication) and enhanced logical replication
(aurora.enhanced_logical_replication), and turn off logical replication
backup (aurora.logical_replication_backup) and Global Database logical
replication (aurora.logical_replication_globaldb). This tutorial uses the
Aurora PostgreSQL 18 family. Use the family that matches your engine version. For more
information about the parameters, see Step 1: Create a custom DB cluster parameter group.
Example
For Linux, macOS, or Unix:
aws rds create-db-cluster-parameter-group \ --db-cluster-parameter-group-name my-s3t-params \ --db-parameter-group-family aurora-postgresql18 \ --description "Parameter group for Aurora PostgreSQL integration with S3 Tables" aws rds modify-db-cluster-parameter-group \ --db-cluster-parameter-group-name my-s3t-params \ --parameters \ "ParameterName=rds.logical_replication,ParameterValue=1,ApplyMethod=pending-reboot" \ "ParameterName=aurora.enhanced_logical_replication,ParameterValue=1,ApplyMethod=pending-reboot" \ "ParameterName=aurora.logical_replication_backup,ParameterValue=0,ApplyMethod=pending-reboot" \ "ParameterName=aurora.logical_replication_globaldb,ParameterValue=0,ApplyMethod=pending-reboot"
The parameters apply on reboot. You confirm them in Step 3.
Step 2: Create the Aurora DB cluster
Create the DB cluster with the parameter group from Step 1, and then add a DB instance to it. The
--manage-master-user-password option makes Aurora generate the master
user password and store it in AWS Secrets Manager. In the create-db-cluster command, use
the DB subnet group and VPC security group from Prerequisites.
Example
For Linux, macOS, or Unix:
aws rds create-db-cluster \ --db-cluster-identifier my-s3t-cluster \ --engine aurora-postgresql \ --engine-version 18.4 \ --master-username pgadmin \ --manage-master-user-password \ --database-name testdb \ --db-subnet-group-namemy-s3t-subnet-group\ --vpc-security-group-idssg-0123456789abcdef0\ --db-cluster-parameter-group-name my-s3t-params aws rds create-db-instance \ --db-instance-identifier my-s3t-instance-1 \ --db-cluster-identifier my-s3t-cluster \ --engine aurora-postgresql \ --db-instance-class db.r6g.large \ --publicly-accessible
The engine version must support the integration. For supported AWS Regions and engine versions, see Aurora PostgreSQL zero-ETL integrations.
The --publicly-accessible option lets you connect to the primary
DB instance with psql from your own machine. Use it only for a short-lived
tutorial cluster. For any other workload, keep the cluster private and connect from
within the VPC.
Wait for the DB instance to become available:
aws rds wait db-instance-available --db-instance-identifier my-s3t-instance-1
Step 3: Reboot and confirm enhanced logical replication
Reboot the primary DB instance, and wait for it to become available. Rebooting makes sure that the parameters are in effect before you continue.
aws rds reboot-db-instance --db-instance-identifier my-s3t-instance-1 aws rds wait db-instance-available --db-instance-identifier my-s3t-instance-1
Connect to the testdb database with psql as
pgadmin. First, get the master user password from Secrets Manager. Get the Amazon
Resource Name (ARN) of the master user secret, and then read the secret. In the second
command, replace secret-arn with the ARN that the first
command returns.
aws rds describe-db-clusters --db-cluster-identifier my-s3t-cluster --query "DBClusters[0].MasterUserSecret.SecretArn" --output text aws secretsmanager get-secret-value --secret-idsecret-arn--query SecretString --output text
The password field in the output is the master user password. For more
information, see Password management with Amazon Aurora and AWS Secrets Manager.
Get the cluster endpoint:
aws rds describe-db-clusters --db-cluster-identifier my-s3t-cluster --query "DBClusters[0].Endpoint" --output text
Connect, and enter the password from Secrets Manager when prompted:
psql --host=cluster-endpoint--port=5432 --username=pgadmin --dbname=testdb
Then confirm that the parameters have the expected values:
SHOW rds.logical_replication; SHOW aurora.enhanced_logical_replication;
Both must return on before you continue. Step 1 set
aurora.logical_replication_backup and
aurora.logical_replication_globaldb to 0 in the parameter
group.
Step 4: Create the target table bucket and resource policy
Create the table bucket:
aws s3tables create-table-bucket --name my-s3t-bucket --region us-east-1
Create a file named s3t-bucket-policy.json that contains the table bucket
resource policy. Use the policy in Creating the table bucket and resource policy, with the following
values:
-
Account ID: your AWS account ID, which this tutorial shows as
111122223333. -
Table bucket:
arn:aws:s3tables:us-east-1:.111122223333:bucket/my-s3t-bucket -
Source DB cluster (
aws:SourceArn):arn:aws:rds:us-east-1:. This is the same ARN that you pass to111122223333:cluster:my-s3t-clustercreate-integrationin Step 7.
Attach the policy to the table bucket:
Example
For Linux, macOS, or Unix:
aws s3tables put-table-bucket-policy \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --resource-policy file://s3t-bucket-policy.json
Confirm the policy:
aws s3tables get-table-bucket-policy --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket
The output contains the policy that you attached.
Step 5: Turn on integration with AWS analytics services
Steps 9, 10, and 11 query the replicated tables with Amazon Athena. Before Athena can read the replicated tables, turn on integration with AWS analytics services for table buckets. This setting applies to all table buckets in your account in the current Region, so you turn it on only once for each account and Region. You can use the Amazon S3 console or the AWS CLI.
For instructions, see Integrating Amazon S3 Tables with AWS analytics services in the Amazon Simple Storage Service User Guide. For more information, see Turning on integration with AWS analytics services.
Step 6: Create a source table
In your psql session from Step 3 (or a new connection to the
testdb database), create a table with a primary key. The integration
replicates only tables that have a primary key. The ssn column holds sample
sensitive data, which the data rules in Step 7 exclude. For more information, see Aurora PostgreSQL table limitations.
CREATE TABLE public.demo_customers ( id INT PRIMARY KEY, name VARCHAR(100), ssn VARCHAR(11), created_at TIMESTAMP DEFAULT now() ); INSERT INTO public.demo_customers (id, name, ssn) VALUES (1, 'first row', '000-00-0001'), (2, 'second row', '000-00-0002'), (3, 'third row', '000-00-0003');
Step 7: Create the integration
Create the integration. The data rules replicate every table in the
testdb database and set the target prefix to demo. The last
rule excludes the ssn column from every table. The rules apply in order, so
the rule that excludes ssn comes after the rule that includes
testdb. For more information, see How the integration applies rules and Excluding sensitive columns.
Example
For Linux, macOS, or Unix:
aws rds create-integration \ --source-arn arn:aws:rds:us-east-1:111122223333:cluster:my-s3t-cluster \ --target-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --integration-name my-s3t-integration \ --data-rules '[{"Database":"*","Schema":"*","Table":"*","Properties":{"TargetPrefix":"demo","ExcludeColumns":["*"]}},{"Database":"testdb","Schema":"*","Table":"*","Properties":{"IncludeColumns":["*"]}},{"Database":"*","Schema":"*","Table":"*","Properties":{"ExcludeColumns":["ssn"]}}]'
The integration has a status of creating while it runs the initial full
sync. For all the options, see Creating an integration with the AWS CLI.
Step 8: Wait for the integration to become active
Check the status of the integration:
Example
For Linux, macOS, or Unix:
aws rds describe-integrations \ --query "Integrations[?IntegrationName=='my-s3t-integration'].[IntegrationName,IntegrationArn,Status]" \ --output table
Run the command until the status is active. For the three-row table in
this tutorial, this takes about 8 to 11 minutes.
To check the status every 60 seconds instead, run the following loop. It ends when the
status is no longer creating.
Example
For Linux, macOS, or Unix:
while [ "$(aws rds describe-integrations \ --query "Integrations[?IntegrationName=='my-s3t-integration'].Status" \ --output text)" = "creating" ]; do sleep 60 done
When the loop ends, run the first command again, and confirm that the status is
active. Note the integration ARN. It ends with the integration ID, and
you use it in Step 11 and in Clean up.
Step 9: Verify the initial full sync
List the namespace and table that the integration created. The namespace is the target prefix and the source database name, joined by an underscore. The table name is the source schema name and the source table name, joined by an underscore.
Example
For Linux, macOS, or Unix:
aws s3tables list-namespaces \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket aws s3tables list-tables \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --namespace demo_testdb
The first command lists the namespace demo_testdb, and also
integrations_metadata, which holds the status table that you query in
Step 11. The second command lists the table public_demo_customers. For how
the names are formed, see Namespace and table names.
In Athena, run the following query:
SELECT count(*) FROM "s3tablescatalog/my-s3t-bucket"."demo_testdb"."public_demo_customers";
The count is 3, the same as the source.
To confirm that the ssn column was not replicated, run the following query
in Athena:
SELECT * FROM "s3tablescatalog/my-s3t-bucket"."demo_testdb"."public_demo_customers" LIMIT 10;
The output has no ssn column. For more ways to query the replicated
tables, see Adding data to a source Aurora DB cluster and querying it in Amazon S3 Tables.
Step 10: Confirm ongoing replication
Insert a row on the source DB cluster:
INSERT INTO public.demo_customers (id, name) VALUES (1001, 'cdc_probe');
After a few minutes, query the target in Athena:
SELECT * FROM "s3tablescatalog/my-s3t-bucket"."demo_testdb"."public_demo_customers" WHERE id = 1001;
The query returns the row that you inserted. Change data capture (CDC) replicated it to the target. If the query returns no rows, wait a few more minutes and run it again.
Step 11: Check the per-table status
Aurora keeps a status table in the integrations_metadata namespace of the
table bucket. The table is named integration_table_status_ followed by the
integration ID, with its hyphens replaced by underscores. In the following query,
replace the integration ID with the one from Step 8.
In Athena, run the following query:
SELECT source_table_name, target_table_name, target_table_current_state, status_reason FROM "s3tablescatalog/my-s3t-bucket"."integrations_metadata"."integration_table_status_5b9f3d2e_1111_2222_3333_444455556666";
Confirm that the target_table_current_state value for
testdb.public.demo_customers is SYNCED. For the columns
and states, see Per-table status.
Clean up
To avoid charges, delete the resources that you created. Delete them in the following order: the integration, the tables, the namespaces, the table bucket, the DB instance, the DB cluster, and the parameter group.
-
Delete the integration. Replace the ARN with the integration ARN from Step 8.
Example
For Linux, macOS, or Unix:
aws rds delete-integration \ --integration-identifier arn:aws:rds:us-east-1:111122223333:integration:5b9f3d2e-1111-2222-3333-444455556666Before you continue, wait for the deletion to finish. To check, run the
describe-integrationscommand from Step 8 until the integration no longer appears in the output. -
Delete the target table and the status table. A table bucket must be empty before you can delete it, so delete each table, and then each namespace.
Example
For Linux, macOS, or Unix:
aws s3tables delete-table \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --namespace demo_testdb \ --name public_demo_customers aws s3tables delete-table \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --namespace integrations_metadata \ --name integration_table_status_5b9f3d2e_1111_2222_3333_444455556666 -
Delete the namespaces.
Example
For Linux, macOS, or Unix:
aws s3tables delete-namespace \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --namespace demo_testdb aws s3tables delete-namespace \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket \ --namespace integrations_metadata -
Run the
list-namespacescommand from Step 9 again. If it lists any other namespace, delete its tables and then the namespace. To find the tables, use thelist-tablescommand from Step 9. Then delete the table bucket.Example
For Linux, macOS, or Unix:
aws s3tables delete-table-bucket \ --table-bucket-arn arn:aws:s3tables:us-east-1:111122223333:bucket/my-s3t-bucket -
Delete the DB instance, and wait for the deletion to finish.
aws rds delete-db-instance --db-instance-identifier my-s3t-instance-1 --skip-final-snapshot aws rds wait db-instance-deleted --db-instance-identifier my-s3t-instance-1 -
Delete the DB cluster, and wait for the deletion to finish. Deleting the DB cluster also deletes the master user secret that Aurora created in Secrets Manager. For more information, see Password management with Amazon Aurora and AWS Secrets Manager.
aws rds delete-db-cluster --db-cluster-identifier my-s3t-cluster --skip-final-snapshot aws rds wait db-cluster-deleted --db-cluster-identifier my-s3t-cluster -
Delete the DB cluster parameter group.
aws rds delete-db-cluster-parameter-group --db-cluster-parameter-group-name my-s3t-params -
If you created an Amazon S3 bucket only for Athena query results, empty it and delete it.
Step 5 turned on integration with AWS analytics services for the Region.
Next steps
To go further, see the following topics: