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:

    https://github.com/aws/aws-cdk/issues/5944

    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
                ]
              },
            ]
          }
        }
    ....

    広告ここから
    広告ここまで

    Random posts

    Home
    Search
    Bookmark