Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot seem to fetch SSM Parameter at deploy with CDK

I’m currently trying a fetch a parameter for my pipeline through the CDK SSM Parameter library, however I seem to face a weird issue:

CfnParameter at 'nonProdAccountId.Parameter' should be created in the scope of a Stack, but no Stack found

However, I’m rather confident that I am fetching my Parameter value in the Scope of a Stack (the BackendPipelineStack).

//cdk.ts aka my entrypoint
const app = new cdk.App()
...
new BackendPipelineStack(app, "BackendPipelineStack", {
  nonProdAccountId: StringParameter.fromStringParameterName(app, "nonProdAccountId", "nonProdAccountId").stringValue,
  apiStack,
  commonInfraStack,
  deploymentStack,
})

Am I missing something?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TIA

>Solution :

Right now, you’re importing the StringParameter in the scope of the App. The first argument in every Stack or Construct is the scope.

You can create stacks in the scope of an App, but you can’t create constructs in the scope of an App – they have to be created in the scope of a Stack.

You need to move the import into the stack, and use the stack as the scope for the import (passing this instead of app).

So you would change

  nonProdAccountId: StringParameter.fromStringParameterName(app, "nonProdAccountId", "nonProdAccountId").stringValue,

to

  nonProdAccountIdParamName: "nonProdAccountId",

And import the parameter inside of the stack with

const nonProdAccountId = new StringParameter.fromStringParameterName(this, "nonProdAccountId", nonProdAccountIdParamName).stringValue;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading