Skip to content
v2.278.0

AWS::LakeFormation Construct Library ​

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

ts
import * as lakeformation from 'aws-cdk-lib/aws-lakeformation';
python
import aws_cdk.aws_lakeformation as lakeformation
java
import software.amazon.awscdk.services.lakeformation.*;
csharp
using Amazon.CDK.AWS.LakeFormation;
go
import lakeformation "github.com/aws/aws-cdk-go/awscdk"

There are no official hand-written (L2) constructs for this service yet. Here are some suggestions on how to proceed:

There are no hand-written (L2) constructs for this service yet. However, you can still use the automatically generated L1 constructs, and use this service exactly as you would using CloudFormation directly.

For more information on the resources and properties available for this service, see the CloudFormation documentation for AWS::LakeFormation.

(Read the CDK Contributing Guide and submit an RFC if you are interested in contributing to this construct library.)

Example ​

Here is an example of creating a glue table and putting lakeformation tags on it. Note: this example uses deprecated constructs and overly permissive IAM roles. This example is meant to give a general idea of using the L1s; it is not production level.

ts
import * as cdk from 'aws-cdk-lib';
import { S3Table, Database, DataFormat, Schema } from 'aws-cdk-lib/aws-glue';
import { CfnDataLakeSettings, CfnTag, CfnTagAssociation } from 'aws-cdk-lib/aws-lakeformation';

declare const stack: cdk.Stack;
declare const accountId: string;

const tagKey = 'aws';
const tagValues = ['dev'];

const database = new Database(this, 'Database');

const table = new S3Table(this, 'Table', {
  database,
  columns: [
    {
      name: 'col1',
      type: Schema.STRING,
    },
    {
      name: 'col2',
      type: Schema.STRING,
    }
  ],
  dataFormat: DataFormat.CSV,
});

const synthesizer = stack.synthesizer as cdk.DefaultStackSynthesizer;
new CfnDataLakeSettings(this, 'DataLakeSettings', {
  admins: [
    {
      dataLakePrincipalIdentifier: stack.formatArn({
        service: 'iam',
        resource: 'role',
        region: '',
        account: accountId,
        resourceName: 'Admin',
      }),
    },
    {
      // The CDK cloudformation execution role.
      dataLakePrincipalIdentifier: synthesizer.cloudFormationExecutionRoleArn.replace('${AWS::Partition}', 'aws'),
    },
  ],
});

const tag = new CfnTag(this, 'Tag', {
  catalogId: accountId,
  tagKey,
  tagValues,
});

const lfTagPairProperty: CfnTagAssociation.LFTagPairProperty = {
  catalogId: accountId,
  tagKey,
  tagValues,
};

const tagAssociation = new CfnTagAssociation(this, 'TagAssociation', {
  lfTags: [lfTagPairProperty],
  resource: {
    tableWithColumns: {
      databaseName: database.databaseName,
      columnNames: ['col1', 'col2'],
      catalogId: accountId,
      name: table.tableName,
    }
  }
});

tagAssociation.node.addDependency(tag);
tagAssociation.node.addDependency(table);
python
import aws_cdk as cdk
from aws_cdk.aws_glue import S3Table, Database, DataFormat, Schema
from aws_cdk.aws_lakeformation import CfnDataLakeSettings, CfnTag, CfnTagAssociation

# stack: cdk.Stack
# account_id: str


tag_key = "aws"
tag_values = ["dev"]

database = Database(self, "Database")

table = S3Table(self, "Table",
    database=database,
    columns=[cdk.aws_glue.Column(
        name="col1",
        type=Schema.STRING
    ), cdk.aws_glue.Column(
        name="col2",
        type=Schema.STRING
    )
    ],
    data_format=DataFormat.CSV
)

synthesizer = stack.synthesizer
CfnDataLakeSettings(self, "DataLakeSettings",
    admins=[CfnDataLakeSettings.DataLakePrincipalProperty(
        data_lake_principal_identifier=stack.format_arn(
            service="iam",
            resource="role",
            region="",
            account=account_id,
            resource_name="Admin"
        )
    ), CfnDataLakeSettings.DataLakePrincipalProperty(
        # The CDK cloudformation execution role.
        data_lake_principal_identifier=synthesizer.cloud_formation_execution_role_arn.replace("${AWS::Partition}", "aws")
    )
    ]
)

tag = CfnTag(self, "Tag",
    catalog_id=account_id,
    tag_key=tag_key,
    tag_values=tag_values
)

lf_tag_pair_property = CfnTagAssociation.LFTagPairProperty(
    catalog_id=account_id,
    tag_key=tag_key,
    tag_values=tag_values
)

