AWS CloudFormation per AWS Glue - AWS Glue

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

AWS CloudFormation per AWS Glue

AWS CloudFormation è un servizio in grado di creare molte risorse. AWS AWS Glue fornisce operazioni API per creare oggetti in AWS Glue Data Catalog. Tuttavia, potrebbe essere più comodo definire e creare AWS Glue oggetti e altri oggetti AWS risorsa correlati in un file AWS CloudFormation modello. È quindi possibile automatizzare il processo di creazione degli oggetti.

AWS CloudFormation fornisce una sintassi semplificata, JSON (JavaScript Object Notation) o YAML (YAML Ain't Markup Language), per esprimere la creazione di risorse. AWS Puoi usare modelli AWS CloudFormation per definire oggetti del catalogo dati come database, tabelle, partizioni, crawler, classificatori e connessioni. È anche possibile definire oggetti ETL, come processi, trigger ed endpoint di sviluppo. Crei un modello che descrive tutte le risorse che desideri e si occupa del provisioning e della AWS configurazione di tali risorse per te. AWS CloudFormation

Per ulteriori informazioni, consulta What Is? AWS CloudFormation e Utilizzo dei AWS CloudFormation modelli nella Guida per l'AWS CloudFormation utente.

Se si prevede di utilizzare AWS CloudFormation modelli compatibili con AWS Glue, in qualità di amministratore, devi concedere l'accesso ai AWS CloudFormation e ai AWS servizi e alle azioni da cui dipende. Per concedere le autorizzazioni alla creazione di AWS CloudFormation risorse, allega la seguente politica agli utenti che lavorano con AWS CloudFormation:

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

La tabella seguente contiene le azioni che un AWS CloudFormation modello può eseguire per tuo conto. Include collegamenti a informazioni sui tipi di AWS risorse e sui relativi tipi di proprietà che è possibile aggiungere a un AWS CloudFormation modello.

Per iniziare, usa i modelli di esempio seguenti e personalizzali con i tuoi metadati. Quindi usa la AWS CloudFormation console per creare uno stack a cui aggiungere oggetti AWS CloudFormation AWS Glue e tutti i servizi associati. Molti campi in un AWS Glue gli oggetti sono opzionali. Questi modelli illustrano i campi che sono obbligatori o sono necessari per un funzionamento e una funzionalità AWS Glue oggetto.

Un AWS CloudFormation modello può essere in formato JSON o YAML. In questi esempi viene usato il formato YAML per semplificare la lettura. Gli esempi contengono commenti (#) per descrivere i valori definiti nei modelli.

AWS CloudFormation i modelli possono includere una sezione. Parameters Questa sezione può essere modificata nel testo di esempio o quando il file YAML viene inviato alla AWS CloudFormation console per creare uno stack. La Resources sezione del modello contiene la definizione di AWS Glue e oggetti correlati. AWS CloudFormation le definizioni della sintassi dei modelli potrebbero contenere proprietà che includono una sintassi delle proprietà più dettagliata. Non tutte le proprietà potrebbero essere necessarie per creare un AWS Glue oggetto. Questi esempi mostrano valori di esempio per proprietà comuni per creare un AWS Glue oggetto.

AWS CloudFormation Modello di esempio per un AWS Glue database

Un record AWS Glue il database nel Data Catalog contiene tabelle di metadati. Il database è composto da pochissime proprietà e può essere creato nel Data Catalog con un AWS CloudFormation modello. Il seguente modello di esempio viene fornito per iniziare e per illustrare l'uso degli AWS CloudFormation stack con AWS Glue. L'unica risorsa creata dal modello di esempio è un database denominatocfn-mysampledatabase. Puoi cambiarlo modificando il testo dell'esempio o cambiando il valore sulla AWS CloudFormation console quando invii il codice YAML.

Di seguito sono riportati alcuni esempi di valori per proprietà comuni per creare un AWS Glue database. Per ulteriori informazioni sul modello di AWS CloudFormation database per AWS Glue, consulta 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

AWS CloudFormation Modello di esempio per un AWS Glue database, tabella e partizione

Un record AWS Glue la tabella contiene i metadati che definiscono la struttura e la posizione dei dati che si desidera elaborare con gli script ETL. In una tabella è possibile definire partizioni per parallelizzare l'elaborazione dei dati. Una partizione è un blocco di dati definito con una chiave. Se, ad esempio, usi il mese come chiave, tutti i dati per gennaio vengono inclusi nella stessa partizione. In AWS Glue, i database possono contenere tabelle e le tabelle possono contenere partizioni.

L'esempio seguente mostra come popolare un database, una tabella e le partizioni usando un modello AWS CloudFormation . Il formato dei dati di base è csv, con valori delimitati da una virgola (,). Poiché un database deve esistere per poter contenere una tabella e una tabella deve esistere per poter creare le partizioni, il modello usa l'istruzione DependsOn per definire la dipendenza di questi oggetti quando vengono creati.

I valori in questo esempio definiscono una tabella che contiene dati di voli da un bucket Amazon S3 disponibile pubblicamente. A scopo illustrativo, sono definite solo alcune colonne di dati e una chiave di partizionamento. Vengono definite anche quattro partizioni nel catalogo dati. Nei campi StorageDescriptor sono mostrati anche alcuni campi per descrivere lo storage dei dati di base.

--- 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

AWS CloudFormation Modello di esempio per un AWS Glue classificatore di gruppo

Un record AWS Glue il classificatore determina lo schema dei dati. Un tipo di classificatore personalizzato usa un pattern grok per trovare la corrispondenza con i dati. Se il pattern corrisponde, il classificatore personalizzato viene usato per creare lo schema della tabella e impostare classification sul valore impostato nella definizione del classificatore.

Questo esempio crea un classificatore che crea a sua volta uno schema con una colonna denominata message e imposta la classificazione su 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

AWS CloudFormation Modello di esempio per un AWS Glue Classificatore JSON

Un record AWS Glue il classificatore determina lo schema dei dati. Un tipo di classificatore personalizzato utilizza una JsonPath stringa che definisce i dati JSON da classificare dal classificatore. AWS Glue supporta un sottoinsieme degli operatori perJsonPath, come descritto in Writing Custom Classifiers. JsonPath

Se il modello corrisponde, il classificatore personalizzato viene utilizzato per creare il tuo schema della tabella.

Questo esempio crea un classificatore che a sua volta crea uno schema con ogni record nella matrice Records3 in un oggetto.

--- 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[*]

Modello di esempio per un AWS CloudFormationAWS Glue Classificatore XML

Un record AWS Glue il classificatore determina lo schema dei dati. Un tipo di classificatore personalizzato specifica un tag XML per designare l'elemento che contiene ogni record in un documento XML sottoposto ad analisi. Se il pattern corrisponde, il classificatore personalizzato viene usato per creare lo schema della tabella e impostare classification sul valore impostato nella definizione del classificatore.

Questo esempio crea un classificatore che crea a sua volta uno schema con ciascun record nel tag Record e imposta la classificazione su 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>

AWS CloudFormation Modello di esempio per un AWS Glue crawler per Amazon S3

Un record AWS Glue crawler crea tabelle di metadati nel tuo Data Catalog che corrispondono ai tuoi dati. Puoi quindi usare queste definizioni di tabella come origini e target nei processi ETL.

Questo esempio crea un crawler, il ruolo IAM richiesto e un AWS Glue database nel Data Catalog. Quando il crawler viene eseguito, assume il ruolo IAM e crea una tabella del database per i dati dei voli pubblici. La tabella viene creata con il prefisso "cfn_sample_1_". Il ruolo IAM creato da questo modello concede autorizzazioni globali. Potresti voler creare un ruolo personalizzato. Nessun classificatore personalizzato è definito da questo classificatore. AWS Glue i classificatori incorporati vengono utilizzati per impostazione predefinita.

Quando invii questo esempio alla AWS CloudFormation console, devi confermare di voler creare il ruolo IAM.

--- 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\"}}}"

AWS CloudFormation Modello di esempio per un AWS Glue connessione

Un record AWS Glue la connessione nel Data Catalog contiene le informazioni JDBC e di rete necessarie per connettersi a un database JDBC. Queste informazioni vengono usate per la connessione a un database JDBC per il crawling o l'esecuzione di processi ETL.

In questo esempio viene creata una connessione a un database Amazon RDS MySQL denominato devdb. Quando la connessione viene usata, è necessario fornire anche un ruolo IAM, le credenziali del database e i valori per la connessione di rete. Consulta i dettagli dei campi necessari nel modello.

--- 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

Modello di esempio per un AWS CloudFormationAWS Glue crawler per JDBC

Un record AWS Glue crawler crea tabelle di metadati nel tuo Data Catalog che corrispondono ai tuoi dati. Puoi quindi usare queste definizioni di tabella come origini e target nei processi ETL.

Questo esempio crea un crawler, un ruolo IAM richiesto e un AWS Glue database nel Data Catalog. Quando il crawler viene eseguito, assume il ruolo IAM e crea una tabella nel database per i dati dei voli pubblici archiviati in un database MySQL. La tabella viene creata con il prefisso "cfn_jdbc_1_". Il ruolo IAM creato da questo modello concede autorizzazioni globali. Potresti voler creare un ruolo personalizzato. Non è possibile definire classificatori personalizzati per i dati JDBC. AWS Glue i classificatori incorporati vengono utilizzati per impostazione predefinita.

Quando invii questo esempio alla AWS CloudFormation console, devi confermare di voler creare il ruolo IAM.

--- 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\"}}}"

AWS CloudFormation Modello di esempio per un AWS Glue lavoro da Amazon S3 ad Amazon S3

Un record AWS Glue job nel Data Catalog contiene i valori dei parametri necessari per eseguire uno script in AWS Glue.

Questo esempio crea un processo che legge i dati dei voli da un bucket Amazon S3 in formato csv e li scrive in un file Parquet in Amazon S3. Lo script eseguito da questo processo deve esistere già. È possibile generare uno script ETL per il proprio ambiente con AWS Glue console. Quando questo processo viene eseguito, è necessario fornire anche un ruolo IAM con le autorizzazioni appropriate.

I valori dei parametri comuni sono mostrati nel modello. Ad esempio, il valore predefinito AllocatedCapacity (DPUs) è 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

AWS CloudFormation Modello di esempio per un AWS Glue lavoro per JDBC su Amazon S3

Un record AWS Glue job nel Data Catalog contiene i valori dei parametri necessari per eseguire uno script in AWS Glue.

Questo esempio crea un processo che legge i dati dei voli da un database JDBC MySQL in base a quanto definito dalla connessione denominata cfn-connection-mysql-flights-1 e li scrive in un file Parquet in Amazon S3. Lo script eseguito da questo processo deve esistere già. È possibile generare uno script ETL per il proprio ambiente con AWS Glue console. Quando questo processo viene eseguito, è necessario fornire anche un ruolo IAM con le autorizzazioni appropriate.

I valori dei parametri comuni sono mostrati nel modello. Ad esempio, il valore predefinito AllocatedCapacity (DPUs) è 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

AWS CloudFormation Modello di esempio per un AWS Glue trigger su richiesta

Un record AWS Glue il trigger nel Data Catalog contiene i valori dei parametri necessari per avviare l'esecuzione di un job quando viene attivato il trigger. Un trigger on demand viene attivato quando lo si abilita.

In questo esempio viene creato un trigger on demand che avvia un processo denominato 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:

AWS CloudFormation Modello di esempio per un AWS Glue trigger pianificato

Un record AWS Glue il trigger nel Data Catalog contiene i valori dei parametri necessari per avviare l'esecuzione di un job quando viene attivato il trigger. Un trigger pianificato viene attivato quando è abilitato e il timer cron raggiunge il valore definito.

In questo esempio viene creato un trigger pianificato che avvia un processo denominato cfn-job-S3-to-S3-1. Il timer è un'espressione cron per l'esecuzione del processo ogni 10 minuti nei giorni feriali.

--- 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:

AWS CloudFormation Modello di esempio per un AWS Glue innesco condizionale

Un record AWS Glue il trigger nel Data Catalog contiene i valori dei parametri necessari per avviare l'esecuzione di un job quando viene attivato il trigger. Un trigger condizionale viene attivato quando è abilitato e le relative condizioni vengono soddisfatte, ad esempio un processo viene completato correttamente.

In questo esempio viene creato un trigger condizionale che avvia un processo denominato cfn-job-S3-to-S3-1. Questo processo viene avviato quando il processo denominato cfn-job-S3-to-S3-2 viene completato correttamente.

--- 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

AWS CloudFormation Modello di esempio per un AWS Glue endpoint di sviluppo

Un record AWS Glue la trasformazione dell'apprendimento automatico è una trasformazione personalizzata per pulire i dati. Attualmente è disponibile una trasformazione denominata FindMatches. La FindMatches trasformazione consente di identificare i record duplicati o corrispondenti nel set di dati, anche quando i record non hanno un identificatore univoco comune e nessun campo corrisponde esattamente.

Questo esempio mostra come creare una trasformazione basata su machine learning. Per ulteriori informazioni sui parametri necessari per creare una trasformazione basata su machine learning, consulta Record di abbinamento con 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

Modello di esempio per un AWS CloudFormationAWS Glue Data Quality set di regole

Un set di regole per la qualità AWS Glue dei dati contiene regole che possono essere valutate su una tabella all'interno del Data Catalog. Una volta che il set di regole è stato inserito nella tabella di destinazione, è possibile accedere a Catalogo dati ed eseguire una valutazione che esamina i dati in base a tali regole all'interno del set di regole. Queste regole spaziano dalla valutazione del conteggio delle righe alla valutazione dell'integrità referenziale dei dati.

L'esempio seguente è un CloudFormation modello che crea un set di regole con una varietà di regole sulla tabella di destinazione specificata.

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

AWS CloudFormation Modello di esempio per un AWS Glue Data Quality set di regole con scheduler EventBridge

Un set di regole per la qualità AWS Glue dei dati contiene regole che possono essere valutate su una tabella all'interno del Data Catalog. Una volta che il set di regole è stato inserito nella tabella di destinazione, è possibile accedere a Catalogo dati ed eseguire una valutazione che esamina i dati in base a tali regole all'interno del set di regole. Invece di dover accedere manualmente al Data Catalog per valutare il set di regole, puoi anche aggiungere uno EventBridge Scheduler all'interno del nostro CloudFormation modello per pianificare queste valutazioni del set di regole per te in base a un intervallo di tempo.

L'esempio seguente è un CloudFormation modello che crea un set di regole di Data Quality e uno EventBridge Scheduler per valutare il suddetto set di regole ogni cinque minuti.

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" ] } '

Modello di esempio per un AWS CloudFormationAWS Glue endpoint di sviluppo

Un record AWS Glue development endpoint è un ambiente che puoi usare per sviluppare e testare AWS Glue script.

In questo esempio viene creato un endpoint di sviluppo con i valori dei parametri di rete minimi necessari per la creazione. Per ulteriori informazioni sui parametri necessari per configurare un endpoint di sviluppo, consulta Configurazione di reti per lo sviluppo per AWS Glue.

Per creare l'endpoint di sviluppo, puoi fornire un ARN (Amazon Resource Name) di un ruolo IAM esistente. Fornisci una chiave pubblica RSA valida e tieni a disposizione la chiave privata corrispondente se prevedi di creare un server notebook nell'endpoint di sviluppo.

Nota

Effettui la gestione di qualsiasi server notebook che hai creato e che è associato a un endpoint di sviluppo. Pertanto, se si elimina l'endpoint di sviluppo, per eliminare il server notebook, è necessario eliminare lo AWS CloudFormation stack sulla console. 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