aws::glue的cdk构造库
aws-cdk.aws-glue的Python项目详细描述
aws glue构造库
This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.
This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.
这个模块是AWS Cloud Development Kit项目的一部分。
数据库
Database
是胶水目录中Tables
的逻辑分组。
newglue.Database(stack,'MyDatabase',{databaseName:'my_database'});
默认情况下,会创建一个s3 bucket,数据库存储在s3://<bucket-name>/
下,但您可以手动指定另一个位置:
newglue.Database(stack,'MyDatabase',{databaseName:'my_database',locationUri:'s3://explicit-bucket/some-path/'});
表
glue表描述s3中的数据表:它的结构(列名和类型)、数据的位置(s3 bucket中具有公共前缀的s3对象)和文件的格式(json、avro、parquet等):
newglue.Table(stack,'MyTable',{database: myDatabase,tableName:'my_table',columns:[{name:'col1',type: glue.Schema.string,},{name:'col2',type: glue.Schema.array(Schema.string),comment:'col2 is an array of strings'// comment is optional}]dataFormat: glue.DataFormat.Json});
默认情况下,将创建一个s3 bucket来存储表的数据,但是您可以手动传递bucket
和s3Prefix
:
newglue.Table(stack,'MyTable',{bucket: myBucket,s3Prefix:'my-table/'...});
分区
为了提高查询性能,表可以指定单独存储和查询数据的partitionKeys
。例如,可以通过year
和month
对表进行分区,以基于时间窗口优化查询:
newglue.Table(stack,'MyTable',{database: myDatabase,tableName:'my_table',columns:[{name:'col1',type: glue.Schema.string}],partitionKeys:[{name:'year',type: glue.Schema.smallint},{name:'month',type: glue.Schema.smallint}],dataFormat: glue.DataFormat.Json});
Encryption
您可以对表的数据启用加密:
Unencrypted
-文件未加密。默认加密设置。- S3Managed-使用amazon s3托管密钥的服务器端加密(
SSE-S3
)。
newglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.S3Managed...});
- Kms-使用由帐户所有者管理的aws kms密钥的服务器端加密(
SSE-KMS
)。
// KMS key is created automaticallynewglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.Kms...});// with an explicit KMS keynewglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.Kms,encryptionKey: newkms.Key(stack,'MyKey')...});
- KmsManaged-服务器端加密(
SSE-KMS
),类似于Kms
,但aws密钥管理服务管理的aws kms密钥除外。
newglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.KmsManaged...});
- ClientSideKms-客户端加密(
CSE-KMS
),使用由帐户所有者管理的aws kms密钥。
// KMS key is created automaticallynewglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.ClientSideKms...});// with an explicit KMS keynewglue.Table(stack,'MyTable',{encryption: glue.TableEncryption.ClientSideKms,encryptionKey: newkms.Key(stack,'MyKey')...});
注意:如果希望使用服务器端加密(Kms
、KmsManaged
或S3Managed
),则在创建Table
时不能提供Bucket
。
类型
表的模式是列的集合,每个列都有一个name
和一个type
。类型是递归结构,由原始类型和复杂类型组成:
newglue.Table(stack,'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'>"}],...
原语
数字:
bigint
float
integer
smallint
tinyint
日期和时间:
date
timestamp
字符串类型:
string
decimal
char
varchar
其他:
boolean
binary
复杂的
array
-其他类型的数组map
-将某个基元键类型映射到任何值类型。struct
-包含单独命名和类型化列的嵌套结构。