Skip to content

Comments

fix(cli): on cdk import the option--role-arn is also parsed as --record-resource-mapping, creating a mapping file path from ARN#1177

Open
abhu85 wants to merge 2 commits intoaws:mainfrom
abhu85:fix/import-r-alias-collision-1175
Open

fix(cli): on cdk import the option--role-arn is also parsed as --record-resource-mapping, creating a mapping file path from ARN#1177
abhu85 wants to merge 2 commits intoaws:mainfrom
abhu85:fix/import-r-alias-collision-1175

Conversation

@abhu85
Copy link

@abhu85 abhu85 commented Feb 24, 2026

Fixes #1175

Summary

The cdk import command's --record-resource-mapping option defined -r as an alias, which conflicts with the global --role-arn option that also uses -r. When yargs sees both options with the same alias, it assigns the value to both, causing the role ARN to be incorrectly treated as a file path for recording resource mappings.

Root Cause

cdk import MyStack --role-arn=arn:aws:iam::123:role/MyRole
                         |
                  yargs resolves -r
                         |
            +------------+------------+
            v                         v
   +------------------+     +---------------------------+
   |  --role-arn      |     |  --record-resource-mapping |
   |  alias: -r       |     |  alias: -r                 |
   |  (global)        |     |  (import subcommand)       |
   +--------+---------+     +-------------+-------------+
            v                             v
   roleArn = "arn:..."         recordResourceMapping = "arn:..."
                                          |
                                          v
                               +---------------------+
                               | ARN treated as file  |
                               | path -> bogus file   |
                               +---------------------+

Fix

This PR removes the -r alias from --record-resource-mapping in the import command definition, allowing the global --role-arn option to retain exclusive use of -r.

Files Changed

  • packages/aws-cdk/lib/cli/cli-config.ts - Source of truth (removed alias: 'r')
  • packages/aws-cdk/lib/cli/parse-command-line-arguments.ts - Generated parser
  • packages/aws-cdk/lib/cli/cli-type-registry.json - Type registry

Test Plan

  • Verified the fix addresses the alias collision described in the issue
  • Confirmed the global --role-arn option retains its -r alias
  • Confirmed --record-resource-mapping still works with its full name

The fix was validated against the reproduction provided in issue comment by @pahud, which confirmed that removing the alias resolves the collision.

Checklist

  • This change does not contain a major version upgrade for a dependency

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


Generated with Claude Code

The `import` command's `--record-resource-mapping` option defined `-r` as
an alias, which conflicts with the global `--role-arn` option that also
uses `-r`. When yargs sees both options with the same alias, it assigns
the value to both, causing the role ARN to be incorrectly treated as a
file path for recording resource mappings.

This fix removes the `-r` alias from `--record-resource-mapping`, allowing
the global `--role-arn` option to retain exclusive use of `-r`.

Fixes aws#1175

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mrgrain mrgrain changed the title fix(import): remove conflicting -r alias from --record-resource-mapping fix(cli): on cdk import the option--role-arn is also parsed as --record-resource-mapping, creating a mapping file path from ARN Feb 24, 2026
@mrgrain
Copy link
Contributor

mrgrain commented Feb 24, 2026

@abhu85 we require you to include the contributor statement, see PR template: https://github.com/aws/aws-cdk-cli/blob/main/.github/pull_request_template.md

Tip: I instruct my AI Agents to always look the PR template for the current repo.

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.76%. Comparing base (e51b1ae) to head (225804a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1177      +/-   ##
==========================================
- Coverage   87.76%   87.76%   -0.01%     
==========================================
  Files          72       72              
  Lines       10137    10136       -1     
  Branches     1339     1338       -1     
==========================================
- Hits         8897     8896       -1     
  Misses       1215     1215              
  Partials       25       25              
Flag Coverage Δ
suite.unit 87.76% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@abhu85
Copy link
Author

abhu85 commented Feb 24, 2026

Thanks @mrgrain! I've updated the PR description to include the contributor statement and checklist from the template.

Good tip about checking the PR template - I'll make sure to do that going forward. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug effort/medium 1-3 days of effort p1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-cdk import: --role-arn is also parsed as --record-resource-mapping, creating a mapping file path from ARN

3 participants