Skip to content

fix(stepfunctions): properly deprecate DistributedMap resultWriter property#36000

Open
pahud wants to merge 5 commits intoaws:mainfrom
pahud:fix-35966-distributed-map-result-writer
Open

fix(stepfunctions): properly deprecate DistributedMap resultWriter property#36000
pahud wants to merge 5 commits intoaws:mainfrom
pahud:fix-35966-distributed-map-result-writer

Conversation

@pahud
Copy link
Copy Markdown
Contributor

@pahud pahud commented Nov 10, 2025

Issue # (if applicable)

Closes #35966.

Reason for this change

The getResultWriter() method in DistributedMap gates on the @aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2 feature flag to decide which writer to return. This causes two problems:

  1. When the flag is enabled but only resultWriter is provided → returns undefined (silent data loss)
  2. When the flag fails to propagate (e.g. inside a CDK Stage) → resultWriterV2 is never selected, even when explicitly provided

As reported by @aihaddad in #35966 (comment), FeatureFlags.of(this).isEnabled() returns false inside a Stage even when the flag is set to true.

Evidence

Official AWS docs confirm the expected ASL output — ResultWriter (Map) specifies that ResultWriter must contain Resource + Parameters (JSONPath) or Resource + Arguments (JSONata) to export results to S3. The CDK bug causes this entire block to be silently omitted.

Description of changes

Removed the feature flag gate from getResultWriter() and replaced it with a simple fallback:

private getResultWriter(): ResultWriterV2 | ResultWriter | undefined {
  return this.resultWriterV2 ?? this.resultWriter;
}
  • resultWriterV2 is always preferred when provided
  • Falls back to resultWriter for backward compatibility
  • Emits a deprecation warning (not error) when resultWriter is used
  • No feature flag dependency — works in all contexts (Stack, Stage, Pipeline)

How it works

Before (broken):

┌─────────────────────┐     ┌──────────────────────────┐
│ User provides        │ ──> │ getResultWriter()        │
│ resultWriter or      │     │ checks FeatureFlags      │
│ resultWriterV2       │     └──────────────────────────┘
└─────────────────────┘               │
                              ┌───────┴───────┐
                              │               │
                           flag=true      flag=false
                              │               │
                              v               v
                     ┌──────────────┐  ┌──────────────┐
                     │ return       │  │ return       │
                     │ resultWriter │  │ resultWriter │
                     │ V2           │  │ (deprecated) │
                     └──────────────┘  └──────────────┘
                              │               │
                              v               v
                     ┌──────────────┐  ┌──────────────┐
                     │ undefined if │  │ undefined if │
                     │ user only    │  │ user only    │
                     │ set V1  ✗   │  │ set V2  ✗   │
                     └──────────────┘  └──────────────┘


After (fixed):

┌─────────────────────┐     ┌──────────────────────────┐
│ User provides        │ ──> │ getResultWriter()        │
│ resultWriter or      │     │ resultWriterV2 ??        │
│ resultWriterV2       │     │ resultWriter             │
└─────────────────────┘     └──────────────────────────┘
                                       │
                               ┌───────┴───────┐
                               │               │
                          V2 provided?     V1 provided?
                            (yes)            (yes)
                               │               │
                               v               v
                      ┌──────────────┐  ┌──────────────┐
                      │ use V2  ✓   │  │ use V1  ✓   │
                      │              │  │ + warning    │
                      └──────────────┘  └──────────────┘

Before (broken):

// resultWriterV2 silently ignored inside a Stage
new DistributedMap(stack, "Map", {
  resultWriterV2: new ResultWriterV2({ bucket, prefix: "results/" }),
});
// → No ResultWriter in CloudFormation template

After (fixed):

// Works everywhere, no feature flag needed
new DistributedMap(stack, "Map", {
  resultWriterV2: new ResultWriterV2({ bucket, prefix: "results/" }),
});
// → ResultWriter correctly rendered

// Deprecated property still works with warning
new DistributedMap(stack, "Map", {
  resultWriter: new ResultWriter({ bucket, prefix: "results/" }),
});
// → ResultWriter rendered + deprecation warning emitted

Describe any new or updated permissions being added

N/A

Description of how you validated changes

  • All 65 distributed-map unit tests pass
  • Tests updated to verify:
    • resultWriterV2 renders regardless of feature flag state
    • resultWriter renders with deprecation warning
    • resultWriterV2 takes precedence when both are provided
  • Integration tests updated to use resultWriterV2

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

- Mark `resultWriter` as deprecated in `DistributedMapBaseOptions`
- Add validation error when `resultWriter` is used
- Update documentation to clarify that `resultWriter` does not function correctly
- Recommend using `resultWriterV2` instead of deprecated `resultWriter`
- Update test cases to validate new deprecation behavior
This change ensures users are guided towards using the correct result writer configuration for Distributed Map states in AWS Step Functions.
@aws-cdk-automation aws-cdk-automation requested a review from a team November 10, 2025 17:47
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Nov 10, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 10, 2025
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 10, 2025 18:27

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@pahud pahud marked this pull request as ready for review November 11, 2025 19:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 14, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results144 ran144 passed
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 14, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates144 ran144 passed
TestResult
No test annotations available

pahud added 2 commits April 2, 2026 04:57
…e resultWriterV2 ?? resultWriter

Remove the FeatureFlags dependency from getResultWriter() and use a simple
resultWriterV2 ?? resultWriter fallback. This fixes resultWriterV2 not
rendering inside CDK Stages where FeatureFlags.of(this).isEnabled() returns
false even when the flag is set to true.

- resultWriterV2 is always preferred when provided
- Falls back to resultWriter for backward compatibility
- Emits a deprecation warning when resultWriter is used

Closes aws#35966
@pahud pahud force-pushed the fix-35966-distributed-map-result-writer branch from 3feb769 to b81dae8 Compare April 1, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-stepfunctions): DistributedMap prop resultWriter doesn't work when integrating with StateMachine

2 participants