AWS 粘结构造库
AWS CDK v1在2023-06-01上达到了支持结束. 此软件包不再更新,用户应该迁移到 AWS CDK v2.
关于如何移徙的更多信息,请参见: 移动到 AWS CDK v2 指南。 。 。 .
这个模块是 AWS 云开发套件 项目.
任务
A 类 Job 封装连接数据源的脚本,对其进行处理,然后将输出写入数据目标.
AWS Glue 支持的工作有3个类型: Spark ETL, Spark Streaming, 和 Python Shell 工作.
这个 glue.JobExecutable 允许您指定任务类型、使用的语言和任务所需的代码资产.
glue.Code 允许您从现有的 S3 位置或本地文件路径引用任务所需的不同代码资产.
火花任务
这些工作在 AWS Glue 管理的 Apache Spark 环境中运行 .
ETL 作业
使用 Apache Spark 批次处理 ETL 工作数据 .
declare const bucket: s3.Bucket;
new glue.Job(this, 'ScalaSparkEtlJob', {
executable: glue.JobExecutable.scalaEtl({
glueVersion: glue.GlueVersion.V2_0,
script: glue.Code.fromBucket(bucket, 'src/com/example/HelloWorld.scala'),
className: 'com.example.HelloWorld',
extraJars: [glue.Code.fromBucket(bucket, 'jars/HelloWorld.jar')],
}),
description: 'an example Scala ETL job',
});
流动工作
流线工作类似于ETL工作,只是它在数据流上执行ETL. 它使用Apache Spark结构流式框架. 一些 Spark 工作特性无法流出 ETL 工作 .
new glue.Job(this, 'PythonSparkStreamingJob', {
executable: glue.JobExecutable.pythonStreaming({
glueVersion: glue.GlueVersion.V2_0,
pythonVersion: glue.PythonVersion.THREE,
script: glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py')),
}),
description: 'an example Python Streaming job',
});
Python 贝壳作业
一个 Python shell 任务将 Python 脚本作为 shell 运行,并支持一个依赖于您正在使用的 AWS Glue 版本的 Python 版本. 这可用于安排和运行不需要Apache Spark环境的任务.
declare const bucket: s3.Bucket;
new glue.Job(this, 'PythonShellJob', {
executable: glue.JobExecutable.pythonShell({
glueVersion: glue.GlueVersion.V1_0,
pythonVersion: glue.PythonVersion.THREE,
script: glue.Code.fromBucket(bucket, 'script.py'),
}),
description: 'an example Python Shell job',
});
见 文档 用于获取有关在Glue中添加工作的更多信息.
连接
A 类 Connection 允许 Glue 任务,爬行者和开发端点访问某些类型的数据存储. 例如,要创建网络连接以连接VPC内的数据源:
declare const securityGroup: ec2.SecurityGroup;
declare const subnet: ec2.Subnet;
new glue.Connection(this, 'MyConnection', {
type: glue.ConnectionType.NETWORK,
// The security groups granting AWS Glue inbound access to the data source within the VPC
securityGroups: [securityGroup],
// The VPC subnet which contains the data source
subnet,
});
如果您需要使用一个不存在作为静态成员的连接类型 ConnectionType你可以即兴表演 ConnectionType 对象,例如: new glue.ConnectionType('NEW_TYPE')。 。 。 .
见 正在将连接添加到您的数据库 财务报告和审定财务报表 连接结构 文档中关于所支持的数据存储及其配置的更多信息.
安全配置
A 类 SecurityConfiguration 是一组安全属性,可用于AWS Glue在休息时加密数据.
new glue.SecurityConfiguration(this, 'MySecurityConfiguration', {
securityConfigurationName: 'name',
cloudWatchEncryption: {
mode: glue.CloudWatchEncryptionMode.KMS,
},
jobBookmarksEncryption: {
mode: glue.JobBookmarksEncryptionMode.CLIENT_SIDE_KMS,
},
s3Encryption: {
mode: glue.S3EncryptionMode.KMS,
},
});
默认情况下,会创建一个共享的 KMS 密钥,与需要的加密配置一起使用. 您也可以为每个加密配置提供自己的密钥, 例如用于 Cloud Watch 加密 :
declare const key: kms.Key;
new glue.SecurityConfiguration(this, 'MySecurityConfiguration', {
securityConfigurationName: 'name',
cloudWatchEncryption: {
mode: glue.CloudWatchEncryptionMode.KMS,
kmsKey: key,
},
});
见 文档 用于 Glue 加密由 Crawlers, Jobs, and Development Endpoints 编写的数据.
数据库
A 类 Database 是逻辑组合 Tables 在胶片目录.
new glue.Database(this, 'MyDatabase', {
databaseName: 'my_database',
});
图表
Glue表描述了S3中的数据表格:其结构(列名和类型),数据位置(S3对象在S3桶中有一个共同的前缀),以及文件格式(Json, Avro, Parquet等)
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}, {
name: 'col2',
type: glue.Schema.array(glue.Schema.STRING),
comment: 'col2 is an array of strings' // comment is optional
}],
dataFormat: glue.DataFormat.JSON,
});
默认情况下, 将会创建 S3 桶来存储表格的数据, 但您可以手动通过 bucket 财务报告和审定财务报表 s3Prefix数字 :
declare const myBucket: s3.Bucket;
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
bucket: myBucket,
s3Prefix: 'my-table/',
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
默认情况下,将创建一个S3桶来存储表格的数据并存储到桶根. 您也可以手动通过 bucket 财务报告和审定财务报表 s3Prefix数字 :
分区密钥
为了提高查询性能,表格可以指定 partitionKeys 数据分别存储和询问。 例如,您可以将表格按 year 财务报告和审定财务报表 month 以时间窗口优化查询:
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
partitionKeys: [{
name: 'year',
type: glue.Schema.SMALL_INT,
}, {
name: 'month',
type: glue.Schema.SMALL_INT,
}],
dataFormat: glue.DataFormat.JSON,
});
分区索引
提高查询性能的另一种方法是指定分区索引. 如果没有分区索引 在表格中显示, AWS 粘贴加载表格的所有分区并使用 查询表达式。 随着分区数量的增加,查询需要更多的时间来运行. 与一个 索引,查询将尝试取取分区的子集,而不是装入分区的全部分区 页:1.
分区索引的密钥必须是表格分区密钥的一个子集. 你可以有一个
每个表格最多3个分区索引。 要指定分区索引, 您可以使用 partitionIndexes
属性 :
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
partitionKeys: [{
name: 'year',
type: glue.Schema.SMALL_INT,
}, {
name: 'month',
type: glue.Schema.SMALL_INT,
}],
partitionIndexes: [{
indexName: 'my-index', // optional
keyNames: ['year'],
}], // supply up to 3 indexes
dataFormat: glue.DataFormat.JSON,
});
或者,你可以打电话 addPartitionIndex() 表格上的函数 :
declare const myTable: glue.Table;
myTable.addPartitionIndex({
indexName: 'my-index',
keyNames: ['year'],
});
加密
您可以启用表格数据的加密 :
Unencrypted- 文件没有加密。 默认加密设置 .- S3 管理 - 服务器侧加密(
SSE-S3) 有亚马逊S3管理的密钥.
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.S3_MANAGED,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
- 键 - 服务器端加密(
SSE-KMSAWS KMS 密钥由账户所有人管理.
declare const myDatabase: glue.Database;
// KMS key is created automatically
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.KMS,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
// with an explicit KMS key
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.KMS,
encryptionKey: new kms.Key(this, 'MyKey'),
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
- 管理 - 服务器端加密(
SSE-KMS比如说Kms,但有一个由 AWS 密钥管理处管理的 AWS KMS 密钥除外.
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.KMS_MANAGED,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
- 客户端 - 客户端加密(
CSE-KMSAWS KMS 密钥由账户所有人管理.
declare const myDatabase: glue.Database;
// KMS key is created automatically
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.CLIENT_SIDE_KMS,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
// with an explicit KMS key
new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.CLIENT_SIDE_KMS,
encryptionKey: new kms.Key(this, 'MyKey'),
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
}],
dataFormat: glue.DataFormat.JSON,
});
注意: 您无法提供 Bucket 创建时 Table 如果您想要使用服务器侧加密( u)KMS, (中文(简体) ), KMS_MANAGED 或者说 S3_MANAGED(中文(简体) )。 。 。 .
类型
一张桌子的图案是一列,每列都有 name (单位:千美元) type类型是递归结构,由原始和复杂的类型组成:
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
columns: [{
name: 'primitive_column',
type: glue.Schema.STRING,
}, {
name: 'array_column',
type: glue.Schema.array(glue.Schema.INTEGER),
comment: 'array<integer>',
}, {
name: 'map_column',
type: glue.Schema.map(
glue.Schema.STRING,
glue.Schema.TIMESTAMP),
comment: 'map<string,string>',
}, {
name: 'struct_column',
type: glue.Schema.struct([{
name: 'nested_column',
type: glue.Schema.DATE,
comment: 'nested comment',
}]),
comment: "struct<nested_column:date COMMENT 'nested comment'>",
}],
// ...
database: myDatabase,
tableName: 'my_table',
dataFormat: glue.DataFormat.JSON,
});
初级
数字
| 名称 | 类型 | 评论 |
|---|---|---|
| 浮图 | 常数 | 32 位单精度浮点数 |
| 进口 | 常数 | 一个32位的签名值,以两个补充格式,最小值为-2^31,最大值为-2^31- 1个 |
| 丢弃 | 常数 | 64位双精度浮点数 |
| 大键 | 常数 | 一个64位签名的INTEGER,以两个补充格式,最小值为-2^63,最大值为-2^63-1 |
| 小型小号 | 常数 | 一个16位签名的INTEGER,以两个补充格式,最小值为-2^15,最大值为-2^15- 1个 |
| 小叮当 INT | 常数 | 一个8位签名的INTEGER,2个补充格式,最小值为-2^7,最大值为-2^7- 1个 |
日期和时间
| 名称 | 类型 | 评论 |
|---|---|---|
| 日期 | 常数 | 一个UNIX格式的日期,例如YYY-MM-DD. |
| 时间 | 常数 | 在UNiX格式中的日期和时间即时,如yyy-mm-dd hh:mm:s[.f.]. 例如,TIMESTAMP '2008-09-15 03:04:05.324'. 此格式使用会话时区. |
字符串
| 名称 | 类型 | 评论 |
|---|---|---|
| 绳子 | 常数 | 以单引号或双引号附加的字符串文字 |
| 小数点( 精度: 数字, 缩放? ) | 函数 | precision 是数字的总数. scale (可选)是分数部分的位数,默认为0. 例如,使用这些类型定义:小数(11,5),小数(15) |
| 字符( 长度: 数字) | 函数 | 固定长度字符数据, 指定长度在 1 至 255 之间, 如 char(10) |
| varchar(长:数字) | 函数 | 可变长度字符数据,具体长度介于1至65535之间,例如 varchar(10) |
杂项
| 名称 | 类型 | 评论 |
|---|---|---|
| 玻利维亚 | 常数 | 值为 true 财务报告和审定财务报表 false |
| 比利时 | 常数 | 值为二进制 |
复杂
| 名称 | 类型 | 评论 |
|---|---|---|
| 数组( 项目类型: 类型) | 函数 | 其他类型的数组 |
| 映射( 密钥类型: 类型, 值) | 函数 | 某个原始密钥类型的映射到任何值类型的地图 |
| struct(列:列 []) | 函数 | 包含单独命名和打入的圆柱形结构 |