tag_association = CfnTagAssociation(self, "TagAssociation",
    lf_tags=[lf_tag_pair_property],
    resource=CfnTagAssociation.ResourceProperty(
        table_with_columns=CfnTagAssociation.TableWithColumnsResourceProperty(
            database_name=database.database_name,
            column_names=["col1", "col2"],
            catalog_id=account_id,
            name=table.table_name
        )
    )
)

tag_association.node.add_dependency(tag)
tag_association.node.add_dependency(table)
java
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.glue.S3Table;
import software.amazon.awscdk.services.glue.Database;
import software.amazon.awscdk.services.glue.DataFormat;
import software.amazon.awscdk.services.glue.Schema;
import software.amazon.awscdk.services.lakeformation.CfnDataLakeSettings;
import software.amazon.awscdk.services.lakeformation.CfnTag;
import software.amazon.awscdk.services.lakeformation.CfnTagAssociation;

Stack stack;
String accountId;


String tagKey = "aws";
String[] tagValues = List.of("dev");

Database database = new Database(this, "Database");

S3Table table = S3Table.Builder.create(this, "Table")
        .database(database)
        .columns(List.of(Column.builder()
                .name("col1")
                .type(Schema.STRING)
                .build(), Column.builder()
                .name("col2")
                .type(Schema.STRING)
                .build()))
        .dataFormat(DataFormat.CSV)
        .build();

DefaultStackSynthesizer synthesizer = (DefaultStackSynthesizer)stack.getSynthesizer();
CfnDataLakeSettings.Builder.create(this, "DataLakeSettings")
        .admins(List.of(DataLakePrincipalProperty.builder()
                .dataLakePrincipalIdentifier(stack.formatArn(ArnComponents.builder()
                        .service("iam")
                        .resource("role")
                        .region("")
                        .account(accountId)
                        .resourceName("Admin")
                        .build()))
                .build(), DataLakePrincipalProperty.builder()
                // The CDK cloudformation execution role.
                .dataLakePrincipalIdentifier(synthesizer.cloudFormationExecutionRoleArn.replace("${AWS::Partition}", "aws"))
                .build()))
        .build();

CfnTag tag = CfnTag.Builder.create(this, "Tag")
        .catalogId(accountId)
        .tagKey(tagKey)
        .tagValues(tagValues)
        .build();

LFTagPairProperty lfTagPairProperty = LFTagPairProperty.builder()
        .catalogId(accountId)
        .tagKey(tagKey)
        .tagValues(tagValues)
        .build();

CfnTagAssociation tagAssociation = CfnTagAssociation.Builder.create(this, "TagAssociation")
        .lfTags(List.of(lfTagPairProperty))
        .resource(ResourceProperty.builder()
                .tableWithColumns(TableWithColumnsResourceProperty.builder()
                        .databaseName(database.getDatabaseName())
                        .columnNames(List.of("col1", "col2"))
                        .catalogId(accountId)
                        .name(table.getTableName())
                        .build())
                .build())
        .build();

tagAssociation.node.addDependency(tag);
tagAssociation.node.addDependency(table);
csharp
using Amazon.CDK;
using Amazon.CDK.AWS.Glue;
using Amazon.CDK.AWS.LakeFormation;

Stack stack;
string accountId;


var tagKey = "aws";
var tagValues = new [] { "dev" };

var database = new Database(this, "Database");

var table = new S3Table(this, "Table", new S3TableProps {
    Database = database,
    Columns = new [] { new Column {
        Name = "col1",
        Type = Schema.STRING
    }, new Column {
        Name = "col2",
        Type = Schema.STRING
    } },
    DataFormat = DataFormat.CSV
});

var synthesizer = (DefaultStackSynthesizer)stack.Synthesizer;
new CfnDataLakeSettings(this, "DataLakeSettings", new CfnDataLakeSettingsProps {
    Admins = new [] { new DataLakePrincipalProperty {
        DataLakePrincipalIdentifier = stack.FormatArn(new ArnComponents {
            Service = "iam",
            Resource = "role",
            Region = "",
            Account = accountId,
            ResourceName = "Admin"
        })
    }, new DataLakePrincipalProperty {
        // The CDK cloudformation execution role.
        DataLakePrincipalIdentifier = synthesizer.CloudFormationExecutionRoleArn.Replace("${AWS::Partition}", "aws")
    } }
});

var tag = new CfnTag(this, "Tag", new CfnTagProps {
    CatalogId = accountId,
    TagKey = tagKey,
    TagValues = tagValues
});

