Skip navigation links

Package software.amazon.awscdk.services.glue

AWS Glue Construct Library

See: Description

Package software.amazon.awscdk.services.glue Description

AWS Glue Construct Library

---

cfn-resources: Stable

All classes with the Cfn prefix in this module (CFN Resources) are always stable and safe to use.

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This module is part of the AWS Cloud Development Kit project.

Job

A Job encapsulates a script that connects to data sources, processes them, and then writes output to a data target.

There are 3 types of jobs supported by AWS Glue: Spark ETL, Spark Streaming, and Python Shell jobs.

The glue.JobExecutable allows you to specify the type of job, the language to use and the code assets required by the job.

glue.Code allows you to refer to the different code assets required by the job, either from an existing S3 location or from a local file path.

Spark Jobs

These jobs run in an Apache Spark environment managed by AWS Glue.

ETL Jobs

An ETL job processes data in batches using Apache Spark.

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Job.Builder.create(stack, "ScalaSparkEtlJob")
         .executable(glue.JobExecutable.scalaEtl(Map.of(
                 "glueVersion", glue.GlueVersion.getV2_0(),
                 "script", glue.Code.fromBucket(bucket, "src/com/example/HelloWorld.scala"),
                 "className", "com.example.HelloWorld",
                 "extraJars", asList(glue.Code.fromBucket(bucket, "jars/HelloWorld.jar")))))
         .description("an example Scala ETL job")
         .build();
 

Streaming Jobs

A Streaming job is similar to an ETL job, except that it performs ETL on data streams. It uses the Apache Spark Structured Streaming framework. Some Spark job features are not available to streaming ETL jobs.

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Job.Builder.create(stack, "PythonSparkStreamingJob")
         .executable(glue.JobExecutable.pythonStreaming(Map.of(
                 "glueVersion", glue.GlueVersion.getV2_0(),
                 "pythonVersion", glue.PythonVersion.getTHREE(),
                 "script", glue.Code.fromAsset(path.join(__dirname, "job-script/hello_world.py")))))
         .description("an example Python Streaming job")
         .build();
 

Python Shell Jobs

A Python shell job runs Python scripts as a shell and supports a Python version that depends on the AWS Glue version you are using. This can be used to schedule and run tasks that don't require an Apache Spark environment.

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Job.Builder.create(stack, "PythonShellJob")
         .executable(glue.JobExecutable.pythonShell(Map.of(
                 "glueVersion", glue.GlueVersion.getV1_0(),
                 "pythonVersion", PythonVersion.getTHREE(),
                 "script", glue.Code.fromBucket(bucket, "script.py"))))
         .description("an example Python Shell job")
         .build();
 

See documentation for more information on adding jobs in Glue.

Connection

A Connection allows Glue jobs, crawlers and development endpoints to access certain types of data stores. For example, to create a network connection to connect to a data source within a VPC:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Connection.Builder.create(stack, "MyConnection")
         .connectionType(glue.ConnectionTypes.getNETWORK())
         // The security groups granting AWS Glue inbound access to the data source within the VPC
         .securityGroups(asList(securityGroup))
         // The VPC subnet which contains the data source
         .subnet(subnet)
         .build();
 

If you need to use a connection type that doesn't exist as a static member on ConnectionType, you can instantiate a ConnectionType object, e.g: new glue.ConnectionType('NEW_TYPE').

See Adding a Connection to Your Data Store and Connection Structure documentation for more information on the supported data stores and their configurations.

SecurityConfiguration

A SecurityConfiguration is a set of security properties that can be used by AWS Glue to encrypt data at rest.

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 SecurityConfiguration.Builder.create(stack, "MySecurityConfiguration")
         .securityConfigurationName("name")
         .cloudWatchEncryption(Map.of(
                 "mode", glue.CloudWatchEncryptionMode.getKMS()))
         .jobBookmarksEncryption(Map.of(
                 "mode", glue.JobBookmarksEncryptionMode.getCLIENT_SIDE_KMS()))
         .s3Encryption(Map.of(
                 "mode", glue.S3EncryptionMode.getKMS()))
         .build();
 

By default, a shared KMS key is created for use with the encryption configurations that require one. You can also supply your own key for each encryption config, for example, for CloudWatch encryption:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 SecurityConfiguration.Builder.create(stack, "MySecurityConfiguration")
         .securityConfigurationName("name")
         .cloudWatchEncryption(Map.of(
                 "mode", glue.CloudWatchEncryptionMode.getKMS(),
                 "kmsKey", key))
         .build();
 

See documentation for more info for Glue encrypting data written by Crawlers, Jobs, and Development Endpoints.

Database

A Database is a logical grouping of Tables in the Glue Catalog.

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Database.Builder.create(stack, "MyDatabase")
         .databaseName("my_database")
         .build();
 

Table

A Glue table describes a table of data in S3: its structure (column names and types), location of data (S3 objects with a common prefix in a S3 bucket), and format for the files (Json, Avro, Parquet, etc.):

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
         .database(myDatabase)
         .tableName("my_table")
         .columns(asList(Map.of(
                 "name", "col1",
                 "type", glue.Schema.getSTRING()), Map.of(
                 "name", "col2",
                 "type", glue.Schema.array(Schema.getSTRING()),
                 "comment", "col2 is an array of strings")))
         .dataFormat(glue.DataFormat.getJSON())
         .build();
 

