Serverless-application-model: Create AWS::Serverless::GatewayResponse resource

Created on 15 Feb 2019  路  12Comments  路  Source: aws/serverless-application-model

There's a number of issues raised by customers regarding the mix of AWS::Serverless::Api and AWS::ApiGateway::GatewayResponse

We should do better and create a resource to ensure this works. From my understanding this is a result of merge behaviour and quirks in CFN.

623

contributorgood-first-issue typfeature

Most helpful comment

Released with SAM v1.11.0!

All 12 comments

Would it make sense to extend the AWS::Severless:Api resource with gateway responses to avoid adding another Serverless resource?

Example:

Resources:
  ExampleAPI:
      Type: 'AWS::Serverless::Api'
      Properties:
          GatewayResponses:
              - Parameters:
                    gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
                Type: 'DEFAULT_4XX'

I think the above would be very useful and a 'simple' solution to the problem.
Might even be possible to simplify the above a bit too.
For example, drop gatewayresponse. since that could be added by SAM.

@carlnordenfelt is correct, we would need to extend the AWS::Serverless::Api with a GatewayResponses parameter instead of creating a new resource. In this case we would probably just pass through anything defined on GatewayResponses and apply it as x-amazon-apigateway-gateway-responses in the Swagger body.

Note we are talking more about the "Merge" feature I alluded to in #623 which will effectively do this pass through.

If only it wasn't python :)

@carlnordenfelt curious which language you would prefer.

@brettstack feels like we are hijacking the issue a bit but my go to is nodejs or even Java. Not too familiar with the ins and outs of python.

@brettstack I would love to work on the above issue.

@Buffer0x7cd Absolutely! Go ahead and give it a try, and reach out if you have any questions!

@Buffer0x7cd I'm also working on this -- I hope we're not duplicating each other's work too much! Let's sync up if you've already started.

In my implementation, I've broken it down a little more than it was in this comment. For example, to recreate (kinda) my use-case from #623:

ExplicitApi:
  Type: AWS::Serverless::Api
  Properties:
    StageName: Prod
    GatewayResponses:
      UNAUTHORIZED:
        StatusCode: 401
        ResponseParameters:
          Headers:
            Access-Control-Expose-Headers: "'WWW-Authenticate'"
            Access-Control-Allow-Origin: "'*'"
            WWW-Authenticate: >-
              'Bearer realm="admin"'

(I grabbed this from one of the test cases -- please don't think it's fully representative.)

I'm a hair over 95% coverage, but I'm not sure I've covered all the negative cases I want to. Once the codey part is done, I'll open a PR. I think I'll need more help with the spec language than with the Python.

This is now in #841.

Hey, while I'm here, is the translator meant to be runnable from the bin directory? I had to move it up one to the project root before it would run.

@chrisoverzero I do that too haha. It has a few other bugs as well, it needs to be updated.

Released with SAM v1.11.0!

Was this page helpful?
0 / 5 - 0 ratings