var lfTagPairProperty = new LFTagPairProperty {
    CatalogId = accountId,
    TagKey = tagKey,
    TagValues = tagValues
};

var tagAssociation = new CfnTagAssociation(this, "TagAssociation", new CfnTagAssociationProps {
    LfTags = new [] { lfTagPairProperty },
    Resource = new ResourceProperty {
        TableWithColumns = new TableWithColumnsResourceProperty {
            DatabaseName = database.DatabaseName,
            ColumnNames = new [] { "col1", "col2" },
            CatalogId = accountId,
            Name = table.TableName
        }
    }
});

tagAssociation.Node.AddDependency(tag);
tagAssociation.Node.AddDependency(table);
go
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var stack Stack
var accountId string


tagKey := "aws"
tagValues := []*string{
	"dev",
}

database := awscdk.NewDatabase(this, jsii.String("Database"))

table := awscdk.NewS3Table(this, jsii.String("Table"), &S3TableProps{
	Database: Database,
	Columns: []Column{
		&Column{
			Name: jsii.String("col1"),
			Type: awscdk.Schema_STRING(),
		},
		&Column{
			Name: jsii.String("col2"),
			Type: awscdk.Schema_STRING(),
		},
	},
	DataFormat: awscdk.DataFormat_CSV(),
})

synthesizer := stack.Synthesizer.(DefaultStackSynthesizer)
awscdk.NewCfnDataLakeSettings(this, jsii.String("DataLakeSettings"), &CfnDataLakeSettingsProps{
	Admins: []interface{}{
		&DataLakePrincipalProperty{
			DataLakePrincipalIdentifier: stack.FormatArn(&ArnComponents{
				Service: jsii.String("iam"),
				Resource: jsii.String("role"),
				Region: jsii.String(""),
				Account: accountId,
				ResourceName: jsii.String("Admin"),
			}),
		},
		&DataLakePrincipalProperty{
			// The CDK cloudformation execution role.
			DataLakePrincipalIdentifier: synthesizer.cloudFormationExecutionRoleArn.replace(jsii.String("${AWS::Partition}"), jsii.String("aws")),
		},
	},
})

tag := awscdk.NewCfnTag(this, jsii.String("Tag"), &CfnTagProps{
	CatalogId: accountId,
	TagKey: jsii.String(TagKey),
	TagValues: TagValues,
})

lfTagPairProperty := &LFTagPairProperty{
	CatalogId: accountId,
	TagKey: jsii.String(TagKey),
	TagValues: TagValues,
}

tagAssociation := awscdk.NewCfnTagAssociation(this, jsii.String("TagAssociation"), &CfnTagAssociationProps{
	LfTags: []interface{}{
		lfTagPairProperty,
	},
	Resource: &ResourceProperty{
		TableWithColumns: &TableWithColumnsResourceProperty{
			DatabaseName: database.databaseName,
			ColumnNames: []*string{
				jsii.String("col1"),
				jsii.String("col2"),
			},
			CatalogId: accountId,
			Name: table.tableName,
		},
	},
})

tagAssociation.Node.AddDependency(tag)
tagAssociation.Node.AddDependency(table)

Additionally, you may need to use the lakeformation console to give permissions, particularly to give the cdk-exec-role tagging permissions.

Types ​

Constructs (L1) ​

  • CfnDataCellsFilter Construct (L1)
    A structure that represents a data cell filter with column-level, row-level, and/or cell-level security.
  • CfnDataLakeSettings Construct (L1)
    The AWS::LakeFormation::DataLakeSettings resource is an AWS Lake Formation resource type that manages the data lake settings for your account.
  • CfnPermissions Construct (L1)
    The AWS::LakeFormation::Permissions resource represents the permissions that a principal has on an AWS Glue Data Catalog resource (such as AWS Glue database or AWS Glue tables).
  • CfnPrincipalPermissions Construct (L1)
    The AWS::LakeFormation::PrincipalPermissions resource represents the permissions that a principal has on a Data Catalog resource (such as AWS Glue databases or AWS Glue tables).
  • CfnResource Construct (L1)
    The AWS::LakeFormation::Resource represents the data ( buckets and folders) that is being registered with AWS Lake Formation .
  • CfnTag Construct (L1)
    The AWS::LakeFormation::Tag resource represents an LF-tag, which consists of a key and one or more possible values for the key.
  • CfnTagAssociation Construct (L1)
    The AWS::LakeFormation::TagAssociation resource represents an assignment of an LF-tag to a Data Catalog resource (database, table, or column).

Structs ​