jorgebastida / gordon

λ Gordon is a tool to create, wire and deploy AWS Lambdas using CloudFormation
Other
2.05k stars 137 forks source link

Support for API Gateway IntegrationResponses ResponseParameters #68

Open elkelk opened 8 years ago

elkelk commented 8 years ago

Currently the only keys supported for the API Gateway under IntegrationResponses are pattern, status, and template: https://github.com/jorgebastida/gordon/blob/43d7bd02b9cf8c7a10234bf4b259c70e752cdf80/gordon/resources/apigateway.py#L160

ResponseParameters (parameters) is missing: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration-integrationresponse.html#cfn-apigateway-method-integration-integrationresponse-responseparameters

I could create a PR which adds this support, but it doesn't appear that any PRs are being merged currently. Is it worth the effort?

YoavGivati commented 8 years ago

This is related to https://github.com/jorgebastida/gordon/issues/56 since it's prevents setting values for CORS headers, which seems like a fairly common use case. PR would be great, the community can benefit from a patch that's reviewed and tested until it's merged. 💯

(active PRs are less than a month old and last PR merged was 25 days ago)

jorgebastida commented 8 years ago

I've been quite busy recently at work, so I took a small break. Planning to have some holidays in the following weeks, so I'll try to catch up.

tl;dr yes, PR are worth the effort :D

elkelk commented 8 years ago

Great, thanks for the responses. I'll get a PR up that will work for this and CORS.

YoavGivati commented 8 years ago

I tried the patch @elkelk suggested and set up my api gateway project config with:

apigateway:
  apitest:
    description: TEST API
    resources:            
      /kittens:
        methods:
          POST:
            integration:
              lambda: cats.smaller
              responses:
                - pattern: ""
                  code: "200"
                  parameters:
                    method.response.header.Access-Control-Allow-Origin: "'*'"
            responses:
              - code: "200"
                parameters:
                  method.response.header.Access-Control-Allow-Origin: True
          OPTIONS:
            request_templates:
              application/json: |
                {"statusCode": 200}
            integration:
              type: MOCK
              responses:
                - pattern: ""
                  code: "200"
                  template:
                    application/json: ""
                  parameters:
                    method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
                    method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
                    method.response.header.Access-Control-Allow-Origin: "'*'"
            responses:
              - code: "200"
                models: 
                  application/json: Empty
                parameters:                                
                  method.response.header.Access-Control-Allow-Headers: True
                  method.response.header.Access-Control-Allow-Methods: True
                  method.response.header.Access-Control-Allow-Origin: True

And it duplicates the same CORS configuration as API Gateway's 'Add CORS' button would.

It seems to work just as well same with setting the headers to method.response.header.Access-Control-Allow-Headers: True instead of specifying type: string but I understood from api gateway docs the proper way to do it is to specify the default type, :/ either way.

updated code snippet

elkelk commented 8 years ago

@YoavGivati on the contrary the boolean value is expected for the response parameters detailed here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-methodresponse.html

YoavGivati commented 8 years ago

Ah that makes sense. updated the snippet above