Skip to content

Commit

Permalink
Merge pull request #110 from sternik/lambda_proxy_integration
Browse files Browse the repository at this point in the history
Add Lambda Proxy integration to API Gateway
  • Loading branch information
Jorge Bastida committed Apr 6, 2017
2 parents b75e2e8 + fda8813 commit 617d451
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion docs/eventsources/apigateway.rst
Expand Up @@ -300,7 +300,7 @@ Integration Type
Name ``type``
Required No
Default AWS
Valid Values ``AWS``, ``MOCK``, ``HTTP``
Valid Values ``AWS``, ``AWS_PROXY``, ``MOCK``, ``HTTP``
Description Type of the integration
=========================== ============================================================================================================

Expand Down Expand Up @@ -425,6 +425,12 @@ Full Example
integration:
type: MOCK
/{integration+}:
methods: POST
integration:
lambda: helloworld.sayho
type: AWS_PROXY
/parameters:
methods: GET
parameters:
Expand Down
16 changes: 13 additions & 3 deletions gordon/resources/apigateway.py
Expand Up @@ -16,6 +16,7 @@
LAMBDA_INTEGRATION = 20
HTTP_INTEGRATION = 30
MOCK_INTEGRATION = 40
LAMBDA_PROXY_INTEGRATION = 50


class ApiGateway(BaseResource):
Expand Down Expand Up @@ -82,7 +83,8 @@ def get_integration_http_method(self, resource):
return http_method

integration_type = self._get_integration_type(resource)
if integration_type == LAMBDA_INTEGRATION:
if integration_type == LAMBDA_INTEGRATION or \
integration_type == LAMBDA_PROXY_INTEGRATION:
return 'POST'
else:
return 'GET'
Expand All @@ -91,6 +93,9 @@ def _get_integration_type(self, resource):
if 'integration' not in resource:
raise exceptions.InvalidApigatewayIntegrationTypeError("Resource has no integration".format(resource))
if 'lambda' in resource['integration']:
if 'type' in resource['integration'] and \
resource['integration']['type'] == 'AWS_PROXY':
return LAMBDA_PROXY_INTEGRATION
return LAMBDA_INTEGRATION
elif resource['integration']['type'] == 'HTTP':
return HTTP_INTEGRATION
Expand All @@ -106,16 +111,21 @@ def get_integration_type(self, resource):
return 'MOCK'
elif integration == LAMBDA_INTEGRATION:
return 'AWS'
elif integration == LAMBDA_PROXY_INTEGRATION:
return 'AWS_PROXY'
return None

def get_integration_credentials(self, resource, invoke_lambda_role):
if self._get_integration_type(resource) == LAMBDA_INTEGRATION:
integration_type = self._get_integration_type(resource)
if integration_type == LAMBDA_INTEGRATION or \
integration_type == LAMBDA_PROXY_INTEGRATION:
return troposphere.GetAtt(invoke_lambda_role, 'Arn')
return troposphere.Ref(troposphere.AWS_NO_VALUE)

def get_integration_uri(self, resource):
integration_type = self._get_integration_type(resource)
if integration_type == LAMBDA_INTEGRATION:
if integration_type == LAMBDA_INTEGRATION or \
integration_type == LAMBDA_PROXY_INTEGRATION:
return troposphere.Join(
'',
[
Expand Down

0 comments on commit 617d451

Please sign in to comment.