0
votes

I am relatively new to AWS API Gateway. I am trying to make use of OpenAPI Components in the OpenAPI definition for the API Gateway.

I am trying to build reusable responses for the integration response as illustrated below.

This is a reusable component for 400 response (along with the mapping template for it):

    components:
      responses:
        BAD_REQUEST:
          statusCode: "400"
          responseTemplates:
            application/json: "#set($inputRoot = $input.path('$'))\n{ \n  \"message\"\
                : \"Invalid Request Body\"\n}"

And I am trying to use this under responses in the API Gateway Integration like below:

          x-amazon-apigateway-integration:
            <API_GATEWAY_CONFIG_GOES_HERE>
            responses:
              .*"BadRequest".*:
                $ref: '#/components/responses/BAD_REQUEST'

When I deploy the whole CloudFormation stack I got that error and the stack could not be deployed:

Unable to put integration response on 'POST' for resource at path '/test_resource': Integration response status code must be non-empty

Any ideas?

1
Did you get your answer?Pablo
@Pablo, unfortunately no.m.y.m
Did you try YAML anchors? Although they fall out of the scope of OpenApi and cloudformation but this might fit your case. stackoverflow.com/questions/53297072/… I am still looking for a better alternative since you will need to run pakage command before deploy if you use anchors From aws docs you can try this: docs.aws.amazon.com/apigateway/latest/developerguide/… But i haven't been able to get it working though!json singh

1 Answers

0
votes

I have spent a few days searching for this and the only possible way is YAML anchors: You can check the code from:

Additionally, this official way from AWS doesn't seem to work as of now!