Set “AWS::CloudFormation::Interface” in your AWS CDK code (For TypeScript)
AWS CDK has not supported the parameter AWS::CloudFormation::Interface. We don’t currently have a plan f […]
広告ここから
広告ここまで
目次
AWS CDK has not supported the parameter AWS::CloudFormation::Interface
.
We don’t currently have a plan for first-class support for AWS::CloudFormation::Interface but it shouldn’t be too hard to synthesize this metadata:
Solution: use templateOptions.metadata
instead
We can define the parameter by using the templateOptions.metadata
parameter.
export class CfStackStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// params
const originDomain = new cdk.CfnParameter(this, 'OriginDomain', {
type: 'String',
description: 'Website url'
})
this.templateOptions.metadata = {
"AWS::CloudFormation::Interface": {
ParameterGroups: [
{
Label: {
default: "Example interface"
},
Parameters: [
'OriginDomain'
]
},
]
}
}
....
enum
helps us to handle the parameter ID
We have to put the parameter ID at least two times when using Interface. It’s possible to miss the ID.
To define the IDs by using enum is helps us to handle it more easily.
enum CfnParameterName {
OriginDomain = 'OriginDomain'
}
export class CfStackStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// params
const originDomain = new cdk.CfnParameter(this, CfnParameterName.OriginDomain, {
type: 'String',
description: 'Website url'
})
this.templateOptions.metadata = {
"AWS::CloudFormation::Interface": {
ParameterGroups: [
{
Label: {
default: "Example interface"
},
Parameters: [
CfnParameterName.OriginDomain
]
},
]
}
}
....