I am migrating the cloudformation template to CDK. The only problem is I don't know how to get the same logical ID of parent stack from the cloudformation template to CDK. Any help please! Thank you! or is there a way to override cdk generated logical id? This will be really helpful when migrating templates to CDK w/o Cfn actually deleting and recreating the resource due to change in logical id.
from aws_cdk.core import Stack, Construct, StackProps
import aws_cdk.aws_cloudformation as cfn
import aws_cdk.aws_s3 as s3
import aws_cdk.core as core
import aws_cdk.cloudformation_include as cfn_inc
class MyNestedStack1(cfn.NestedStack):
def __init__(self, scope, id, *, parameters=None, timeout=None, notifications=None):
super().__init__(scope, id)
bucket = s3.Bucket.from_bucket_name(self, "S3Bucket",
bucket_name = "sample-bucket-sample-tin-test")
bucket_arn = core.Fn.get_att("S3Bucket", "Arn")
class MyParentStack1 (Stack):
def __init__(self, scope, id, *, description=None, env=None, stack_name=None, tags=None, synthesizer=None, terminationProtection=None):
super().__init__(scope, id, stack_name='aws-stack-nightly')
MyNestedStack(self, "AWSHealthStack")
As you can see on the screenshot. The AWSHealthStack is the logical ID of the cf template. Then when I deployed that to cdk it creates another logical id (AWSHealthStackNestedStackAWSHealthStackNestedStackResource7F23391A)
Well in here I tried this code so I can override the logical id using CFnInclude. But I got this error:
jsii.errors.JSIIError: Missing required properties for @aws-cdk/cloudformation-include.CfnIncludeProps: templateFile
class MyParentStack(core.Stack):
def __init__(self, scope, id, *, description=None, env=None, stack_name=None, tags=None, synthesizer=None, terminationProtection=None):
super().__init__(scope, id, stack_name='aws-stack-nightly')
stack = MyNestedStack(self, "AWSHealthStack1")
cfn_template = cfn_inc.CfnIncludeProps(template_file="monitoring-template/aws-stack.yml",
nested_stacks=[stack])
cfn_template1 = cfn_inc.CfnInclude(self, "AWSHealthStack2", template_file="monitoring-template/aws-stack.yml",
nested_stacks=cfn_template)
cfn_stack = core.Fn.get_att("AWSHealthStack", "Arn")
cfn_template1.override_logical_id("AWSHealthStack")