# ResultWriterV2

Configuration for writing Distributed Map state results to S3 The ResultWriter field cannot be empty.

You must specify one of these sets of sub-fields.
  writerConfig - to preview the formatted output, without saving the results to Amazon S3.
  bucket and prefix - to save the results to Amazon S3 without additional formatting.
  All three fields: writerConfig, bucket and prefix - to format the output and save it to Amazon S3.

- Source: [`aws-stepfunctions/lib/states/distributed-map/result-writer.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map/result-writer.ts#L225)
- Type last changed: v2.196.0 · 16 May 2025

## Example

TypeScript:

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

// create a bucket
const bucket = new s3.Bucket(this, 'Bucket');

// create a WriterConfig

const distributedMap = new sfn.DistributedMap(this, 'Distributed Map State', {
  resultWriterV2: new sfn.ResultWriterV2({
    bucket: bucket,
    prefix: 'my-prefix',
    writerConfig: {
      outputType: sfn.OutputType.JSONL,
      transformation: sfn.Transformation.NONE,
    },
  })
});
distributedMap.itemProcessor(new sfn.Pass(this, 'Pass State'));
```

Python:

```python
import aws_cdk.aws_s3 as s3

# create a bucket
bucket = s3.Bucket(self, "Bucket")

# create a WriterConfig

distributed_map = sfn.DistributedMap(self, "Distributed Map State",
    result_writer_v2=sfn.ResultWriterV2(
        bucket=bucket,
        prefix="my-prefix",
        writer_config={
            "output_type": sfn.OutputType.JSONL,
            "transformation": sfn.Transformation.NONE
        }
    )
)
distributed_map.item_processor(sfn.Pass(self, "Pass State"))
```

Java:

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

// create a bucket
Bucket bucket = new Bucket(this, "Bucket");

// create a WriterConfig

DistributedMap distributedMap = DistributedMap.Builder.create(this, "Distributed Map State")
        .resultWriterV2(ResultWriterV2.Builder.create()
                .bucket(bucket)
                .prefix("my-prefix")
                .writerConfig(Map.of(
                        "outputType", OutputType.JSONL,
                        "transformation", Transformation.NONE))
                .build())
        .build();
distributedMap.itemProcessor(new Pass(this, "Pass State"));
```

C# / .NET:

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

// create a bucket
var bucket = new Bucket(this, "Bucket");

// create a WriterConfig

var distributedMap = new DistributedMap(this, "Distributed Map State", new DistributedMapProps {
    ResultWriterV2 = new ResultWriterV2(new ResultWriterV2Props {
        Bucket = bucket,
        Prefix = "my-prefix",
        WriterConfig = new Dictionary<string, object> {
            { "outputType", OutputType.JSONL },
            { "transformation", Transformation.NONE }
        }
    })
});
distributedMap.ItemProcessor(new Pass(this, "Pass State"));
```

Golang:

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

// create a bucket
bucket := s3.NewBucket(this, jsii.String("Bucket"))

// create a WriterConfig

distributedMap := sfn.NewDistributedMap(this, jsii.String("Distributed Map State"), &DistributedMapProps{
	ResultWriterV2: sfn.NewResultWriterV2(&ResultWriterV2Props{
		Bucket: bucket,
		Prefix: jsii.String("my-prefix"),
		WriterConfig: map[string]interface{}{
			"outputType": sfn.OutputType_JSONL,
			"transformation": sfn.Transformation_NONE,
		},
	}),
})
distributedMap.ItemProcessor(sfn.NewPass(this, jsii.String("Pass State")))
```

## Initializer

TypeScript:

```ts
new ResultWriterV2(props: ResultWriterV2Props)
```

Python:

```python
ResultWriterV2(props: ResultWriterV2Props)
```

Java:

```java
new ResultWriterV2(ResultWriterV2Props props)
```

C# / .NET:

```csharp
new ResultWriterV2(ResultWriterV2Props props)
```

Golang:

```go
NewResultWriterV2(Props ResultWriterV2Props)
```

## Properties

- `bucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — S3 Bucket in which to save Map Run results.

- `bucketNamePath`: string — S3 bucket name in which to save Map Run results, as JsonPath.

- `prefix`: string — S3 prefix in which to save Map Run results.

  **Default:** No prefix

- `writerConfig`: [WriterConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.WriterConfig.html) — Configuration to format the output of the Child Workflow executions.

## Methods

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

- `render(queryLanguage?: QueryLanguage): any` — Render ResultWriter in ASL JSON format.

- `validateResultWriter(): string[]` — Validate that ResultWriter contains exactly either.
