I am currently using Swagger to define an API with many end-points, and each one of those end-points all have the same definition for the 'x-amazon-apigateway-integration' key. I would like to define this somewhere in the document, and re-use that definition through-out.
Either I am not understanding how the definition should be defined, I am not placing it in the correct location or a mix of the two. I have tried defining this definition within 'definitions', and as some alias under it's own key. The definition (with key information removed) is:
x-amazon-apigateway-integration:
responses:
default:
statusCode: '200'
passthroughBehavior: when_no_match
httpMethod: POST
uri: >-
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
credentials: '<role arn>'
type: aws
requestTemplates: "application/json": "<object definition>"
I have tried defining this as an alias under it's own key (not definitions, but the same base scope):
amazon:
Amazon: &Amazon
- responses:
default:
statusCode: '200'
- passthroughBehavior: when_no_match
- httpMethod: POST
- uri: >-
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
- credentials: '<role arn>'
- type: aws
- requestTemplates:
"application/json": "<object definition>"
To use, I have the following:
x-amazon-apigateway-integration:
*Amazon
The error received on API Gateway import is 'Unable to parse API definition because of a malformed integration at path /'
I have also tried defining this under 'definitions', and using 'ref' to access it:
definitions:
Amazon:
type: object
x-amazon-apigateway-integration:
responses:
default:
statusCode: '200'
passthroughBehavior: when_no_match
httpMethod: POST
uri: >-
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
credentials: '<role arn>'
type: aws
requestTemplates:
"application/json": "<object definition>"
To use, I have the following:
x-amazon-apigateway-integration:
$ref: '#/definitions/Amazon'
On import to API Gateway I receive the following error(s):
Your API was not imported due to errors in the Swagger file.
Thank you in advance for your help.
Select Amazon API Gateway Integration from the list of integrations. Enter integration parameters: Name – A display name for this integration. AWS Region – Select the AWS region where you want to publish your API or that contains the existing API you want to publish to.
As mentioned before, AWS API Gateway can be configured by using API specifications written in Swagger. Additionally, a set of extensions have been defined for the API Gateway to capture most of its specific properties, like integrating Lambda functions or using Authorizers.
Before you create your API Gateway API, you need to give API Gateway permission to call Step Functions API actions. Sign in to the IAM console and choose Roles, Create role. On the Select type of trusted entity page, under AWS service, select API Gateway from the list, and then choose Next: Permissions.
Currently, API Gateway supports OpenAPI v2. 0 and OpenAPI v3. 0 definition files.
Using YAML anchors seems like a good idea. The correct syntax is as follows.
Add the following on the root level of your OpenAPI file:
x-definitions: # <--- "x-" before "definitions" prevents it from being
# attempted to be parsed as an OpenAPI Schema object.
Amazon:
type: object
x-amazon-apigateway-integration: &Amazon # <--- "&Amazon" is the anchor
responses:
default:
statusCode: '200'
passthroughBehavior: when_no_match
httpMethod: POST
uri: >-
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
credentials: '<role arn>'
type: aws
requestTemplates:
"application/json": "<object definition>"
Then you can refer to the anchor like this:
x-amazon-apigateway-integration: *Amazon
However, it might be that AWS parser does not support YAML anchors (&...
, *...
). In that case you can try pre-processing your definition using a parser that can resolve YAML anchors and then feed the resolved file to AWS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With