Mulai menggunakan integrasi nol-ETL Aurora dengan Amazon Redshift - Amazon Aurora

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Mulai menggunakan integrasi nol-ETL Aurora dengan Amazon Redshift

Sebelum Anda membuat integrasi nol-ETL dengan Amazon Redshift, konfigurasikan DB dan gudang data Amazon Redshift Anda dengan parameter dan izin yang diperlukan. Selama pengaturan, Anda akan menyelesaikan langkah-langkah berikut:

Setelah Anda menyelesaikan tugas-tugas ini, lanjutkan ke Membuat integrasi nol-ETL Aurora dengan Amazon Redshift.

Anda dapat menggunakan AWS SDKs untuk mengotomatiskan proses penyiapan untuk Anda. Untuk informasi selengkapnya, lihat Siapkan integrasi menggunakan AWS SDKs.

Tip

Anda dapat meminta RDS menyelesaikan langkah-langkah pengaturan ini untuk Anda saat Anda membuat integrasi, daripada melakukannya secara manual. Untuk segera mulai membuat integrasi, lihatMembuat integrasi nol-ETL Aurora dengan Amazon Redshift.

Langkah 1: Buat grup parameter klaster DB kustom

Integrasi nol-ETL Aurora dengan Amazon Redshift memerlukan nilai spesifik untuk parameter klaster DB yang mengontrol replikasi. Secara khusus, Aurora MySQL memerlukan binlog yang ditingkatkan (aurora_enhanced_binlog), dan Aurora PostgreSQL memerlukan replikasi logis yang ditingkatkan (aurora.enhanced_logical_replication).

Untuk mengonfigurasi pencatatan log biner atau replikasi logis, Anda harus membuat grup parameter klaster DB kustom terlebih dahulu, lalu mengaitkannya dengan klaster DB sumber.

Aurora MySQL (rangkaian aurora-mysql8.0):

  • aurora_enhanced_binlog=1

  • binlog_backup=0

  • binlog_format=ROW

  • binlog_replication_globaldb=0

  • binlog_row_image=full

  • binlog_row_metadata=full

Selain itu, pastikan bahwa parameter binlog_transaction_compression tidak ditetapkan ke ON, dan bahwa parameter binlog_row_value_options tidak diatur ke PARTIAL_JSON.

Untuk informasi selengkapnya tentang binlog yang ditingkatkan Aurora MySQL, lihat Menyiapkan binlog yang disempurnakan untuk Aurora MySQL.

Aurora PostgreSQL (keluarga aurora-postgresql16):

  • rds.logical_replication=1

  • aurora.enhanced_logical_replication=1

  • aurora.logical_replication_backup=0

  • aurora.logical_replication_globaldb=0

Mengaktifkan replikasi logis yang disempurnakan (aurora.enhanced_logical_replication) akan selalu menulis semua nilai kolom ke log tulis depan (WAL) meskipun REPLICA IDENTITY FULL tidak diaktifkan. Ini mungkin meningkatkan IOPS untuk cluster DB sumber Anda.

penting

Jika Anda menonaktifkan parameter cluster aurora.enhanced_logical_replication DB setelah integrasi dibuat, instans DB utama membatalkan semua slot replikasi logis. Ini menghentikan replikasi dari sumber ke target, dan Anda harus membuat ulang slot replikasi pada instance DB utama. Untuk mencegah interupsi, pertahankan parameter secara konsisten diaktifkan selama replikasi.

Langkah 2: Pilih atau buat cluster DB sumber

Setelah Anda membuat grup parameter cluster DB kustom, pilih atau buat Aurora DB cluster. Cluster ini akan menjadi sumber replikasi data ke Amazon Redshift. Anda dapat menentukan cluster DB yang menggunakan instans DB yang disediakan atau Aurora Serverless v2 Instans DB sebagai sumbernya. Untuk instruksi untuk membuat cluster , lihat Membuat klaster DB Amazon Auroraatau. Membuat cluster DB yang menggunakan Aurora Serverless v2

