Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@
{
"Ref": "Bucket83908E77"
},
"\",\"Key\":\"my-key.csv\"}}}}}"
"\",\"Key\":\"my-key.csv\",\"ExpectedBucketOwner\":\"",
{
"Ref": "AWS::AccountId"
},
"\"}}}}}"
]
]
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DistributedMapStack extends cdk.Stack {
bucket: this.bucket,
key: CSV_KEY,
csvHeaders: sfn.CsvHeaders.useFirstRow(),
expectedBucketOwner: this.account,
}),
resultWriter: new sfn.ResultWriter({
bucket: this.bucket,
Expand Down
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,20 @@ distributedMap.itemProcessor(new sfn.Pass(this, 'Pass State'));
```
* CSV file stored in S3
* S3 inventory manifest stored in S3
* When your Step Functions state machine needs to read S3 objects from a bucket in a different AWS account, specify the bucket owner's [account ID](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html#FindAccountId) using the `expectedBucketOwner` parameter:

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

const distributedMap = new sfn.DistributedMap(this, 'DistributedMap', {
itemReader: new sfn.S3JsonItemReader({
bucket: s3.Bucket.fromBucketName(this, 'CrossAccountBucket', 'bucket-in-account-a'),
key: 'input.json',
expectedBucketOwner: '123456789012', , // Account ID that owns the bucket
}),
});
distributedMap.itemProcessor(new sfn.Pass(this, 'Pass'));
```

Map states in Distributed mode also support writing results of the iterator to an S3 bucket and optional prefix. Use a `ResultWriterV2` object provided via the optional `resultWriter` property to configure which S3 location iterator results will be written. The default behavior id `resultWriter` is omitted is to use the state output payload. However, if the iterator results are larger than the 256 kb limit for Step Functions payloads then the State Machine will fail.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export interface ItemReaderProps {
* @default - Distributed Map state will iterate over all items provided by the ItemReader
*/
readonly maxItems?: number;

/**
* The account ID of the expected bucket owner for cross-account access
*
* @default - No expected bucket owner validation
*/
readonly expectedBucketOwner?: string;
}

/**
Expand Down Expand Up @@ -125,11 +132,19 @@ export class S3ObjectsItemReader implements IItemReader {
*/
readonly maxItems?: number;

/**
* The account ID of the expected bucket owner for cross-account access
*
* @default - No expected bucket owner validation
*/
readonly expectedBucketOwner?: string;

constructor(props: S3ObjectsItemReaderProps) {
this._bucket = props.bucket;
this.bucketNamePath = props.bucketNamePath;
this.prefix = props.prefix;
this.maxItems = props.maxItems;
this.expectedBucketOwner = props.expectedBucketOwner;
this.resource = Arn.format({
region: '',
account: '',
Expand All @@ -150,6 +165,7 @@ export class S3ObjectsItemReader implements IItemReader {
...(this._bucket && { Bucket: this._bucket.bucketName }),
...(this.bucketNamePath && { Bucket: this.bucketNamePath }),
...(this.prefix && { Prefix: this.prefix }),
...(this.expectedBucketOwner && { ExpectedBucketOwner: this.expectedBucketOwner }),
};
return FieldUtils.renderObject({
Resource: this.resource,
Expand Down Expand Up @@ -239,13 +255,21 @@ abstract class S3FileItemReader implements IItemReader {
*/
readonly maxItems?: number;

/**
* The account ID of the expected bucket owner for cross-account access
*
* @default - No expected bucket owner validation
*/
readonly expectedBucketOwner?: string;

protected abstract readonly inputType: string;

constructor(props: S3FileItemReaderProps) {
this._bucket = props.bucket;
this.bucketNamePath = props.bucketNamePath;
this.key = props.key;
this.maxItems = props.maxItems;
this.expectedBucketOwner = props.expectedBucketOwner;
this.resource = Arn.format({
region: '',
account: '',
Expand All @@ -266,6 +290,7 @@ abstract class S3FileItemReader implements IItemReader {
...(this._bucket && { Bucket: this._bucket.bucketName }),
...(this.bucketNamePath && { Bucket: this.bucketNamePath }),
Key: this.key,
...(this.expectedBucketOwner && { ExpectedBucketOwner: this.expectedBucketOwner }),
};

return FieldUtils.renderObject({
Expand Down
Loading
Loading