湖形成标记 L3 构造
这个软件包为管理AWS湖形成标记及其关联提供了两种构造,并提供了基于标记的访问控制(TBAC)的数据资源.
概览
Lake Formation tags(LF-Tags)是可附加到数据目录资源(数据库,表格,列)中的密钥值对. 这些标签允许基于属性的访问控制,允许您根据标签表达式而不是单个资源授予权限.
此套件将标签创建从标签关联区分为两个不同的构件:
- 湖边建筑: 在账户一级创建 LF- Tags
- 湖边论坛协会L3 建设: 具有数据库和表格的现有标签
构造
湖边建筑
在账户级别创建 LF- Tags 。 这些标记定义了基于标记的访问控制词汇,可以被多数据库和表格重复使用.
使用量
import { LakeFormationTagsL3Construct } from '@aws-mdaa/lakeformation-tags-l3-construct';
const tagsConstruct = new LakeFormationTagsL3Construct(this, 'ProjectLFTags', {
lfTags: [
{
tagKey: 'environment',
tagValues: ['dev', 'test', 'prod'],
},
{
tagKey: 'data_tier',
tagValues: ['bronze', 'silver', 'gold'],
},
],
});
属性
lfTags(需要):数量LFTagConfig定义要创建的标签的对象
LFtag 图形
tagKey(需要):湖形成标记的密钥(名称)tagValues( 需要): 此标签的允许值阵列catalogId(可选) : 创建标签的目录 ID( 默认为当前账户)
湖边论坛协会L3 建设
拥有数据库和表格的现有LF-Tag。 此构造假设标记已经创建 .
使用量
import {
LakeFormationTagsL3Construct,
LakeFormationTagAssociationL3Construct
} from '@aws-mdaa/lakeformation-tags-l3-construct';
// First, create the tags
const tagsConstruct = new LakeFormationTagsL3Construct(this, 'ProjectLFTags', {
lfTags: [
{
tagKey: 'environment',
tagValues: ['dev', 'test', 'prod'],
},
{
tagKey: 'data_tier',
tagValues: ['bronze', 'silver', 'gold'],
},
],
});
// Then, associate tags with a database
new LakeFormationTagAssociationL3Construct(this, 'DatabaseTagAssociation', {
databaseName: 'my-database',
tagValues: [
{
tagKey: 'environment',
tagValues: ['prod'],
},
{
tagKey: 'data_tier',
tagValues: ['gold'],
},
],
projectLevelTagsConstruct: tagsConstruct, // Ensures tags exist before association
});
// Optionally, associate tags with specific tables
new LakeFormationTagAssociationL3Construct(this, 'TableTagAssociation', {
databaseName: 'my-database',
tables: ['table1', 'table2'],
tagValues: [
{
tagKey: 'environment',
tagValues: ['prod'],
},
],
projectLevelTagsConstruct: tagsConstruct,
});
属性
databaseName(需要):将标签与tagValues(需要):数量LFTagConfig指定要关联的标签值的对象projectLevelTagsConstruct(可选):参考创建标记的构造(用于依赖管理)tables(可选) : 特定表格名称的组合到关联标记
完整示例
import {
LakeFormationTagsL3Construct,
LakeFormationTagAssociationL3Construct
} from '@aws-mdaa/lakeformation-tags-l3-construct';
// Step 1: Create account-level tags
const tagsConstruct = new LakeFormationTagsL3Construct(this, 'OrgLFTags', {
lfTags: [
{
tagKey: 'environment',
tagValues: ['dev', 'test', 'prod'],
},
{
tagKey: 'data_tier',
tagValues: ['bronze', 'silver', 'gold'],
},
{
tagKey: 'pii',
tagValues: ['true', 'false'],
},
],
});
// Step 2: Associate tags with production database
new LakeFormationTagAssociationL3Construct(this, 'ProdDatabaseTags', {
databaseName: 'production-db',
tagValues: [
{ tagKey: 'environment', tagValues: ['prod'] },
{ tagKey: 'data_tier', tagValues: ['gold'] },
],
projectLevelTagsConstruct: tagsConstruct,
});
// Step 3: Associate tags with specific sensitive tables
new LakeFormationTagAssociationL3Construct(this, 'SensitiveTableTags', {
databaseName: 'production-db',
tables: ['customers', 'transactions'],
tagValues: [
{ tagKey: 'pii', tagValues: ['true'] },
],
projectLevelTagsConstruct: tagsConstruct,
});
最佳做法
- 关注的分离: 在账户一级创建标签一次, 然后根据需要将其与多个资源关联
- 标记命名: 对标记键使用一致的命名惯例( 如: snake case)
- 标记值: 在标签创建步骤中定义所有可能的值,以确保标记的一致性
- 依赖关系: 总是通过
projectLevelTagsConstruct在创建协会之前确保标签存在 - 可续用性: 账户级别标签可在多个数据库和表格中重复使用
相关构造
LakeFormationTagBasedPermissionsL3Construct: 根据 LF-Tag 表达式授予权限LakeFormationAccessControlL3Construct: 传统资源型湖形成许可