aws-cdk: AWS APIgateway: fromRestApiAttributes does not bring all the RestAPI configuration

Describe the bug

I was following this documentation section, where there’s a workaround for multiple stack describing api gateway resources:

Breaking up Methods and Resources across Stacks It is fairly common for REST APIs with a large number of Resources and Methods to hit the CloudFormation limit of 500 resources per stack.

So I broke my stack in several nested stacks and imported back my api in each nested stack using the ``fromRestApiAttributes``` method. The correct object was found but not all the configuration appeared.

Expected Behavior

I was expecting the full object as set during the API creation in the main stack.

Current Behavior

Dumping the object, I had the following:

{
...
    defaultIntegration: undefined,
    defaultMethodOptions: undefined,
    defaultCorsPreflightOptions: undefined
...
}

instead of:

{
...
    defaultIntegration: undefined,
    defaultMethodOptions: undefined,
    defaultCorsPreflightOptions: { allowOrigins: [Array], allowMethods: [Array] },
...
}

Reproduction Steps

The following piece of code as mentionned in the documentation: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway-readme.html#breaking-up-methods-and-resources-across-stacks

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.127.0 (build 6c90efc)

Framework Version

No response

Node.js Version

v21.1.0

OS

Mac

Language

TypeScript

Language Version

No response

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created 5 months ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I would not say it’s a bug but we definitely need to improve the user experience. Generally, any imported resource with fromXxxAttribute() method is actually a reference object that carries all attributes user passes in. So in this case the imported API literally has no idea if the original API is having defaultCorsPreflightOptionsenabled until we allow users to pass this attribute in fromRestApiAttributes()

It might be a solution to add a new prop in RestApiAttributes so when we import that API we can specify defaultCorsPreflightOptions for it.

This might be an option off the top of my head. We welcome any PR to help us improve this user experience.