Database harus menjalankan versi mesin DB yang didukung. Untuk daftar versi yang didukung, lihat Daerah yang Didukung dan engine Aurora DB untuk ETL integrasi nol dengan Amazon Redshift.

Saat Anda membuat database, di bawah Konfigurasi tambahan, ubah grup parameter cluster DB default ke grup parameter kustom yang Anda buat di langkah sebelumnya.

catatan

Jika Anda mengaitkan grup parameter dengan cluster DB setelah cluster sudah dibuat, Anda harus me-reboot instance DB utama di cluster untuk menerapkan perubahan sebelum Anda dapat membuat integrasi nol-ETL. Untuk petunjuk, lihat Mem-boot ulang klaster DB Amazon Aurora atau instans DB Amazon Aurora.

Langkah 3: Buat gudang data Amazon Redshift

Setelah membuat cluster DB sumber, Anda harus membuat dan mengonfigurasi gudang data target di Amazon Redshift. Gudang data harus memenuhi persyaratan berikut:

  • Menggunakan tipe RA3 node dengan setidaknya dua node, atau Redshift Serverless.

  • Terenkripsi (jika menggunakan klaster yang disediakan). Untuk informasi selengkapnya, lihat Enkripsi basis data Amazon Redshift.

Untuk petunjuk cara membuat gudang data, lihat Membuat klaster untuk klaster terprovisi, atau Membuat grup kerja dengan ruang nama untuk Redshift Nirserver.

Aktifkan kepekaan huruf besar/kecil di gudang data

Agar integrasi berhasil, parameter kepekaan huruf besar/kecil (enable_case_sensitive_identifier) harus diaktifkan untuk gudang data. Secara default, kepekaan huruf besar/kecil dinonaktifkan di semua klaster terprovisi dan grup kerja Redshift Nirserver.

Untuk mengaktifkan kepekaan huruf besar/kecil, lakukan langkah-langkah berikut bergantung pada jenis gudang data Anda:

  • Klaster terprovisi – Untuk mengaktifkan kepekaan huruf besar/kecil pada klaster terprovisi, buat grup parameter kustom dengan parameter enable_case_sensitive_identifier diaktifkan. Kemudian, hubungkan grup parameter dengan klaster. Untuk petunjuknya, lihat Mengelola grup parameter menggunakan konsol atau Mengonfigurasi nilai parameter menggunakan AWS CLI.

    catatan

    Ingatlah untuk mem-boot ulang klaster setelah Anda mengaitkan grup parameter kustom dengannya.

  • Grup kerja Nirserver – Untuk mengaktifkan kepekaan huruf besar/kecil di grup kerja Redshift Nirserver, Anda harus menggunakan AWS CLI. Konsol Amazon Redshift saat ini tidak mendukung modifikasi nilai parameter Redshift Nirserver. Kirim permintaan update-workgroup berikut:

    aws redshift-serverless update-workgroup \ --workgroup-name target-workgroup \ --config-parameters parameterKey=enable_case_sensitive_identifier,parameterValue=true

    Anda tidak perlu mem-boot ulang grup kerja setelah Anda mengubah nilai parameternya.

Konfigurasikan otorisasi untuk gudang data

Setelah Anda membuat gudang data, Anda harus mengkonfigurasi sumber Aurora DB cluster sebagai sumber integrasi resmi. Untuk petunjuknya, lihat Mengonfigurasi otorisasi untuk gudang data Amazon Redshift Anda.

Siapkan integrasi menggunakan AWS SDKs

Daripada menyiapkan setiap sumber daya secara manual, Anda dapat menjalankan skrip Python berikut untuk menyiapkan sumber daya yang diperlukan secara otomatis. Contoh kode menggunakan AWS SDK for Python (Boto3)untuk membuat sumber Amazon Aurora DB cluster data Amazon Redshift, masing-masing dengan nilai parameter yang diperlukan. Kemudian menunggu database tersedia sebelum membuat integrasi nol-ETL di antara mereka. Anda dapat menerapkan "comment out" pada berbagai fungsi tergantung pada sumber daya yang perlu Anda atur.

Untuk menginstal dependensi yang diperlukan, jalankan perintah berikut:

