-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defaultMethodOptions in SpecRestApi is confusing #8347
Comments
This could simply be me not reading the documentation correctly, but on first pass, I think the documentation suggests that I shouldn't need to define anything with If I need to specify a lambda within a |
Observed same problem today with CDK 1.42.0 (build 3b64241). The 'defaultIntegration' was ignored when create new 'SpecRestApi'. Specified AwsIntegration was not picked up and result error ('No integration defined for method') when deploy and failed. |
This will be fixed with #8270. However, note that, the |
The apigateway CDK construct library creates a large number of CloudFormation resources. To define a single Method that is backed with a Lambda function and authorizer with an Authorizer, ~8 CloudFormation resources are created. This quickly grows and a reasonable sized RestApi is bound to hit the 200 resource limit on their stack. Re-organizing the CDK app into multiple `Stack`s that share the same instance of `RestApi` will not resolve this problem, since the CDK still makes an executive decision to keep the Methods and Resources in the same stack as the `RestApi` construct. (see #7391) This change introduces a new import style API `fromRestApiAttributes()` that returns an instance of `IRestApi` that allows for new Resources to be defined across stacks. As a nice side effect, this change also adds the ability to define Resources on SpecRestApi in addition to what has already been defined in the OpenAPI spec. closes #1477 closes #7391 fixes #8347 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Mhh it doesn't look like that the chick-and-egg problem is solved. I can't see that the code handles that somehow. I worked around that with deploying two times and doing a json merge to have the x-amazon-apigateway-integration into the spec. I described it in the Workaround section here: https://martinmueller.dev/cdk-swagger-eng/ but yeah is kind of hard to explain. |
I'm still seeing this as well, just in Typescript. I am creating a LambdaFunction and a LambdaIntegration for that function so that they can be the default handler. If I give that toa SpecRestApi, it just ignores it and throws an exception: No integration defined for method (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: fcf92d52-dab4-4c7e-9b0c-598f77ed5ba3) |
Re-opening to investigate. |
Re-reading some of the comments here. The CDK does not open and read the OpenAPI definition files. This means that any value provided under Perhaps having a If I've misunderstood and this is not what you're trying to do, could you please clarify and provide code examples for reproduction? |
@nija-at Actually, I think it might just be fine to call this out clearly in the documentation, as I had interpreted the name @mmuller88 I got around the chicken and the egg problem by templating the API spec, rather than having to do two deployments and I used Mustache. So, for a CDK defined API in Java, I added this to the dependencies:
Then, within the API spec, I defined things like:
Finally, within the CDK definition, I did this:
I found some bizarre dependency issues that sometimes cropped up where the deployment seemed to happen before the Lambda permissions had been created and then the ApiGateway would not be able to invoke the functions, even though the permissions had been set. I'd have to re-deploy the API in the console in order to have the permissions set correctly, so I can only assume that the ApiGateway, when it creates a deployment, takes a copy of the Lambda permissions as they exist at that moment of deployment, and any subsequent changes have no effect. To get around this, I needed to do the following:
|
I think it creates some confusion only because there is some assumption
that it helps with defining the required pieces for OpenApi. Removing it
would make it clearer that there is no functionality there and folks need
to, unfortunately, roll their own solution.
Maybe an example of how it's intended to work would help. There are a lot
of people parsing the spec and inserting tokens and such. Is that what we
are expected to do? If so, simply saying that would help people understand
the intent. I personally intend to do that under the assumption that if I
push tokens from the synth process into a document that will be passed to
apigateway that cdk will substitute the tokens along the way. As such I'm
generating the integrations in memory and plan to insert function arns and
the like along the way - then pass that token filled doc to the restapi. It
appears that I will get all the function deploys before the restapi is
generated so - all good ;)
…On Tue, Jun 30, 2020, 4:51 AM Niranjan Jayakar ***@***.***> wrote:
Re-reading some of the comments here.
The CDK does not open and read the OpenAPI definition files. This means
that any value provided under defaultIntegration or any other property in
the CDK application will only apply to Methods and Resources in the CDK
app. We are not able to (and currently do not) apply these to the Methods
and Resources defined in the OpenAPI definitions.
Perhaps having a defaultIntegration property on SpecRestApi is creating
this confusion. Would it be less ambiguous if this property was removed
entirely and users had to explicitly define the integration for each API?
If I've misunderstood and this is not what you're trying to do, could you
please clarify and provide code examples for reproduction?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8347 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXNUTCOCDYXDW4N4E5TXDRZGYRLANCNFSM4NR34JDA>
.
|
SpecRestApiProps contained `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` as properties. However, these defaults are only applied to Methods and Resources defined via addMethod() and addResource() APIs. These do *not* apply to Resources and Methods defined in the OpenAPI spec. Users have complained that this is unclear[1][2]. This PR removes these options from the constructor properties of `SpecRestApi`. Users can still specify these when adding new Resources and new Methods. These options don't make much sense to be specified on a `SpecRestApi` since they cannot be applied to the Resources and Methods in the OpenAPI spec. This will match up with the functionality available. closes #8347 [1]: #8347 (comment) [2]: #8347 (comment) BREAKING CHANGE: `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` have been removed from `SpecRestApiProps`.
SpecRestApiProps contained `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` as properties. However, these defaults are only applied to Methods and Resources defined via addMethod() and addResource() APIs. These do *not* apply to Resources and Methods defined in the OpenAPI spec. Users have complained that this is unclear [1] [2]. This PR removes these options from the constructor properties of `SpecRestApi`. Users can still specify these when adding new Resources and new Methods. These options don't make much sense to be specified on a `SpecRestApi` since they cannot be applied to the Resources and Methods in the OpenAPI spec. This will match up with the functionality available. closes #8347 [1]: #8347 (comment) [2]: #8347 (comment) BREAKING CHANGE: `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` have been removed from `SpecRestApiProps`. These can be specifed directly in the OpenAPI spec or via `addMethod()` and `addResource()` APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
) SpecRestApiProps contained `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` as properties. However, these defaults are only applied to Methods and Resources defined via addMethod() and addResource() APIs. These do *not* apply to Resources and Methods defined in the OpenAPI spec. Users have complained that this is unclear [1] [2]. This PR removes these options from the constructor properties of `SpecRestApi`. Users can still specify these when adding new Resources and new Methods. These options don't make much sense to be specified on a `SpecRestApi` since they cannot be applied to the Resources and Methods in the OpenAPI spec. This will match up with the functionality available. closes aws#8347 [1]: aws#8347 (comment) [2]: aws#8347 (comment) BREAKING CHANGE: `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` have been removed from `SpecRestApiProps`. These can be specifed directly in the OpenAPI spec or via `addMethod()` and `addResource()` APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The documentation states about
defaultIntegration
:Yet when I define an API with no integration defined within the OpenAPI spec, the default integration is ignored and an error occurs when deploying.
Reproduction Steps
where
myLambda
is a lambda defined earlier in the CDK.The OpenApi spec has a single method defined (the header and model are not shown):
Error Log
The following error appears in the CloudFormation events when deploying:
No integration defined for method (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 56113150-1460-4ed2-93b9-a12618864582)
Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: