CfnInclude L1 construct
Construct to import an existing CloudFormation template file into a CDK application.
All resources defined in the template file can be retrieved by calling the getResource method. Any modifications made on the returned resource objects will be reflected in the resulting CDK template.
Example
const cfnTemplate = new cfn_inc.CfnInclude(this, 'Template', {
templateFile: 'my-template.json',
});
cfn_template = cfn_inc.CfnInclude(self, "Template",
template_file="my-template.json"
)
CfnInclude cfnTemplate = CfnInclude.Builder.create(this, "Template")
.templateFile("my-template.json")
.build();
// Install: dotnet add package Amazon.CDK.Lib
var cfnTemplate = new CfnInclude(this, "Template", new CfnIncludeProps {
TemplateFile = "my-template.json"
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
cfnTemplate := cfn_inc.NewCfnInclude(this, jsii.String("Template"), &CfnIncludeProps{
TemplateFile: jsii.String("my-template.json"),
})
Initializer
new CfnInclude(scope: Construct, id: string, props: CfnIncludeProps)
CfnInclude(scope: Construct, id: str, props: CfnIncludeProps)
new CfnInclude(Construct scope, String id, CfnIncludeProps props)
new CfnInclude(Construct scope, string id, CfnIncludeProps props)
NewCfnInclude(Scope Construct, Id *string, Props CfnIncludeProps)
Construct Props
allowCyclicalReferencesoptionalbooleanallow_cyclical_referencesoptionalboolallowCyclicalReferencesoptionalBooleanAllowCyclicalReferencesoptionalboolAllowCyclicalReferencesoptional*bool#Default: will throw an error on detecting any cyclical references
This should only be set to true in the case of templates utilizing cloud transforms (e.g. SAM) that after processing the transform will no longer contain any circular references.
dehydratedResourcesoptionalstring[]dehydrated_resourcesoptionaltyping.List[str]dehydratedResourcesoptionalList<String>DehydratedResourcesoptionalstring[]DehydratedResourcesoptional*[]*string#Default: All resources are hydrated
This allows you to use CFN templates that rely on Intrinsic placement that cfn-include would otherwise reject, such as non-primitive values in resource update policies.
loadNestedStacksoptional{ [key: string]: CfnIncludeProps }load_nested_stacksoptionaltyping.Mapping[str, CfnIncludeProps]loadNestedStacksoptionalMap<String, CfnIncludeProps>LoadNestedStacksoptionalIDictionary<string, CfnIncludeProps>LoadNestedStacksoptional*map[string]CfnIncludeProps#Default: no nested stacks will be included
notes
If your template specifies a stack that isn't included here, it won't be created as a NestedStack resource, and it won't be accessible from the CfnInclude.getNestedStack method (but will still be accessible from the CfnInclude.getResource method).
If you include a stack here with an ID that isn't in the template, or is in the template but is not a nested stack, template creation will fail and an error will be thrown.
parametersoptional{ [key: string]: any }parametersoptionaltyping.Mapping[str, Any]parametersoptionalMap<String, Object>ParametersoptionalIDictionary<string, object>Parametersoptional*map[string]interface{}#Default: parameters will retain their original definitions
notes
Any parameters in the template that aren't specified here will be left unmodified. If you include a parameter here with an ID that isn't in the template, template creation will fail and an error will be thrown.
If you are importing a parameter from a live stack, we cannot know the value of that parameter. You will need to supply a value for your parameters, else the default value will be used.
preserveLogicalIdsoptionalbooleanpreserve_logical_idsoptionalboolpreserveLogicalIdsoptionalBooleanPreserveLogicalIdsoptionalboolPreserveLogicalIdsoptional*bool= true#notes
If you're vending a Construct using an existing CloudFormation template, make sure to pass this as false.
Note: regardless of whether this option is true or false, the CfnInclude.getResource and related methods always uses the original logical ID of the resource/element, as specified in the template file.
Both JSON and YAML template formats are supported.
Properties
creationStackstring[]creation_stacktyping.List[str]creationStackList<String>CreationStackstring[]CreationStack*[]*string#The logical ID of the element is calculated from the path of the resource node in the construct tree.
To override this value, use overrideLogicalId(newLogicalId).
Methods
getCondition(conditionName: string): CfnConditiondef get_condition(self, condition_name: str) -> CfnConditionpublic CfnCondition getCondition(String conditionName)public CfnCondition GetCondition(string conditionName)func GetCondition(ConditionName *string) CfnCondition#Any modifications performed on that object will be reflected in the resulting CDK template.
If a Condition with the given name is not present in the template, throws an exception.
1 parameter
Parameters
conditionNamecondition_nameconditionNameconditionNameConditionName— the name of the Condition in the CloudFormation template file.
getHook(hookLogicalId: string): CfnHookdef get_hook(self, hook_logical_id: str) -> CfnHookpublic CfnHook getHook(String hookLogicalId)public CfnHook GetHook(string hookLogicalId)func GetHook(HookLogicalId *string) CfnHook#Any modifications performed on the returned object will be reflected in the resulting CDK template.
If a Hook with the given logical ID is not present in the template, an exception will be thrown.
1 parameter
Parameters
hookLogicalIdhook_logical_idhookLogicalIdhookLogicalIdHookLogicalId— the logical ID of the Hook in the included CloudFormation template's 'Hooks' section.
getMapping(mappingName: string): CfnMappingdef get_mapping(self, mapping_name: str) -> CfnMappingpublic CfnMapping getMapping(String mappingName)public CfnMapping GetMapping(string mappingName)func GetMapping(MappingName *string) CfnMapping#Any modifications performed on that object will be reflected in the resulting CDK template.
If a Mapping with the given name is not present in the template, an exception will be thrown.
1 parameter
Parameters
mappingNamemapping_namemappingNamemappingNameMappingName— the name of the Mapping in the template to retrieve.
getNestedStack(logicalId: string): IncludedNestedStackdef get_nested_stack(self, logical_id: str) -> IncludedNestedStackpublic IncludedNestedStack getNestedStack(String logicalId)public IncludedNestedStack GetNestedStack(string logicalId)func GetNestedStack(LogicalId *string) IncludedNestedStack#For a nested stack to be returned by this method, it must be specified either in the CfnIncludeProps.loadNestedStacks property, or through the loadNestedStack method.
1 parameter
Parameters
logicalIdlogical_idlogicalIdlogicalIdLogicalId— the ID of the stack to retrieve, as it appears in the template.
getOutput(logicalId: string): CfnOutputdef get_output(self, logical_id: str) -> CfnOutputpublic CfnOutput getOutput(String logicalId)public CfnOutput GetOutput(string logicalId)func GetOutput(LogicalId *string) CfnOutput#Any modifications performed on that object will be reflected in the resulting CDK template.
If an Output with the given name is not present in the template, throws an exception.
1 parameter
Parameters
logicalIdlogical_idlogicalIdlogicalIdLogicalId— the name of the output to retrieve.
getParameter(parameterName: string): CfnParameterdef get_parameter(self, parameter_name: str) -> CfnParameterpublic CfnParameter getParameter(String parameterName)public CfnParameter GetParameter(string parameterName)func GetParameter(ParameterName *string) CfnParameter#Any modifications performed on that object will be reflected in the resulting CDK template.
If a Parameter with the given name is not present in the template, throws an exception.
1 parameter
Parameters
parameterNameparameter_nameparameterNameparameterNameParameterName— the name of the parameter to retrieve.
getResource(logicalId: string): CfnResourcedef get_resource(self, logical_id: str) -> CfnResourcepublic CfnResource getResource(String logicalId)public CfnResource GetResource(string logicalId)func GetResource(LogicalId *string) CfnResource#notes · 1 parameter
Any modifications performed on that resource will be reflected in the resulting CDK template.
The returned object will be of the proper underlying class; you can always cast it to the correct type in your code:
// assume the template contains an AWS::S3::Bucket with logical ID 'Bucket'
const cfnBucket = cfnTemplate.getResource('Bucket') as s3.CfnBucket;
// cfnBucket is of type s3.CfnBucket
If the template does not contain a resource with the given logical ID, an exception will be thrown.
Parameters
logicalIdlogical_idlogicalIdlogicalIdLogicalId— the logical ID of the resource in the CloudFormation template file.
getRule(ruleName: string): CfnRuledef get_rule(self, rule_name: str) -> CfnRulepublic CfnRule getRule(String ruleName)public CfnRule GetRule(string ruleName)func GetRule(RuleName *string) CfnRule#Any modifications performed on that object will be reflected in the resulting CDK template.
If a Rule with the given name is not present in the template, an exception will be thrown.
1 parameter
Parameters
ruleNamerule_nameruleNameruleNameRuleName— the name of the Rule in the CloudFormation template.
isCfnElement(x: any): boolean@staticmethod def is_cfn_element(x: Any) -> boolpublic static Boolean isCfnElement(Object x)public static bool IsCfnElement(object x)func IsCfnElement(X interface{}) *boolstatic#Uses duck-typing instead of instanceof to allow stack elements from different versions of this library to be included in the same stack.
returns
Returns: The construct as a stack element or undefined if it is not a stack element.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
loadNestedStack(logicalId: string, nestedStackProps: CfnIncludeProps): IncludedNestedStackdef load_nested_stack(self, logical_id: str, nested_stack_props: CfnIncludeProps) -> IncludedNestedStackpublic IncludedNestedStack loadNestedStack(String logicalId, CfnIncludeProps nestedStackProps)public IncludedNestedStack LoadNestedStack(string logicalId, CfnIncludeProps nestedStackProps)func LoadNestedStack(LogicalId *string, NestedStackProps CfnIncludeProps) IncludedNestedStack#A child with this logical ID must exist in the template, and be of type AWS::CloudFormation::Stack. This is equivalent to specifying the value in the CfnIncludeProps.loadNestedStacks property on object construction.
2 parameters · returns
Parameters
logicalIdlogical_idlogicalIdlogicalIdLogicalId— the ID of the stack to retrieve, as it appears in the template.nestedStackPropsnested_stack_propsnestedStackPropsnestedStackPropsNestedStackProps— the properties of the included child Stack.
Returns: the same IncludedNestedStack object that getNestedStack returns for this logical ID
overrideLogicalId(newLogicalId: string): voiddef override_logical_id(self, new_logical_id: str) -> Nonepublic void overrideLogicalId(String newLogicalId)public void OverrideLogicalId(string newLogicalId)func OverrideLogicalId(NewLogicalId *string)#1 parameter
Parameters
newLogicalIdnew_logical_idnewLogicalIdnewLogicalIdNewLogicalId— The new logical ID to use for this stack element.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.