Skip to content
v2.278.0

CsvOptions Struct ​

The options for imported source files in CSV format.

Example ​

ts
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');

declare const bucket: s3.IBucket;

new dynamodb.Table(stack, 'Table', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
  importSource: {
    compressionType: dynamodb.InputCompressionType.GZIP,
    inputFormat: dynamodb.InputFormat.csv({
      delimiter: ',',
      headerList: ['id', 'name'],
    }),
    bucket,
    keyPrefix: 'prefix',
  },
});
python
import aws_cdk as cdk
import aws_cdk.aws_s3 as s3

# bucket: s3.IBucket


app = cdk.App()
stack = cdk.Stack(app, "Stack")

dynamodb.Table(stack, "Table",
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING
    ),
    import_source=dynamodb.ImportSourceSpecification(
        compression_type=dynamodb.InputCompressionType.GZIP,
        input_format=dynamodb.InputFormat.csv(
            delimiter=",",
            header_list=["id", "name"]
        ),
        bucket=bucket,
        key_prefix="prefix"
    )
)
java
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.s3.*;

IBucket bucket;


App app = new App();
Stack stack = new Stack(app, "Stack");

Table.Builder.create(stack, "Table")
        .partitionKey(Attribute.builder()
                .name("id")
                .type(AttributeType.STRING)
                .build())
        .importSource(ImportSourceSpecification.builder()
                .compressionType(InputCompressionType.GZIP)
                .inputFormat(InputFormat.csv(CsvOptions.builder()
                        .delimiter(",")
                        .headerList(List.of("id", "name"))
                        .build()))
                .bucket(bucket)
                .keyPrefix("prefix")
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
using Amazon.CDK.AWS.S3;

IBucket bucket;


var app = new App();
var stack = new Stack(app, "Stack");

new Table(stack, "Table", new TableProps {
    PartitionKey = new Attribute {
        Name = "id",
        Type = AttributeType.STRING
    },
    ImportSource = new ImportSourceSpecification {
        CompressionType = InputCompressionType.GZIP,
        InputFormat = InputFormat.Csv(new CsvOptions {
            Delimiter = ",",
            HeaderList = new [] { "id", "name" }
        }),
        Bucket = bucket,
        KeyPrefix = "prefix"
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import s3 "github.com/aws/aws-cdk-go/awscdk"

var bucket IBucket


app := cdk.NewApp()
stack := cdk.NewStack(app, jsii.String("Stack"))

dynamodb.NewTable(stack, jsii.String("Table"), &TableProps{
	PartitionKey: &Attribute{
		Name: jsii.String("id"),
		Type: dynamodb.AttributeType_STRING,
	},
	ImportSource: &ImportSourceSpecification{
		CompressionType: dynamodb.InputCompressionType_GZIP,
		InputFormat: dynamodb.InputFormat_Csv(&CsvOptions{
			Delimiter: jsii.String(","),
			HeaderList: []*string{
				jsii.String("id"),
				jsii.String("name"),
			},
		}),
		Bucket: *Bucket,
		KeyPrefix: jsii.String("prefix"),
	},
})

Properties ​

delimiteroptionalstringdelimiteroptionalstrdelimiteroptionalStringDelimiteroptionalstringDelimiteroptional*string #
The delimiter used for separating items in the CSV file being imported.

Default: use comma as a delimiter.

Valid delimiters are as follows:

  • comma (,)
  • tab (\t)
  • colon (:)
  • semicolon (;)
  • pipe (|)
  • space ()
headerListoptionalstring[]header_listoptionaltyping.List[str]headerListoptionalList<String>HeaderListoptionalstring[]HeaderListoptional*[]*string #
List of the headers used to specify a common header for all source CSV files being imported.

Default: the first line of the CSV file is treated as the header

NOTE: If this field is specified then the first line of each CSV file is treated as data instead of the header. If this field is not specified the first line of each CSV file is treated as the header.