# S3JsonItemReader

Class · Stable

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

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#L327)
- Type last changed: v2.180.0 · 21 Feb 2025

## Example

TypeScript:

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

/**
 * Tree view of bucket:
 *  my-bucket
 *  |
 *  +--input.json
 *  |
 *  ...
 *
 * File content of input.json:
 *  [
 *    "item1",
 *    "item2"
 *  ]
 */
const bucket = new s3.Bucket(this, 'Bucket', {
  bucketName: 'my-bucket',
});

const distributedMap = new sfn.DistributedMap(this, 'DistributedMap', {
  itemReader: new sfn.S3JsonItemReader({
    bucket,
    key: 'input.json',
  }),
});
distributedMap.itemProcessor(new sfn.Pass(this, 'Pass'));
```

Python:

```python
import aws_cdk.aws_s3 as s3

#
# Tree view of bucket:
#  my-bucket
#  |
#  +--input.json
#  |
#  ...
#
# File content of input.json:
#  [
#    "item1",
#    "item2"
#  ]
#
bucket = s3.Bucket(self, "Bucket",
    bucket_name="my-bucket"
)

distributed_map = sfn.DistributedMap(self, "DistributedMap",
    item_reader=sfn.S3JsonItemReader(
        bucket=bucket,
        key="input.json"
    )
)
distributed_map.item_processor(sfn.Pass(self, "Pass"))
```

Java:

```java
import software.amazon.awscdk.services.s3.*;

/**
 * Tree view of bucket:
 *  my-bucket
 *  |
 *  +--input.json
 *  |
 *  ...
 *
 * File content of input.json:
 *  [
 *    "item1",
 *    "item2"
 *  ]
 */
Bucket bucket = Bucket.Builder.create(this, "Bucket")
        .bucketName("my-bucket")
        .build();

DistributedMap distributedMap = DistributedMap.Builder.create(this, "DistributedMap")
        .itemReader(S3JsonItemReader.Builder.create()
                .bucket(bucket)
                .key("input.json")
                .build())
        .build();
distributedMap.itemProcessor(new Pass(this, "Pass"));
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.S3;

/**
 * Tree view of bucket:
 *  my-bucket
 *  |
 *  +--input.json
 *  |
 *  ...
 *
 * File content of input.json:
 *  [
 *    "item1",
 *    "item2"
 *  ]
 */
var bucket = new Bucket(this, "Bucket", new BucketProps {
    BucketName = "my-bucket"
});

var distributedMap = new DistributedMap(this, "DistributedMap", new DistributedMapProps {
    ItemReader = new S3JsonItemReader(new S3FileItemReaderProps {
        Bucket = bucket,
        Key = "input.json"
    })
});
distributedMap.ItemProcessor(new Pass(this, "Pass"));
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import s3 "github.com/aws/aws-cdk-go/awscdk"

/**
 * Tree view of bucket:
 *  my-bucket
 *  |
 *  +--input.json
 *  |
 *  ...
 *
 * File content of input.json:
 *  [
 *    "item1",
 *    "item2"
 *  ]
 */
bucket := s3.NewBucket(this, jsii.String("Bucket"), &BucketProps{
	BucketName: jsii.String("my-bucket"),
})

distributedMap := sfn.NewDistributedMap(this, jsii.String("DistributedMap"), &DistributedMapProps{
	ItemReader: sfn.NewS3JsonItemReader(&S3FileItemReaderProps{
		Bucket: *Bucket,
		Key: jsii.String("input.json"),
	}),
})
distributedMap.ItemProcessor(sfn.NewPass(this, jsii.String("Pass")))
```

## Initializer

TypeScript:

```ts
new S3JsonItemReader(props: S3FileItemReaderProps)
```

Python:

```python
S3JsonItemReader(props: S3FileItemReaderProps)
```

Java:

```java
new S3JsonItemReader(S3FileItemReaderProps props)
```

C#:

```csharp
new S3JsonItemReader(S3FileItemReaderProps props)
```

Go:

```go
NewS3JsonItemReader(Props S3FileItemReaderProps)
```

## 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.

- `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.

  **Returns:** - JSON object

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