AWS CloudFormationuntuk AWS Glue - AWS Glue

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

AWS CloudFormationuntuk AWS Glue

AWS CloudFormation adalah layanan yang dapat membuat banyak sumber daya AWS. AWS Glue menyediakan operasi API untuk membuat objek di AWS Glue Data Catalog. Namun demikian, mungkin lebih mudah untuk menentukan dan membuat objek AWS Glue dan sumber daya terkait AWS lainnya dalam sebuah file templat AWS CloudFormation. Kemudian Anda bisa mengotomatisasi proses pembuatan objeknya.

AWS CloudFormationmenyediakan sintaks yang disederhanakan — baik JSON (JavaScript Object Notation) atau YAMAL (YAMAL Ain't Markup Language) —untuk mengekspresikan penciptaan sumber daya. AWS Anda dapat menggunakan templat AWS CloudFormation untuk menentukan objek Katalog Data seperti basis data, tabel, partisi, crawler, pengklasifikasi, dan koneksi. Anda juga dapat menentukan objek ETL seperti tugas, pemicu, dan titik akhir pengembangan. Anda membuat templat yang menjelaskan semua sumber daya AWS yang Anda inginkan, dan AWS CloudFormation yang akan mengurus penyediaan dan konfigurasi sumber daya tersebut untuk Anda.

Untuk informasi selengkapnya, lihat Apa itu AWS CloudFormation? dan Bekerja dengan Templat AWS CloudFormation dalam Panduan Pengguna AWS CloudFormation.

Jika Anda berencana untuk menggunakan templat AWS CloudFormation yang kompatibel dengan AWS Glue, sebagai administrator, Anda harus memberikan akses ke AWS CloudFormation dan ke layanan dan tindakan AWS yang menjadi tempat bergantungnya. Untuk memberikan izin untuk membuat AWS CloudFormation sumber daya, lampirkan kebijakan berikut ke pengguna yang bekerja denganAWS CloudFormation:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "cloudformation:*" ], "Resource": "*" } ] }

Tabel berikut berisi tindakan yang dapat dilakukan oleh templat AWS CloudFormation atas nama Anda. Ia menyertakan tautan ke informasi tentang jenis sumber daya AWS dan jenis propertinya yang dapat Anda tambahkan ke templat AWS CloudFormation.

Untuk memulai, gunakan templat contoh berikut dan sesuaikan dengan metadata Anda sendiri. Kemudian gunakan konsol AWS CloudFormation untuk membuat tumpukan AWS CloudFormation untuk menambahkan objek ke AWS Glue dan layanan yang terkait. Banyak bidang dalam objek AWS Glue yang bersifat opsional. Templat ini menggambarkan bidang yang wajib atau diperlukan agar objek AWS Glue bekerja dan berfungsi.