pip install boto3 pip install time

Dalam skrip, secara opsional, Anda dapat memodifikasi nama grup sumber, target, dan parameter. Fungsi akhir akan membuat integrasi bernama my-integration setelah sumber daya disiapkan.

Aurora MySQL
import boto3 import time # Build the client using the default credential configuration. # You can use the CLI and run 'aws configure' to set access key, secret # key, and default Region. rds = boto3.client('rds') redshift = boto3.client('redshift') sts = boto3.client('sts') source_cluster_name = 'my-source-cluster' # A name for the source cluster source_param_group_name = 'my-source-param-group' # A name for the source parameter group target_cluster_name = 'my-target-cluster' # A name for the target cluster target_param_group_name = 'my-target-param-group' # A name for the target parameter group def create_source_cluster(*args): """Creates a source Aurora MySQL DB cluster""" response = rds.create_db_cluster_parameter_group( DBClusterParameterGroupName=source_param_group_name, DBParameterGroupFamily='aurora-mysql8.0', Description='For Aurora MySQL binary logging' ) print('Created source parameter group: ' + response['DBClusterParameterGroup']['DBClusterParameterGroupName']) response = rds.modify_db_cluster_parameter_group( DBClusterParameterGroupName=source_param_group_name, Parameters=[ { 'ParameterName': 'aurora_enhanced_binlog', 'ParameterValue': '1', 'ApplyMethod': 'pending-reboot' }, { 'ParameterName': 'binlog_backup', 'ParameterValue': '0', 'ApplyMethod': 'pending-reboot' }, { 'ParameterName': 'binlog_format', 'ParameterValue': 'ROW', 'ApplyMethod': 'pending-reboot' }, { 'ParameterName': 'binlog_replication_globaldb', 'ParameterValue': '0', 'ApplyMethod': 'pending-reboot' }, { 'ParameterName': 'binlog_row_image', 'ParameterValue': 'full', 'ApplyMethod': 'pending-reboot' }, { 'ParameterName': 'binlog_row_metadata', 'ParameterValue': 'full', 'ApplyMethod': 'pending-reboot' } ] ) print('Modified source parameter group: ' + response['DBClusterParameterGroupName']) response = rds.create_db_cluster( DBClusterIdentifier=source_cluster_name, DBClusterParameterGroupName=source_param_group_name, Engine='aurora-mysql', EngineVersion='8.0.mysql_aurora.3.05.2', DatabaseName='myauroradb', MasterUsername='username', MasterUserPassword='Password01**' ) print('Creating source cluster: ' + response['DBCluster']['DBClusterIdentifier']) source_arn = (response['DBCluster']['DBClusterArn']) create_target_cluster(target_cluster_name, source_arn, target_param_group_name) response = rds.create_db_instance( DBInstanceClass='db.r6g.2xlarge', DBClusterIdentifier=source_cluster_name, DBInstanceIdentifier=source_cluster_name + '-instance', Engine='aurora-mysql' ) return(response) def create_target_cluster(target_cluster_name, source_arn, target_param_group_name): """Creates a target Redshift cluster""" response = redshift.create_cluster_parameter_group( ParameterGroupName=target_param_group_name, ParameterGroupFamily='redshift-1.0', Description='For Aurora MySQL zero-ETL integrations' ) print('Created target parameter group: ' + response['ClusterParameterGroup']['ParameterGroupName']) response = redshift.modify_cluster_parameter_group( ParameterGroupName=target_param_group_name, Parameters=[ { 'ParameterName': 'enable_case_sensitive_identifier', 'ParameterValue': 'true' } ] ) print('Modified target parameter group: ' + response['ParameterGroupName']) response = redshift.create_cluster( ClusterIdentifier=target_cluster_name, NodeType='ra3.4xlarge', NumberOfNodes=2, Encrypted=True, MasterUsername='username', MasterUserPassword='Password01**', ClusterParameterGroupName=target_param_group_name ) print('Creating target cluster: ' + response['Cluster']['ClusterIdentifier']) # Retrieve the target cluster ARN response = redshift.describe_clusters( ClusterIdentifier=target_cluster_name ) target_arn = response['Clusters'][0]['ClusterNamespaceArn'] # Retrieve the current user's account ID response = sts.get_caller_identity() account_id = response['Account'] # Create a resource policy specifying cluster ARN and account ID response = redshift.put_resource_policy( ResourceArn=target_arn, Policy=''' { \"Version\":\"2012-10-17\", \"Statement\":[ {\"Effect\":\"Allow\", \"Principal\":{ \"Service\":\"redshift.amazonaws.com\" }, \"Action\":[\"redshift:AuthorizeInboundIntegration\"], \"Condition\":{ \"StringEquals\":{ \"aws:SourceArn\":\"%s\"} } }, {\"Effect\":\"Allow\", \"Principal\":{ \"AWS\":\"arn:aws:iam::%s:root\"}, \"Action\":\"redshift:CreateInboundIntegration\"} ] } ''' % (source_arn, account_id) ) return(response) def wait_for_cluster_availability(*args): """Waits for both clusters to be available""" print('Waiting for clusters to be available...') response = rds.describe_db_clusters( DBClusterIdentifier=source_cluster_name ) source_status = response['DBClusters'][0]['Status'] source_arn = response['DBClusters'][0]['DBClusterArn'] response = rds.describe_db_instances( DBInstanceIdentifier=source_cluster_name + '-instance' ) source_instance_status = response['DBInstances'][0]['DBInstanceStatus'] response = redshift.describe_clusters( ClusterIdentifier=target_cluster_name ) target_status = response['Clusters'][0]['ClusterStatus'] target_arn = response['Clusters'][0]['ClusterNamespaceArn'] # Every 60 seconds, check whether the clusters are available. if source_status != 'available' or target_status != 'available' or source_instance_status != 'available': time.sleep(60) response = wait_for_cluster_availability( source_cluster_name, target_cluster_name) else: print('Clusters available. Ready to create zero-ETL integration.') create_integration(source_arn, target_arn) return def create_integration(source_arn, target_arn): """Creates a zero-ETL integration using the source and target clusters""" response = rds.create_integration( SourceArn=source_arn, TargetArn=target_arn, IntegrationName='my-integration' ) print('Creating integration: ' + response['IntegrationName']) def main(): """main function""" create_source_cluster(source_cluster_name, source_param_group_name) wait_for_cluster_availability(source_cluster_name, target_cluster_name) if __name__ == "__main__": main()
Aurora PostgreSQL
import boto3 import time # Build the client using the default credential configuration. # You can use the CLI and run 'aws configure' to set access key, secret # key, and default Region. rds = boto3.client('rds') redshift = boto3.client('redshift') sts = boto3.client('sts') source_cluster_name = 'my-source-cluster' # A name for the source cluster source_param_group_name = 'my-source-param-group' # A name for the source parameter group target_cluster_name = 'my-target-cluster' # A name for the target cluster target_param_group_name = 'my-target-param-group' # A name for the target parameter group def create_source_cluster(*args): """Creates a source Aurora PostgreSQL DB cluster""" response = rds.create_db_cluster_parameter_group( DBClusterParameterGroupName=source_param_group_name, DBParameterGroupFamily='aurora-postgresql16', Description='For Aurora PostgreSQL logical replication' ) print('Created source parameter group: ' + response['DBClusterParameterGroup']['DBClusterParameterGroupName']) response = rds.modify_db_cluster_parameter_group( DBClusterParameterGroupName=source_param_group_name, 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' } ] ) print('Modified source parameter group: ' + response['DBClusterParameterGroupName']) response = rds.create_db_cluster( DBClusterIdentifier=source_cluster_name, DBClusterParameterGroupName=source_param_group_name, Engine='aurora-postgresql', EngineVersion='16.4.aurora-postgresql', DatabaseName='mypostgresdb', MasterUsername='username', MasterUserPassword='Password01**' ) print('Creating source cluster: ' + response['DBCluster']['DBClusterIdentifier']) source_arn = (response['DBCluster']['DBClusterArn']) create_target_cluster(target_cluster_name, source_arn, target_param_group_name) response = rds.create_db_instance( DBInstanceClass='db.r6g.2xlarge', DBClusterIdentifier=source_cluster_name, DBInstanceIdentifier=source_cluster_name + '-instance', Engine='aurora-postgresql' ) return(response) def create_target_cluster(target_cluster_name, source_arn, target_param_group_name): """Creates a target Redshift cluster""" response = redshift.create_cluster_parameter_group( ParameterGroupName=target_param_group_name, ParameterGroupFamily='redshift-1.0', Description='For Aurora PostgreSQL zero-ETL integrations' ) print('Created target parameter group: ' + response['ClusterParameterGroup']['ParameterGroupName']) response = redshift.modify_cluster_parameter_group( ParameterGroupName=target_param_group_name, Parameters=[ { 'ParameterName': 'enable_case_sensitive_identifier', 'ParameterValue': 'true' } ] ) print('Modified target parameter group: ' + response['ParameterGroupName']) response = redshift.create_cluster( ClusterIdentifier=target_cluster_name, NodeType='ra3.4xlarge', NumberOfNodes=2, Encrypted=True, MasterUsername='username', MasterUserPassword='Password01**', ClusterParameterGroupName=target_param_group_name ) print('Creating target cluster: ' + response['Cluster']['ClusterIdentifier']) # Retrieve the target cluster ARN response = redshift.describe_clusters( ClusterIdentifier=target_cluster_name ) target_arn = response['Clusters'][0]['ClusterNamespaceArn'] # Retrieve the current user's account ID response = sts.get_caller_identity() account_id = response['Account'] # Create a resource policy specifying cluster ARN and account ID response = redshift.put_resource_policy( ResourceArn=target_arn, Policy=''' { \"Version\":\"2012-10-17\", \"Statement\":[ {\"Effect\":\"Allow\", \"Principal\":{ \"Service\":\"redshift.amazonaws.com\" }, \"Action\":[\"redshift:AuthorizeInboundIntegration\"], \"Condition\":{ \"StringEquals\":{ \"aws:SourceArn\":\"%s\"} } }, {\"Effect\":\"Allow\", \"Principal\":{ \"AWS\":\"arn:aws:iam::%s:root\"}, \"Action\":\"redshift:CreateInboundIntegration\"} ] } ''' % (source_arn, account_id) ) return(response) def wait_for_cluster_availability(*args): """Waits for both clusters to be available""" print('Waiting for clusters to be available...') response = rds.describe_db_clusters( DBClusterIdentifier=source_cluster_name ) source_status = response['DBClusters'][0]['Status'] source_arn = response['DBClusters'][0]['DBClusterArn'] response = rds.describe_db_instances( DBInstanceIdentifier=source_cluster_name + '-instance' ) source_instance_status = response['DBInstances'][0]['DBInstanceStatus'] response = redshift.describe_clusters( ClusterIdentifier=target_cluster_name ) target_status = response['Clusters'][0]['ClusterStatus'] target_arn = response['Clusters'][0]['ClusterNamespaceArn'] # Every 60 seconds, check whether the clusters are available. if source_status != 'available' or target_status != 'available' or source_instance_status != 'available': time.sleep(60) response = wait_for_cluster_availability( source_cluster_name, target_cluster_name) else: print('Clusters available. Ready to create zero-ETL integration.') create_integration(source_arn, target_arn) return def create_integration(source_arn, target_arn): """Creates a zero-ETL integration using the source and target clusters""" response = rds.create_integration( SourceArn=source_arn, TargetArn=target_arn, IntegrationName='my-integration' ) print('Creating integration: ' + response['IntegrationName']) def main(): """main function""" create_source_cluster(source_cluster_name, source_param_group_name) wait_for_cluster_availability(source_cluster_name, target_cluster_name) if __name__ == "__main__": main()

Langkah selanjutnya

Dengan sumber cluster Aurora DB dan gudang data target Amazon Redshift, Anda sekarang dapat membuat integrasi nol-ETL dan mereplikasi data. Untuk instruksi, lihat Membuat integrasi nol-ETL Aurora dengan Amazon Redshift.