Skip to content
v2.273.0

S3JsonItemReader Class ​

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

Example ​

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
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
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"));
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
// 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 ​

ts
new S3JsonItemReader(props: S3FileItemReaderProps)
python
S3JsonItemReader(props: S3FileItemReaderProps)
java
new S3JsonItemReader(S3FileItemReaderProps props)
csharp
new S3JsonItemReader(S3FileItemReaderProps props)
go
NewS3JsonItemReader(Props S3FileItemReaderProps)

Properties ​

bucketIBucketbucketIBucketbucketIBucketBucketIBucketBucketIBucketrequired#
S3 Bucket containing a file with a list to iterate over.
bucketNamePathstringbucket_name_pathstrbucketNamePathStringBucketNamePathstringBucketNamePath*string#
S3 bucket name containing objects to iterate over or a file with a list to iterate over, as JsonPath.
keystringkeystrkeyStringKeystringKey*stringrequired#
S3 key of a file with a list to iterate over.
maxItemsnumbermax_itemsint | floatmaxItemsNumberMaxItemsdoubleMaxItems*float64= No maxItems#
Limits the number of items passed to the Distributed Map state.
resourcestringresourcestrresourceStringResourcestringResource*stringrequired#
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[]def provide_policy_statements(self, ) -> typing.List[PolicyStatement]public List<PolicyStatement> providePolicyStatements()public PolicyStatement[] ProvidePolicyStatements()func ProvidePolicyStatements() *[]PolicyStatement#
Compile policy statements to provide relevent permissions to the state machine.
render(queryLanguage?: QueryLanguage): anydef render(self, query_language: typing.Optional[QueryLanguage] = None) -> Anypublic Object render(QueryLanguage queryLanguage)public object Render(QueryLanguage? queryLanguage = null)func Render(QueryLanguage QueryLanguage) interface{}#
Renders the ItemReader configuration as JSON object.
returns

Returns: - JSON object

validateItemReader(): string[]def validate_item_reader(self, ) -> typing.List[str]public List<String> validateItemReader()public string[] ValidateItemReader()func ValidateItemReader() *[]*string#
Validate that ItemReader contains exactly either.