Sebuah templat AWS CloudFormation dapat berupa format JSON atau YAML. Dalam contoh ini, YAML digunakan agar lebih mudah dibaca. Contoh tersebut berisi komentar (#) untuk menggambarkan nilai-nilai yang didefinisikan dalam templat.

Templat AWS CloudFormation dapat mencakup bagian Parameters. Bagian ini dapat diubah dalam teks contoh atau ketika file YAML dikirimkan ke konsol AWS CloudFormation untuk membuat sebuah tumpukan. Bagian Resources dari templat tersebut berisi definisi dan objek terkait AWS Glue. Definisi sintaksis templat AWS CloudFormation mungkin berisi properti yang mencakup sintaksis properti yang lebih detail. Tidak semua properti mungkin diperlukan untuk membuat sebuah objek AWS Glue. Sampel ini menunjukkan nilai contoh untuk properti umum untuk membuat sebuah objek AWS Glue.

Contoh AWS CloudFormation template untuk AWS Glue database

Sebuah basis data AWS Glue dalam Katalog Data berisi tabel metadata. Basis data terdiri dari properti yang sangat sedikit dan dapat dibuat dalam Katalog Data dengan templat AWS CloudFormation. Contoh templat berikut disediakan untuk Anda agar Anda bisa memulai dan untuk menggambarkan penggunaan tumpukan AWS CloudFormation dengan AWS Glue. Satu-satunya sumber daya yang dibuat oleh templat sampel adalah basis data bernama cfn-mysampledatabase. Anda dapat mengubahnya dengan mengedit teks sampel atau mengubah nilai pada konsol AWS CloudFormation saat Anda mengirimkan YAML.

Berikut ini menunjukkan nilai sampel untuk properti umum untuk membuat sebuah basis data AWS Glue. Untuk informasi selengkapnya tentang template AWS CloudFormation databaseAWS Glue, lihat AWS::Glue::Database.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CloudFormation template in YAML to demonstrate creating a database named mysampledatabase # The metadata created in the Data Catalog points to the flights public S3 bucket # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: CFNDatabaseName: Type: String Default: cfn-mysampledatabse # Resources section defines metadata for the Data Catalog Resources: # Create an AWS Glue database CFNDatabaseFlights: Type: AWS::Glue::Database Properties: # The database is created in the Data Catalog for your account CatalogId: !Ref AWS::AccountId DatabaseInput: # The name of the database is defined in the Parameters section above Name: !Ref CFNDatabaseName Description: Database to hold tables for flights data LocationUri: s3://crawler-public-us-east-1/flight/2016/csv/ #Parameters: Leave AWS database parameters blank

Contoh AWS CloudFormation template untuk AWS Glue database, tabel, dan partisi

Sebuah tabel AWS Glue berisi metadata yang mendefinisikan struktur dan lokasi data yang ingin Anda proses dengan skrip ETL Anda. Dalam sebuah tabel, Anda dapat menentukan partisi untuk memparalelkan pengolahan data Anda. Sebuah partisi adalah sepotong data yang Anda tetapkan dengan sebuah kunci. Sebagai contoh, dengan menggunakan bulan sebagai kunci, maka semua data untuk Januari akan dimasukkan dalam partisi yang sama. Di AWS Glue, basis data dapat berisi tabel, dan tabel dapat berisi partisi.

Contoh berikut menunjukkan cara mengisi basis data, tabel, dan partisi dengan menggunakan templat AWS CloudFormation. Format data dasar adalah csv dan dibatasi oleh koma (,). Karena basis data harus ada sebelum ia dapat berisi tabel, dan tabel harus ada dahulu sebelum partisi dapat dibuat, maka templat menggunakan pernyataan DependsOn untuk menentukan dependensi objek-objek tersebut ketika mereka diciptakan.

Nilai-nilai dalam contoh ini menentukan tabel yang berisi data penerbangan dari bucket Amazon S3 yang tersedia untuk umum. Untuk ilustrasi, hanya beberapa kolom data dan satu kunci partisi yang didefinisikan. Empat partisi juga didefinisikan dalam Katalog Data tersebut. Beberapa bidang untuk menggambarkan penyimpanan basis data juga ditampilkan dalam bidang StorageDescriptor.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CloudFormation template in YAML to demonstrate creating a database, a table, and partitions # The metadata created in the Data Catalog points to the flights public S3 bucket # # Parameters substituted in the Resources section # These parameters are names of the resources created in the Data Catalog Parameters: CFNDatabaseName: Type: String Default: cfn-database-flights-1 CFNTableName1: Type: String Default: cfn-manual-table-flights-1 # Resources to create metadata in the Data Catalog Resources: ### # Create an AWS Glue database CFNDatabaseFlights: Type: AWS::Glue::Database Properties: CatalogId: !Ref AWS::AccountId DatabaseInput: Name: !Ref CFNDatabaseName Description: Database to hold tables for flights data ### # Create an AWS Glue table CFNTableFlights: # Creating the table waits for the database to be created DependsOn: CFNDatabaseFlights Type: AWS::Glue::Table Properties: CatalogId: !Ref AWS::AccountId DatabaseName: !Ref CFNDatabaseName TableInput: Name: !Ref CFNTableName1 Description: Define the first few columns of the flights table TableType: EXTERNAL_TABLE Parameters: { "classification": "csv" } # ViewExpandedText: String PartitionKeys: # Data is partitioned by month - Name: mon Type: bigint StorageDescriptor: OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat Columns: - Name: year Type: bigint - Name: quarter Type: bigint - Name: month Type: bigint - Name: day_of_month Type: bigint InputFormat: org.apache.hadoop.mapred.TextInputFormat Location: s3://crawler-public-us-east-1/flight/2016/csv/ SerdeInfo: Parameters: field.delim: "," SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe # Partition 1 # Create an AWS Glue partition CFNPartitionMon1: DependsOn: CFNTableFlights Type: AWS::Glue::Partition Properties: CatalogId: !Ref AWS::AccountId DatabaseName: !Ref CFNDatabaseName TableName: !Ref CFNTableName1 PartitionInput: Values: - 1 StorageDescriptor: OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat Columns: - Name: mon Type: bigint InputFormat: org.apache.hadoop.mapred.TextInputFormat Location: s3://crawler-public-us-east-1/flight/2016/csv/mon=1/ SerdeInfo: Parameters: field.delim: "," SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe # Partition 2 # Create an AWS Glue partition CFNPartitionMon2: DependsOn: CFNTableFlights Type: AWS::Glue::Partition Properties: CatalogId: !Ref AWS::AccountId DatabaseName: !Ref CFNDatabaseName TableName: !Ref CFNTableName1 PartitionInput: Values: - 2 StorageDescriptor: OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat Columns: - Name: mon Type: bigint InputFormat: org.apache.hadoop.mapred.TextInputFormat Location: s3://crawler-public-us-east-1/flight/2016/csv/mon=2/ SerdeInfo: Parameters: field.delim: "," SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe # Partition 3 # Create an AWS Glue partition CFNPartitionMon3: DependsOn: CFNTableFlights Type: AWS::Glue::Partition Properties: CatalogId: !Ref AWS::AccountId DatabaseName: !Ref CFNDatabaseName TableName: !Ref CFNTableName1 PartitionInput: Values: - 3 StorageDescriptor: OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat Columns: - Name: mon Type: bigint InputFormat: org.apache.hadoop.mapred.TextInputFormat Location: s3://crawler-public-us-east-1/flight/2016/csv/mon=3/ SerdeInfo: Parameters: field.delim: "," SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe # Partition 4 # Create an AWS Glue partition CFNPartitionMon4: DependsOn: CFNTableFlights Type: AWS::Glue::Partition Properties: CatalogId: !Ref AWS::AccountId DatabaseName: !Ref CFNDatabaseName TableName: !Ref CFNTableName1 PartitionInput: Values: - 4 StorageDescriptor: OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat Columns: - Name: mon Type: bigint InputFormat: org.apache.hadoop.mapred.TextInputFormat Location: s3://crawler-public-us-east-1/flight/2016/csv/mon=4/ SerdeInfo: Parameters: field.delim: "," SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe

Contoh AWS CloudFormation template untuk pengklasifikasi AWS Glue grok

Sebuah pengklasifikasi AWS Glue menentukan skema dari data Anda. Salah satu jenis pengklasifikasi kustom menggunakan pola grok untuk mencocokkan data Anda. Jika pola cocok, maka pengklasifikasi kustom tersebut digunakan untuk membuat skema tabel Anda dan mengatur classification dengan nilai yang ditetapkan dalam definisi pengklasifikasi.

Sampel ini menciptakan sebuah pengklasifikasi yang menciptakan sebuah skema dengan satu kolom bernama message dan menetapkan klasifikasi ke greedy.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a classifier # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the classifier to be created CFNClassifierName: Type: String Default: cfn-classifier-grok-one-column-1 # # # Resources section defines metadata for the Data Catalog Resources: # Create classifier that uses grok pattern to put all data in one column and classifies it as "greedy". CFNClassifierFlights: Type: AWS::Glue::Classifier Properties: GrokClassifier: #Grok classifier that puts all data in one column Name: !Ref CFNClassifierName Classification: greedy GrokPattern: "%{GREEDYDATA:message}" #CustomPatterns: none

Contoh AWS CloudFormation template untuk pengklasifikasi AWS Glue JSON

Sebuah pengklasifikasi AWS Glue menentukan skema dari data Anda. Salah satu jenis pengklasifikasi kustom menggunakan JsonPath string yang mendefinisikan data JSON untuk klasifikasi untuk mengklasifikasikan. AWS Gluemendukung subset dari operator untukJsonPath, seperti yang dijelaskan dalam Menulis Pengklasifikasi JsonPath Kustom.

Jika pola cocok, maka pengklasifikasi kustom tersebut digunakan untuk membuat skema tabel Anda.

Contoh ini menciptakan sebuah pengklasifikasi yang membuat skema dengan masing-masing catatan di array Records3 dalam sebuah objek.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a JSON classifier # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the classifier to be created CFNClassifierName: Type: String Default: cfn-classifier-json-one-column-1 # # # Resources section defines metadata for the Data Catalog Resources: # Create classifier that uses a JSON pattern. CFNClassifierFlights: Type: AWS::Glue::Classifier Properties: JSONClassifier: #JSON classifier Name: !Ref CFNClassifierName JsonPath: $.Records3[*]

Contoh AWS CloudFormation template untuk pengklasifikasi AWS Glue XHTML

Sebuah pengklasifikasi AWS Glue menentukan skema dari data Anda. Salah satu jenis pengklasifikasi kustom menentukan tag XML untuk menunjuk elemen yang berisi masing-masing catatan dalam dokumen XML yang sedang diurai. Jika pola cocok, maka pengklasifikasi kustom tersebut digunakan untuk membuat skema tabel Anda dan mengatur classification dengan nilai yang ditetapkan dalam definisi pengklasifikasi.

Contoh ini menciptakan sebuah pengklasifikasi yang membuat sebuah skema dengan setiap catatan di tag Record dan mengatur klasifikasi ke XML.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating an XML classifier # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the classifier to be created CFNClassifierName: Type: String Default: cfn-classifier-xml-one-column-1 # # # Resources section defines metadata for the Data Catalog Resources: # Create classifier that uses the XML pattern and classifies it as "XML". CFNClassifierFlights: Type: AWS::Glue::Classifier Properties: XMLClassifier: #XML classifier Name: !Ref CFNClassifierName Classification: XML RowTag: <Records>

Contoh AWS CloudFormation template untuk AWS Glue crawler untuk Amazon S3

Sebuah crawler AWS Glue membuat tabel metadata dalam Katalog Data yang sesuai dengan data Anda. Anda kemudian dapat menggunakan definisi tabel ini sebagai sumber dan target dalam tugas ETL Anda.

Contoh ini membuat sebuah crawler, IAM role yang diperlukan, dan basis data AWS Glue dalam Katalog Data. Ketika crawler ini dijalankan, crawler tersebut mengambil IAM role dan membuat tabel dalam basis data untuk data penerbangan publik. Tabel dibuat dengan prefiks "cfn_sample_1_". IAM role yang dibuat oleh templat ini memungkinkan izin global; Anda mungkin ingin membuat sebuah peran kustom. Tidak ada pengklasifikasi kustom yang didefinisikan oleh pengklasifikasi ini. Pengklasifikasi bawaan AWS Glue digunakan secara default.

Ketika Anda mengirimkan sampel ini ke konsol AWS CloudFormation, Anda harus mengonfirmasi bahwa Anda ingin membuat IAM role.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a crawler # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the crawler to be created CFNCrawlerName: Type: String Default: cfn-crawler-flights-1 CFNDatabaseName: Type: String Default: cfn-database-flights-1 CFNTablePrefixName: Type: String Default: cfn_sample_1_ # # # Resources section defines metadata for the Data Catalog Resources: #Create IAM Role assumed by the crawler. For demonstration, this role is given all permissions. CFNRoleFlights: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - "glue.amazonaws.com" Action: - "sts:AssumeRole" Path: "/" Policies: - PolicyName: "root" PolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Action: "*" Resource: "*" # Create a database to contain tables created by the crawler CFNDatabaseFlights: Type: AWS::Glue::Database Properties: CatalogId: !Ref AWS::AccountId DatabaseInput: Name: !Ref CFNDatabaseName Description: "AWS Glue container to hold metadata tables for the flights crawler" #Create a crawler to crawl the flights data on a public S3 bucket CFNCrawlerFlights: Type: AWS::Glue::Crawler Properties: Name: !Ref CFNCrawlerName Role: !GetAtt CFNRoleFlights.Arn #Classifiers: none, use the default classifier Description: AWS Glue crawler to crawl flights data #Schedule: none, use default run-on-demand DatabaseName: !Ref CFNDatabaseName Targets: S3Targets: # Public S3 bucket with the flights data - Path: "s3://crawler-public-us-east-1/flight/2016/csv" TablePrefix: !Ref CFNTablePrefixName SchemaChangePolicy: UpdateBehavior: "UPDATE_IN_DATABASE" DeleteBehavior: "LOG" Configuration: "{\"Version\":1.0,\"CrawlerOutput\":{\"Partitions\":{\"AddOrUpdateBehavior\":\"InheritFromTable\"},\"Tables\":{\"AddOrUpdateBehavior\":\"MergeNewColumns\"}}}"

Contoh AWS CloudFormation template untuk AWS Glue koneksi

Sebuah koneksi AWS Glue dalam Katalog Data berisi informasi JDBC dan jaringan yang diperlukan untuk connect ke basis data JDBC. Informasi ini digunakan ketika Anda connect ke basis data JDBC untuk melakukan crawling atau menjalankan tugas ETL.

Sampel ini membuat koneksi ke basis data Amazon RDS MySQL bernama devdb. Ketika koneksi ini digunakan, IAM role, kredensial basis data, dan nilai-nilai koneksi jaringan juga harus disediakan. Lihat detail bidang yang diperlukan dalam templat tersebut.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a connection # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the connection to be created CFNConnectionName: Type: String Default: cfn-connection-mysql-flights-1 CFNJDBCString: Type: String Default: "jdbc:mysql://xxx-mysql.yyyyyyyyyyyyyy.us-east-1.rds.amazonaws.com:3306/devdb" CFNJDBCUser: Type: String Default: "master" CFNJDBCPassword: Type: String Default: "12345678" NoEcho: true # # # Resources section defines metadata for the Data Catalog Resources: CFNConnectionMySQL: Type: AWS::Glue::Connection Properties: CatalogId: !Ref AWS::AccountId ConnectionInput: Description: "Connect to MySQL database." ConnectionType: "JDBC" #MatchCriteria: none PhysicalConnectionRequirements: AvailabilityZone: "us-east-1d" SecurityGroupIdList: - "sg-7d52b812" SubnetId: "subnet-84f326ee" ConnectionProperties: { "JDBC_CONNECTION_URL": !Ref CFNJDBCString, "USERNAME": !Ref CFNJDBCUser, "PASSWORD": !Ref CFNJDBCPassword } Name: !Ref CFNConnectionName

Contoh AWS CloudFormation template untuk AWS Glue crawler untuk JDBC

Sebuah crawler AWS Glue membuat tabel metadata dalam Katalog Data yang sesuai dengan data Anda. Anda kemudian dapat menggunakan definisi tabel ini sebagai sumber dan target dalam tugas ETL Anda.

Contoh ini membuat sebuah crawler, IAM role yang diperlukan, dan basis data AWS Glue dalam Katalog Data. Ketika crawler ini dijalankan, crawler tersebut mengambil IAM role dan membuat tabel dalam basis data untuk data penerbangan publik yang telah disimpan di basis data MySQL. Tabel dibuat dengan prefiks "cfn_jdbc_1_". IAM role yang dibuat oleh templat ini memungkinkan izin global; Anda mungkin ingin membuat sebuah peran kustom. Tidak ada pengklasifikasi kustom yang dapat didefinisikan untuk data JDBC. Pengklasifikasi bawaan AWS Glue digunakan secara default.

Ketika Anda mengirimkan sampel ini ke konsol AWS CloudFormation, Anda harus mengonfirmasi bahwa Anda ingin membuat IAM role.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a crawler # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the crawler to be created CFNCrawlerName: Type: String Default: cfn-crawler-jdbc-flights-1 # The name of the database to be created to contain tables CFNDatabaseName: Type: String Default: cfn-database-jdbc-flights-1 # The prefix for all tables crawled and created CFNTablePrefixName: Type: String Default: cfn_jdbc_1_ # The name of the existing connection to the MySQL database CFNConnectionName: Type: String Default: cfn-connection-mysql-flights-1 # The name of the JDBC path (database/schema/table) with wildcard (%) to crawl CFNJDBCPath: Type: String Default: saldev/% # # # Resources section defines metadata for the Data Catalog Resources: #Create IAM Role assumed by the crawler. For demonstration, this role is given all permissions. CFNRoleFlights: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - "glue.amazonaws.com" Action: - "sts:AssumeRole" Path: "/" Policies: - PolicyName: "root" PolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Action: "*" Resource: "*" # Create a database to contain tables created by the crawler CFNDatabaseFlights: Type: AWS::Glue::Database Properties: CatalogId: !Ref AWS::AccountId DatabaseInput: Name: !Ref CFNDatabaseName Description: "AWS Glue container to hold metadata tables for the flights crawler" #Create a crawler to crawl the flights data in MySQL database CFNCrawlerFlights: Type: AWS::Glue::Crawler Properties: Name: !Ref CFNCrawlerName Role: !GetAtt CFNRoleFlights.Arn #Classifiers: none, use the default classifier Description: AWS Glue crawler to crawl flights data #Schedule: none, use default run-on-demand DatabaseName: !Ref CFNDatabaseName Targets: JdbcTargets: # JDBC MySQL database with the flights data - ConnectionName: !Ref CFNConnectionName Path: !Ref CFNJDBCPath #Exclusions: none TablePrefix: !Ref CFNTablePrefixName SchemaChangePolicy: UpdateBehavior: "UPDATE_IN_DATABASE" DeleteBehavior: "LOG" Configuration: "{\"Version\":1.0,\"CrawlerOutput\":{\"Partitions\":{\"AddOrUpdateBehavior\":\"InheritFromTable\"},\"Tables\":{\"AddOrUpdateBehavior\":\"MergeNewColumns\"}}}"

Contoh AWS CloudFormation template untuk AWS Glue pekerjaan Amazon S3 ke Amazon S3

Sebuah tugas AWS Glue di Katalog Data berisi nilai parameter yang diperlukan untuk menjalankan skrip di AWS Glue.

Sampel ini menciptakan tugas yang membaca data penerbangan dari bucket Amazon S3 dalam format csv dan menulisnya ke file Amazon S3 Parquet. Skrip yang dijalankan oleh tugas ini harus sudah ada. Anda dapat membuat skrip ETL untuk lingkungan Anda dengan konsol AWS Glue. Ketika tugas ini dijalankan, IAM role dengan izin yang semestinya juga harus disediakan.

Nilai parameter umum ditunjukkan dalam templat tersebut. Misalnya, AllocatedCapacity (DPU) default untuk 5.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a job using the public flights S3 table in a public bucket # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the job to be created CFNJobName: Type: String Default: cfn-job-S3-to-S3-2 # The name of the IAM role that the job assumes. It must have access to data, script, temporary directory CFNIAMRoleName: Type: String Default: AWSGlueServiceRoleGA # The S3 path where the script for this job is located CFNScriptLocation: Type: String Default: s3://aws-glue-scripts-123456789012-us-east-1/myid/sal-job-test2 # # # Resources section defines metadata for the Data Catalog Resources: # Create job to run script which accesses flightscsv table and write to S3 file as parquet. # The script already exists and is called by this job CFNJobFlights: Type: AWS::Glue::Job Properties: Role: !Ref CFNIAMRoleName #DefaultArguments: JSON object # If script written in Scala, then set DefaultArguments={'--job-language'; 'scala', '--class': 'your scala class'} #Connections: No connection needed for S3 to S3 job # ConnectionsList #MaxRetries: Double Description: Job created with CloudFormation #LogUri: String Command: Name: glueetl ScriptLocation: !Ref CFNScriptLocation # for access to directories use proper IAM role with permission to buckets and folders that begin with "aws-glue-" # script uses temp directory from job definition if required (temp directory not used S3 to S3) # script defines target for output as s3://aws-glue-target/sal AllocatedCapacity: 5 ExecutionProperty: MaxConcurrentRuns: 1 Name: !Ref CFNJobName

Contoh AWS CloudFormation template untuk AWS Glue pekerjaan JDBC ke Amazon S3

Sebuah tugas AWS Glue di Katalog Data berisi nilai parameter yang diperlukan untuk menjalankan skrip di AWS Glue.

Sampel ini membuat sebuah tugas yang membaca data penerbangan dari basis data MySQL JDBC sebagaimana didefinisikan oleh koneksi bernama cfn-connection-mysql-flights-1 dan menuliskannya ke file Amazon S3 Parquet. Skrip yang dijalankan oleh tugas ini harus sudah ada. Anda dapat membuat skrip ETL untuk lingkungan Anda dengan konsol AWS Glue. Ketika tugas ini dijalankan, IAM role dengan izin yang semestinya juga harus disediakan.

Nilai parameter umum ditunjukkan dalam templat tersebut. Misalnya, AllocatedCapacity (DPU) default untuk 5.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a job using a MySQL JDBC DB with the flights data to an S3 file # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the job to be created CFNJobName: Type: String Default: cfn-job-JDBC-to-S3-1 # The name of the IAM role that the job assumes. It must have access to data, script, temporary directory CFNIAMRoleName: Type: String Default: AWSGlueServiceRoleGA # The S3 path where the script for this job is located CFNScriptLocation: Type: String Default: s3://aws-glue-scripts-123456789012-us-east-1/myid/sal-job-dec4a # The name of the connection used for JDBC data source CFNConnectionName: Type: String Default: cfn-connection-mysql-flights-1 # # # Resources section defines metadata for the Data Catalog Resources: # Create job to run script which accesses JDBC flights table via a connection and write to S3 file as parquet. # The script already exists and is called by this job CFNJobFlights: Type: AWS::Glue::Job Properties: Role: !Ref CFNIAMRoleName #DefaultArguments: JSON object # For example, if required by script, set temporary directory as DefaultArguments={'--TempDir'; 's3://aws-glue-temporary-xyc/sal'} Connections: Connections: - !Ref CFNConnectionName #MaxRetries: Double Description: Job created with CloudFormation using existing script #LogUri: String Command: Name: glueetl ScriptLocation: !Ref CFNScriptLocation # for access to directories use proper IAM role with permission to buckets and folders that begin with "aws-glue-" # if required, script defines temp directory as argument TempDir and used in script like redshift_tmp_dir = args["TempDir"] # script defines target for output as s3://aws-glue-target/sal AllocatedCapacity: 5 ExecutionProperty: MaxConcurrentRuns: 1 Name: !Ref CFNJobName

Contoh AWS CloudFormation template untuk pemicu AWS Glue sesuai permintaan

Sebuah pemicu AWS Glue dalam Katalog Data berisi nilai-nilai parameter yang diperlukan untuk memulai eksekusi tugas ketika pemicu aktif. Sebuah pemicu sesuai permintaan aktif ketika Anda mengaktifkannya.

Sampel ini menciptakan sebuah pemicu sesuai permintaan yang memulai satu tugas bernama cfn-job-S3-to-S3-1.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating an on-demand trigger # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The existing job to be started by this trigger CFNJobName: Type: String Default: cfn-job-S3-to-S3-1 # The name of the trigger to be created CFNTriggerName: Type: String Default: cfn-trigger-ondemand-flights-1 # # Resources section defines metadata for the Data Catalog # Sample CFN YAML to demonstrate creating an on-demand trigger for a job Resources: # Create trigger to run an existing job (CFNJobName) on an on-demand schedule. CFNTriggerSample: Type: AWS::Glue::Trigger Properties: Name: Ref: CFNTriggerName Description: Trigger created with CloudFormation Type: ON_DEMAND Actions: - JobName: !Ref CFNJobName # Arguments: JSON object #Schedule: #Predicate:

Contoh AWS CloudFormation template untuk pemicu AWS Glue terjadwal

Sebuah pemicu AWS Glue dalam Katalog Data berisi nilai-nilai parameter yang diperlukan untuk memulai eksekusi tugas ketika pemicu aktif. Sebuah pemicu terjadwal aktif ketika diaktifkan dan pewaktu cron muncul.

Sampel ini menciptakan sebuah pemicu terjadwal yang memulai satu tugas bernama cfn-job-S3-to-S3-1. Pewaktu adalah ekspresi cron untuk menjalankan tugas setiap 10 menit pada hari kerja.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a scheduled trigger # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The existing job to be started by this trigger CFNJobName: Type: String Default: cfn-job-S3-to-S3-1 # The name of the trigger to be created CFNTriggerName: Type: String Default: cfn-trigger-scheduled-flights-1 # # Resources section defines metadata for the Data Catalog # Sample CFN YAML to demonstrate creating a scheduled trigger for a job # Resources: # Create trigger to run an existing job (CFNJobName) on a cron schedule. TriggerSample1CFN: Type: AWS::Glue::Trigger Properties: Name: Ref: CFNTriggerName Description: Trigger created with CloudFormation Type: SCHEDULED Actions: - JobName: !Ref CFNJobName # Arguments: JSON object # # Run the trigger every 10 minutes on Monday to Friday Schedule: cron(0/10 * ? * MON-FRI *) #Predicate:

Contoh AWS CloudFormation template untuk AWS Glue pemicu bersyarat

Sebuah pemicu AWS Glue dalam Katalog Data berisi nilai-nilai parameter yang diperlukan untuk memulai eksekusi tugas ketika pemicu aktif. Pemicu bersyarat aktif ketika diaktifkan dan syarat terpenuhi, seperti sebuah tugas yang berhasil selesai.

Sampel ini menciptakan sebuah pemicu bersyarat yang memulai satu tugas bernama cfn-job-S3-to-S3-1. Pekerjaan ini dimulai ketika tugas bernama cfn-job-S3-to-S3-2 berhasil diselesaikan.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a conditional trigger for a job, which starts when another job completes # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The existing job to be started by this trigger CFNJobName: Type: String Default: cfn-job-S3-to-S3-1 # The existing job that when it finishes causes trigger to fire CFNJobName2: Type: String Default: cfn-job-S3-to-S3-2 # The name of the trigger to be created CFNTriggerName: Type: String Default: cfn-trigger-conditional-1 # Resources: # Create trigger to run an existing job (CFNJobName) when another job completes (CFNJobName2). CFNTriggerSample: Type: AWS::Glue::Trigger Properties: Name: Ref: CFNTriggerName Description: Trigger created with CloudFormation Type: CONDITIONAL Actions: - JobName: !Ref CFNJobName # Arguments: JSON object #Schedule: none Predicate: #Value for Logical is required if more than 1 job listed in Conditions Logical: AND Conditions: - LogicalOperator: EQUALS JobName: !Ref CFNJobName2 State: SUCCEEDED

Contoh AWS CloudFormation template untuk titik akhir AWS Glue pengembangan

Transformasi pembelajaran AWS Glue mesin adalah transformasi khusus untuk membersihkan data Anda. Saat ini ada satu transformasi yang tersedia bernama FindMatches. FindMatches Transformasi memungkinkan Anda mengidentifikasi duplikat atau pencocokan catatan dalam kumpulan data Anda, bahkan ketika catatan tidak memiliki pengidentifikasi unik umum dan tidak ada bidang yang sama persis.

Sampel ini menciptakan transformasi pembelajaran mesin. Untuk informasi selengkapnya tentang parameter yang Anda perlukan untuk membuat transformasi pembelajaran mesin, lihatRekam pencocokan dengan AWS Lake Formation FindMatches.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a machine learning transform # # Resources section defines metadata for the machine learning transform Resources: MyMLTransform: Type: "AWS::Glue::MLTransform" Condition: "isGlueMLGARegion" Properties: Name: !Sub "MyTransform" Description: "The bestest transform ever" Role: !ImportValue MyMLTransformUserRole GlueVersion: "1.0" WorkerType: "Standard" NumberOfWorkers: 5 Timeout: 120 MaxRetries: 1 InputRecordTables: GlueTables: - DatabaseName: !ImportValue MyMLTransformDatabase TableName: !ImportValue MyMLTransformTable TransformParameters: TransformType: "FIND_MATCHES" FindMatchesParameters: PrimaryKeyColumnName: "testcolumn" PrecisionRecallTradeoff: 0.5 AccuracyCostTradeoff: 0.5 EnforceProvidedLabels: True Tags: key1: "value1" key2: "value2" TransformEncryption: TaskRunSecurityConfigurationName: !ImportValue MyMLTransformSecurityConfiguration MLUserDataEncryption: MLUserDataEncryptionMode: "SSE-KMS" KmsKeyId: !ImportValue MyMLTransformEncryptionKey

Contoh AWS CloudFormation template untuk kumpulan AWS Glue Data Quality aturan

Kumpulan aturan Kualitas AWS Glue Data berisi aturan yang dapat dievaluasi pada tabel dalam Katalog Data. Setelah kumpulan aturan ditempatkan pada tabel yang ditargetkan, Anda dapat masuk ke Katalog Data dan menjalankan evaluasi yang menjalankan data Anda terhadap aturan tersebut dalam kumpulan aturan. Aturan ini dapat bervariasi dari mengevaluasi jumlah baris hingga mengevaluasi integritas referensial pada data Anda.

Contoh berikut adalah CloudFormation template yang membuat ruleset dengan berbagai aturan pada tabel target yang ditentukan.

AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a DataQualityRuleset # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the ruleset to be created RulesetName: Type: String Default: "CFNRulesetName" RulesetDescription: Type: String Default: "CFN DataQualityRuleset" # Rules that will be associated with this ruleset Rules: Type: String Default: 'Rules = [ RowCount > 100, IsUnique "id", IsComplete "nametype" ]' # Name of database and table within Data Catalog which the ruleset will # be applied too DatabaseName: Type: String Default: "ExampleDatabaseName" TableName: Type: String Default: "ExampleTableName" # Resources section defines metadata for the Data Catalog Resources: # Creates a Data Quality ruleset under specified rules DQRuleset: Type: AWS::Glue::DataQualityRuleset Properties: Name: !Ref RulesetName Description: !Ref RulesetDescription # The String within rules must be formatted in DQDL, a language # used specifically to make rules Ruleset: !Ref Rules # The targeted table must exist within Data Catalog alongside # the correct database TargetTable: DatabaseName: !Ref DatabaseName TableName: !Ref TableName

Contoh AWS CloudFormation template untuk AWS Glue Data Quality kumpulan aturan dengan penjadwal EventBridge

Kumpulan aturan Kualitas AWS Glue Data berisi aturan yang dapat dievaluasi pada tabel dalam Katalog Data. Setelah kumpulan aturan ditempatkan pada tabel yang ditargetkan, Anda dapat masuk ke Katalog Data dan menjalankan evaluasi yang menjalankan data Anda terhadap aturan tersebut dalam kumpulan aturan. Alih-alih harus secara manual masuk ke Katalog Data untuk mengevaluasi kumpulan aturan, Anda juga dapat menambahkan EventBridge Penjadwal dalam CloudFormation template kami untuk menjadwalkan evaluasi kumpulan aturan ini untuk Anda pada interval waktu.

Contoh berikut adalah CloudFormation template yang membuat aturan Kualitas Data dan EventBridge Scheduler untuk mengevaluasi aturan yang disebutkan di atas setiap lima menit.

AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a DataQualityRuleset # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the ruleset to be created RulesetName: Type: String Default: "CFNRulesetName" # Rules that will be associated with this Ruleset Rules: Type: String Default: 'Rules = [ RowCount > 100, IsUnique "id", IsComplete "nametype" ]' # The name of the Schedule to be created ScheduleName: Type: String Default: "ScheduleDQRulsetEvaluation" # This expression determines the rate at which the Schedule will evaluate # your data using the above ruleset ScheduleRate: Type: String Default: "rate(5 minutes)" # The Request that being sent must match the details of the Data Quality Ruleset ScheduleRequest: Type: String Default: ' { "DataSource": { "GlueTable": { "DatabaseName": "ExampleDatabaseName", "TableName": "ExampleTableName" } }, "Role": "role/AWSGlueServiceRoleDefault", "RulesetNames": [ ""CFNRulesetName"" ] } ' # Resources section defines metadata for the Data Catalog Resources: # Creates a Data Quality ruleset under specified rules DQRuleset: Type: AWS::Glue::DataQualityRuleset Properties: Name: !Ref RulesetName Description: "CFN DataQualityRuleset" # The String within rules must be formatted in DQDL, a language # used specifically to make rules Ruleset: !Ref Rules # The targeted table must exist within Data Catalog alongside # the correct database TargetTable: DatabaseName: "ExampleDatabaseName" TableName: "ExampleTableName" # Create a Scheduler to schedule evaluation runs on the above ruleset ScheduleDQEval: Type: AWS::Scheduler::Schedule Properties: Name: !Ref ScheduleName Description: "Schedule DataQualityRuleset Evaluations" FlexibleTimeWindow: Mode: "OFF" ScheduleExpression: !Ref ScheduleRate ScheduleExpressionTimezone: "America/New_York" State: "ENABLED" Target: # The ARN is the API that will be run, since we want to evaluate our ruleset # we want this specific ARN Arn: "arn:aws:scheduler:::aws-sdk:glue:startDataQualityRulesetEvaluationRun" # Your RoleArn must have approval to schedule RoleArn: "arn:aws:iam::123456789012:role/AWSGlueServiceRoleDefault" # This is the Request that is being sent to the Arn Input: ' { "DataSource": { "GlueTable": { "DatabaseName": "sampledb", "TableName": "meteorite" } }, "Role": "role/AWSGlueServiceRoleDefault", "RulesetNames": [ "TestCFN" ] } '

Contoh AWS CloudFormation template untuk titik akhir AWS Glue pengembangan

Sebuah titik akhir pengembangan AWS Glue adalah sebuah lingkungan yang dapat Anda gunakan untuk mengembangkan dan menguji skrip AWS Glue.

Sampel ini menciptakan sebuah titik akhir pengembangan dengan nilai parameter jaringan minimal yang diperlukan untuk berhasil membuatnya. Untuk informasi lebih lanjut tentang parameter yang Anda butuhkan untuk menyiapkan titik akhir pengembangan, lihat Menyiapkan jaringan untuk pengembangan AWS Glue.

Anda memberikan ARN (Amazon Resource Name) IAM role yang ada untuk membuat titik akhir pengembangan. Berikan kunci publik RSA yang benar dan sediakan kunci privat yang sesuai jika Anda berencana untuk membuat server notebook pada titik akhir pengembangan.

catatan

Untuk setiap notebook server yang Anda buat yang dikaitkan dengan titik akhir pengembangan, Anda mengelolanya. Oleh karena itu, jika Anda menghapus titik akhir pengembangan, untuk menghapus server notebook, Anda harus menghapus tumpukan AWS CloudFormation pada konsol AWS CloudFormation.

--- AWSTemplateFormatVersion: '2010-09-09' # Sample CFN YAML to demonstrate creating a development endpoint # # Parameters section contains names that are substituted in the Resources section # These parameters are the names the resources created in the Data Catalog Parameters: # The name of the crawler to be created CFNEndpointName: Type: String Default: cfn-devendpoint-1 CFNIAMRoleArn: Type: String Default: arn:aws:iam::123456789012/role/AWSGlueServiceRoleGA # # # Resources section defines metadata for the Data Catalog Resources: CFNDevEndpoint: Type: AWS::Glue::DevEndpoint Properties: EndpointName: !Ref CFNEndpointName #ExtraJarsS3Path: String #ExtraPythonLibsS3Path: String NumberOfNodes: 5 PublicKey: ssh-rsa public.....key myuserid-key RoleArn: !Ref CFNIAMRoleArn SecurityGroupIds: - sg-64986c0b SubnetId: subnet-c67cccac