Skip to content

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

@yutaro1985

Description

@yutaro1985

Describe the bug

When running cdk import with --role-arn, the CLI incorrectly also sets --record-resource-mapping to the same value.

As a result, the ARN string is treated as a file path, and a file/directory like this is created locally:

arn:aws:iam::<ACCOUNT_ID>:role/<CLOUDFORMATION_EXECUTION_ROLE_NAME>

CLI output includes:

arn:aws:iam::<ACCOUNT_ID>:role/<CLOUDFORMATION_EXECUTION_ROLE_NAME>: mapping file written.

This makes cdk import unusable when we must explicitly specify an execution role.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

--role-arn should only set the CloudFormation execution role for import/deploy operations.

It should not set record-resource-mapping, and should not create a local mapping file path from the ARN string.

Current Behavior

Both values are set internally from a single flag.

With -vvv, CLI arguments include both:

  • roleArn: arn:aws:iam::...:role/...
  • recordResourceMapping: arn:aws:iam::...:role/...

Reproduction Steps

  1. Use local CDK CLI (example: pnpm exec cdk, not global).
  2. Run:
cd infra/cdk
CDK_DEFAULT_ACCOUNT=<ACCOUNT_ID> \
CDK_DEFAULT_REGION=<AWS_REGION> \
pnpm exec cdk import <STACK_NAME> \
  -c env=<ENV_NAME> \
  --role-arn=arn:aws:iam::<ACCOUNT_ID>:role/<CLOUDFORMATION_EXECUTION_ROLE_NAME> \
  -vvv
  1. Observe debug output: record-resource-mapping is set to the same ARN.
  2. Observe local file/directory creation from the ARN path and output mapping file written.

Possible Solution

cdk import appears to have conflicting short option binding (-r) for both:

  • --role-arn
  • --record-resource-mapping

Please separate these options (remove alias conflict and ensure independent parsing).

Possible Solution

No response

Additional Information/Context

cdk import --help currently shows both options using -r, which appears to be the root cause.

AWS CDK Library version (aws-cdk-lib)

2.236.0

AWS CDK CLI version

2.1106.1 (build 4e0d9f7)

Node.js Version

v22.18.0

OS

Amazon Linux 2023 (Cloud9/EC2 environment)

Language

Python

Language Version

Python 3.11

Other information

We can work around by not using --role-arn, but in our environment explicit execution role is required, so this is blocking for cdk import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions