Skip to content

Commit

Permalink
Merge pull request #70 from elkelk/master
Browse files Browse the repository at this point in the history
Add API Gateway IntegrationResponse header support
  • Loading branch information
Jorge Bastida committed Apr 6, 2017
2 parents 5289cf3 + 80cb3ef commit 3f393ab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
30 changes: 28 additions & 2 deletions docs/eventsources/apigateway.rst
Expand Up @@ -349,7 +349,15 @@ Required No
Valid Values ``list``
Description The response that API Gateway provides after a method's back end completes processing a request.
API Gateway intercepts the integration's response so that you can control how API Gateway surfaces back-end
responses.
responses. Each response item can conatain the following keys: ``pattern``: a regular expression that
specifies which error strings or status codes from the back end map to the integration response; ``code``:
the status code that API Gateway uses to map the integration response to a MethodResponse status code;
``template``: the templates used to transform the integration response body; ``parameters``: the response
parameters from the back-end response that API Gateway sends to the method response. Parameters can be used
to set outbound CORS headers: ``method.response.header.Access-Control-Allow-Origin: "'*'"`` or to map custom
dynamic headers: ``method.response.header.Custom: "integration.response.body.customValue"``


=========================== ============================================================================================================

Example:
Expand Down Expand Up @@ -431,7 +439,25 @@ Full Example
responses:
- code: "200"
parameters:
method.response.header.color: color
method.response.header.color: color
/cors:
methods: GET
integration:
lambda: helloworld.hellopy
responses:
- pattern: ""
code: "200"
parameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Allow-Methods: "'*'"
method.response.header.Access-Control-Request-Method: "'GET'"
responses:
- code: "200"
parameters:
method.response.header.Access-Control-Allow-Origin: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Request-Method: true
/hi/complex/:
methods:
Expand Down
19 changes: 19 additions & 0 deletions examples/apigateway/settings.yml
Expand Up @@ -48,6 +48,25 @@ apigateway:
parameters:
method.response.header.color: color

/cors:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration-integrationresponse.html
methods: GET
integration:
lambda: helloworld.hellopy
responses:
- pattern: ""
code: "200"
parameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Allow-Methods: "'*'"
method.response.header.Access-Control-Request-Method: "'GET'"
responses:
- code: "200"
parameters:
method.response.header.Access-Control-Allow-Origin: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Request-Method: true

/shop/{item}:
methods: GET
integration:
Expand Down
2 changes: 2 additions & 0 deletions gordon/resources/apigateway.py
Expand Up @@ -157,6 +157,8 @@ def get_integration_responses(self, resource):
responses = []
for response in resource['integration'].get('responses', default_integration_responses):
extra = {}
if 'parameters' in response:
extra['ResponseParameters'] = response['parameters']
if 'template' in response:
extra['ResponseTemplates'] = response['template']
responses.append(
Expand Down

0 comments on commit 3f393ab

Please sign in to comment.