aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.84k forks source link

(aws_apigateway): empty policy attribute for CfnRestApi fails synthesize #29175

Open jwoehrle opened 6 months ago

jwoehrle commented 6 months ago

Describe the bug

I'm playing with cdk migrate and came across an IMO general CDK issue. The following CloudFormation Resource deploys just fine:

"ApiGatewayRestApi": {
      "Type": "AWS::ApiGateway::RestApi",
      "Properties": {
        "Name": "serverless-project-dev",
        "EndpointConfiguration": {
          "Types": [
            "EDGE"
          ]
        },
        "Policy": "",
        "MinimumCompressionSize": 1024
      }
    },

Note the empty string for the Policy attribute

Migrated into CDK with cdk migrate this results in the following L1 construct:

    const apiGatewayRestApi = new apigateway.CfnRestApi(this, 'ApiGatewayRestApi', {
      name: 'serverless-project-dev',
      endpointConfiguration: {
        types: [
          'EDGE',
        ],
      },
      policy: '',
      minimumCompressionSize: 1024,
    });

which fails synthesis with the following error:

CfnSynthesisError: Resolution error: Supplied properties not correct for "CfnRestApiProps" policy: "" should be an 'object'.

When I remove the policy key completely synthesis succeeds

Expected Behavior

L1 constructs should behave like CFN and therefore an empty string as policy value should succeed

Current Behavior

cdk synth fails

Reproduction Steps

try to deploy a CfnRestApi with empty string as value for policy attribute

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.128.0 (build d995261)

Framework Version

No response

Node.js Version

v20.9.0

OS

macOS

Language

TypeScript

Language Version

TypeScript (~5.3.3)

Other information

No response

pahud commented 6 months ago

Thank you for the report. We'll bring this up to the maintainer for further investigation.

TheRealAmazonKendra commented 6 months ago

As this is a problem across our L1s and is not specific to CDK migrate, I'm un-assigning myself on this. I am curious, however, if we accept an empty string for L2s here.