By default, a S3 bucket will be created to store the table's data but you can manually pass the bucket and s3Prefix:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
         .bucket(myBucket)
         .s3Prefix("my-table/")...
         .build();
 

By default, an S3 bucket will be created to store the table's data and stored in the bucket root. You can also manually pass the bucket and s3Prefix:

Partitions

To improve query performance, a table can specify partitionKeys on which data is stored and queried separately. For example, you might partition a table by year and month to optimize queries based on a time window:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
         .database(myDatabase)
         .tableName("my_table")
         .columns(asList(Map.of(
                 "name", "col1",
                 "type", glue.Schema.getSTRING())))
         .partitionKeys(asList(Map.of(
                 "name", "year",
                 "type", glue.Schema.getSMALL_INT()), Map.of(
                 "name", "month",
                 "type", glue.Schema.getSMALL_INT())))
         .dataFormat(glue.DataFormat.getJSON())
         .build();
 

Encryption

You can enable encryption on a Table's data:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getS3_MANAGED())...
         .build();
 

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 // KMS key is created automatically
 // KMS key is created automatically
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getKMS())...
         .build();
 
 // with an explicit KMS key
 // with an explicit KMS key
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getKMS())
         .encryptionKey(new Key(stack, "MyKey"))...
         .build();
 

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getKMS_MANAGED())...
         .build();
 

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 // KMS key is created automatically
 // KMS key is created automatically
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getCLIENT_SIDE_KMS())...
         .build();
 
 // with an explicit KMS key
 // with an explicit KMS key
 Table.Builder.create(stack, "MyTable")
         .encryption(glue.TableEncryption.getCLIENT_SIDE_KMS())
         .encryptionKey(new Key(stack, "MyKey"))...
         .build();
 

Note: you cannot provide a Bucket when creating the Table if you wish to use server-side encryption (KMS, KMS_MANAGED or S3_MANAGED).

Types

A table's schema is a collection of columns, each of which have a name and a type. Types are recursive structures, consisting of primitive and complex types:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Table.Builder.create(stack, "MyTable")
 .columns(asList(Map.of(
         "name", "primitive_column",
         "type", glue.Schema.getSTRING()), Map.of(
         "name", "array_column",
         "type", glue.Schema.array(glue.Schema.getINTEGER()),
         "comment", "array<integer>"), Map.of(
         "name", "map_column",
         "type", glue.Schema.map(glue.Schema.getSTRING(), glue.Schema.getTIMESTAMP()),
         "comment", "map<string,string>"), Map.of(
         "name", "struct_column",
         "type", glue.Schema.struct(asList(Map.of(
                 "name", "nested_column",
                 "type", glue.Schema.getDATE(),
                 "comment", "nested comment"))),
         "comment", "struct<nested_column:date COMMENT 'nested comment'>")))...
 .build();
 

Primitives

Numeric

| Name | Type | Comments | |----------- |---------- |------------------------------------------------------------------------------------------------------------------ | | FLOAT | Constant | A 32-bit single-precision floating point number | | INTEGER | Constant | A 32-bit signed value in two's complement format, with a minimum value of -2^31 and a maximum value of 2^31-1 | | DOUBLE | Constant | A 64-bit double-precision floating point number | | BIG_INT | Constant | A 64-bit signed INTEGER in two’s complement format, with a minimum value of -2^63 and a maximum value of 2^63 -1 | | SMALL_INT | Constant | A 16-bit signed INTEGER in two’s complement format, with a minimum value of -2^15 and a maximum value of 2^15-1 | | TINY_INT | Constant | A 8-bit signed INTEGER in two’s complement format, with a minimum value of -2^7 and a maximum value of 2^7-1 |

Date and time

| Name | Type | Comments | |----------- |---------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | DATE | Constant | A date in UNIX format, such as YYYY-MM-DD. | | TIMESTAMP | Constant | Date and time instant in the UNiX format, such as yyyy-mm-dd hh:mm:ss[.f...]. For example, TIMESTAMP '2008-09-15 03:04:05.324'. This format uses the session time zone. |

String

| Name | Type | Comments | |-------------------------------------------- |---------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | STRING | Constant | A string literal enclosed in single or double quotes | | decimal(precision: number, scale?: number) | Function | precision is the total number of digits. scale (optional) is the number of digits in fractional part with a default of 0. For example, use these type definitions: decimal(11,5), decimal(15) | | char(length: number) | Function | Fixed length character data, with a specified length between 1 and 255, such as char(10) | | varchar(length: number) | Function | Variable length character data, with a specified length between 1 and 65535, such as varchar(10) |

Miscellaneous

| Name | Type | Comments | |--------- |---------- |------------------------------- | | BOOLEAN | Constant | Values are true and false | | BINARY | Constant | Value is in binary |

Complex

| Name | Type | Comments | |------------------------------------- |---------- |------------------------------------------------------------------- | | array(itemType: Type) | Function | An array of some other type | | map(keyType: Type, valueType: Type) | Function | A map of some primitive key type to any value type | | struct(collumns: Column[]) | Function | Nested structure containing individually named and typed collumns |

Skip navigation links