I am currently utilizing aws cdk 2.132.1 to implement a basic Lambda application.
Within my project, there is one stack named AllStack.ts
which acts as the parent stack for all other stacks (DynamoDB, SNS, SQS, StepFunction, etc.), here is an overview:
import * as cfn_inc from 'aws-cdk-lib/cloudformation-include';
import {CfnStateMachine} from 'aws-cdk-lib/aws-stepfunctions';
import {Duration} from 'aws-cdk-lib';
interface AllStackProps {
readonly env: DeploymentEnvironment;
readonly lambdaFunction: IFunction;
}
export class AllStack extends DeploymentStack {
constructor(scope: Construct, id: string, readonly props: AllStackProps) {
super(scope, id, {
env: props.env,
softwareType: SoftwareType.INFRASTRUCTURE,
});
const cfnInclude = new cfn_inc.CfnInclude(this, 'Template', {
templateFile: 'templates/root.yaml',
// loadNestedStacks: {
// StepFunctionStack: {
// templateFile: 'templates/step_function.yaml',
// preserveLogicalIds: true,
// parameters: { 'Domain': props.env }
// },
// },
// parameters: {
// 'Domain': props.env
// }
});
}
}
The build process was successful with the loadNestedStack
part commented out. However, upon uncommenting these lines, it failed to build and produced errors such as:
TypeError: Cannot read properties of undefined (reading 'Parameters')
at CfnInclude.createNestedStack (ROOT_TO_MY_WORK_DIR/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:15080)
at CfnInclude.getOrCreateResource (ROOT_TO_MY_WORK_DIR/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:13018)
at CfnInclude.loadNestedStack (ROOT_TO_MY_WORK_DIR/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:5353)
at new AllStack (ROOT_TO_MY_WORK_DIR/dist/lib/allStack.js:26:20)
at Object.<anonymous> (ROOT_TO_MY_WORK_DIR/dist/lib/app.js:41:18)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
This is the structure of my entire folder:
-FunServiceCDK
--lib
---allStack.ts
---app.ts
--templates
---root.yaml
---step_function.yaml
This is the content of my root.yaml
:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Domain:
Type: String
Resources:
StepFunctionStack:
Type: AWS::CloudFormation::Stack
This is the content of my step_function.yaml
:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Domain:
Type: String
Resources:
ComputationStepFunction:
Type: AWS::StepFunctions::StateMachine
After reviewing the CDK documentation on CfnInclude doc, it seems that the parameters
field is optional. Despite supplying this field in both the .ts and .yaml files, the issue persists. Any assistance would be greatly appreciated!
Thank you!