Open sudhirkumar04 opened 1 month ago
@sudhirkumar04 , Thanks for reporting this.
I am able to repro the situation and resources are not getting imported however in my case, the error is a bit different which only says Skipping import
. I found a somewhat similar past issue , there is a workaround suggested, not really sure if that works. You could check that out. Please feel free to share if that works!
I am currently investigating the root cause and looking into it. Will share my findings soon if there is an alternate on how this could be achieved.
thanks for looking into it @khushail
Skipping import
means its not importing the resource with the --resource-mapping
options. The workaround you suggested has been checked before this issue raised. One of the solution suggested to use RemovalPolicy.DESTROY/RETAIN has also been checked.
In the issue you suggested not using --resource-mapping
to map the resource. The main purpose of using --resource-mapping option is to import resources using ci/cd where the resources is taken from a file rather entering details for each resource manually in the terminal
@sudhirkumar04 , I understood your point in providing the resources through the file and I tried to repro the same scenario and faced similar error -
As per my investigation, this code leads to reading the data from the file -
which is invoking this module -
Looks like, the file is not being read properly and error is produced by contents being read as Unknown - https://github.com/aws/aws-cdk/blob/ba8edb3e16e3b7c72bb2a38bb3318969e0e9f054/packages/aws-cdk/lib/import.ts#L111
Since the direct option of passing the logical id exists through cdk import
, marking this as P2.
Describe the bug
cdk import --resource-mapping=resource-mapping.json
doesn't work. This returnsImportedKMSKey1, ImportedKMSKey2 are resource names
--resource-mapping option also return same result when it used after --record-resource-mapping
cdk import --record-resource-mapping=resource-mapping.json
// this command prompted for keyId twicecdk import -resource-mapping=resource-mapping.json
This returns same as above
Expected Behavior
cdk import --resource-mapping=resource-mapping.json
should import the resources mentioned in the resource-mapping.json fileCurrent Behavior
cdk import --resource-mapping=resource-mapping.json
doesn't work. This returnsImportedKMSKey1, ImportedKMSKey2 are resource names
Reproduction Steps
Create a resource-mapping file, in this test, resource-mapping file is created inside lib/config/dev.json. E.g. below
Create file inside lib directory, this is for importing two kms keys.
export class CoreAwsInfraStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); const config = JSON.parse(fs.readFileSync(
lib/config/dev.json
, 'utf8')); for (const [key] of Object.entries(config)) { new Key(this, key, { }); } } }!/usr/bin/env node
import 'source-map-support/register'; import * as cdk from 'aws-cdk-lib'; import { CoreAwsInfraStack } from '../lib/core-aws-infra-stack';
const app = new cdk.App(); new CoreAwsInfraStack(app, 'CoreAwsInfraStack', { });