# S3CsvItemReader

Item Reader configuration for iterating over items in a CSV file stored in S3.

Implements: [IItemReader](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.IItemReader.html)

- Source: [`aws-stepfunctions/lib/states/distributed-map/item-reader.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map/item-reader.ts#L443)
- Type last changed: v2.181.0 · 26 Feb 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_s3 as s3 } from 'aws-cdk-lib';
import { aws_stepfunctions as stepfunctions } from 'aws-cdk-lib';

declare const bucket: s3.Bucket;
declare const csvHeaders: stepfunctions.CsvHeaders;
const s3CsvItemReader = new stepfunctions.S3CsvItemReader({
  key: 'key',

  // the properties below are optional
  bucket: bucket,
  bucketNamePath: 'bucketNamePath',
  csvDelimiter: stepfunctions.CsvDelimiter.COMMA,
  csvHeaders: csvHeaders,
  maxItems: 123,
});
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_stepfunctions as stepfunctions

# bucket: s3.Bucket
# csv_headers: stepfunctions.CsvHeaders

s3_csv_item_reader = stepfunctions.S3CsvItemReader(
    key="key",

    # the properties below are optional
    bucket=bucket,
    bucket_name_path="bucketNamePath",
    csv_delimiter=stepfunctions.CsvDelimiter.COMMA,
    csv_headers=csv_headers,
    max_items=123
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.services.stepfunctions.*;

Bucket bucket;
CsvHeaders csvHeaders;

S3CsvItemReader s3CsvItemReader = S3CsvItemReader.Builder.create()
        .key("key")

        // the properties below are optional
        .bucket(bucket)
        .bucketNamePath("bucketNamePath")
        .csvDelimiter(CsvDelimiter.COMMA)
        .csvHeaders(csvHeaders)
        .maxItems(123)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.StepFunctions;

Bucket bucket;
CsvHeaders csvHeaders;

var s3CsvItemReader = new S3CsvItemReader(new S3CsvItemReaderProps {
    Key = "key",

    // the properties below are optional
    Bucket = bucket,
    BucketNamePath = "bucketNamePath",
    CsvDelimiter = CsvDelimiter.COMMA,
    CsvHeaders = csvHeaders,
    MaxItems = 123
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var bucket Bucket
var csvHeaders CsvHeaders

s3CsvItemReader := awscdk.Aws_stepfunctions.NewS3CsvItemReader(&S3CsvItemReaderProps{
	Key: jsii.String("key"),

	// the properties below are optional
	Bucket: bucket,
	BucketNamePath: jsii.String("bucketNamePath"),
	CsvDelimiter: awscdk.*Aws_stepfunctions.CsvDelimiter_COMMA,
	CsvHeaders: csvHeaders,
	MaxItems: jsii.Number(123),
})
```

## Initializer

TypeScript:

```ts
new S3CsvItemReader(props: S3CsvItemReaderProps)
```

Python:

```python
S3CsvItemReader(props: S3CsvItemReaderProps)
```

Java:

```java
new S3CsvItemReader(S3CsvItemReaderProps props)
```

C# / .NET:

```csharp
new S3CsvItemReader(S3CsvItemReaderProps props)
```

Golang:

```go
NewS3CsvItemReader(Props S3CsvItemReaderProps)
```

## Properties

- `bucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — S3 Bucket containing a file with a list to iterate over.

- `bucketNamePath`: string — S3 bucket name containing objects to iterate over or a file with a list to iterate over, as JsonPath.

- `csvDelimiter`: [CsvDelimiter](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.CsvDelimiter.html) — Delimiter used in CSV file.

- `csvHeaders`: [CsvHeaders](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.CsvHeaders.html) — CSV headers configuration.

- `key`: string — S3 key of a file with a list to iterate over.

- `maxItems`: number — Limits the number of items passed to the Distributed Map state.

  **Default:** No maxItems

- `resource`: string — ARN for the `getObject` method of the S3 API This API method is used to iterate all objects in the S3 bucket/prefix.

## Methods

- `providePolicyStatements(): PolicyStatement[]` — Compile policy statements to provide relevent permissions to the state machine.

- `render(queryLanguage?: QueryLanguage): any` — Renders the ItemReader configuration as JSON object.

- `validateItemReader(): string[]` — Validate that ItemReader contains exactly either.
