defaultMethodOptions in SpecRestApi is confusing
See original GitHub issueThe documentation states about defaultIntegration
:
An integration to use as a default for all methods created within this API unless an integration is specified.
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
SpecRestApi openapiRestApi = SpecRestApi.Builder.create(this, "MyApi")
.restApiName("MyApi")
.apiDefinition(ApiDefinition.fromAsset("openapi.yaml"))
.defaultIntegration(LambdaIntegration.Builder.create(myLambda)
.proxy(false)
.build())
.deploy(true)
.build();
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):
paths:
/items:
get:
summary: List all items.
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ItemList'
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
- CLI Version : 1.42.0
- Framework Version: 1.42.1
- Node.js Version: v12.16.0
- OS : Windows
- Language (Version): Java
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
aws-cdk/aws-apigateway module - AWS Documentation
This is to prevent people duplication of these properties and potential confusion. Endpoint configuration. By default, SpecRestApi will create an edge optimized ...
Read more >@aws-cdk/aws-apigateway | Yarn - Package Manager
The defaultIntegration and defaultMethodOptions properties can be used to configure a default integration at any resource level. These options will be used ...
Read more >awsapigateway - Go Packages
See reference documentation for default method options. The following example defines the booksBackend integration as a default integration. This means that all ...
Read more >Ask Question - Stack Overflow
How to do lambda integrations for API Gateways defined with AWS CDK SpecRestApi and swagger.yml/openapi · Ask Question. Asked 8 months ago.
Read more >OpenAPI Specs from CDK Stack WITHOUT Deploying First
defaultMethodOptions && props.apiProps.defaultMethodOptions.authorizer) { this.openApiSpec.components.securitySchemes.authorizer = { 'type': ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nija-at Actually, I think it might just be fine to call this out clearly in the documentation, as I had interpreted the name
defaultIntegration
to mean exactly that, i.e. if I do nothing then it is the integration used, come what may, whereas it is only ever used if the API is defined using CDK Methods and Resources.@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 notifications@github.com wrote: