Skip to content

Commit

Permalink
Merge f6b172d into 640d5cf
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn-spire committed Apr 28, 2019
2 parents 640d5cf + f6b172d commit 127f8df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ python:
- "3.5"
- "3.6"

before_install:
# Because Travis has some special configuration for boto that interfere
# https://github.com/travis-ci/travis-ci/issues/7940
- "sudo rm -f /etc/boto.cfg"

install:
- pip install tox-travis coveralls

Expand Down
15 changes: 8 additions & 7 deletions raven_python_lambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def decorated(event, context):

# Gather identity information from context if possible
if event.get('requestContext'):
identity = event['requestContext']['identity']
identity = event['requestContext'].get('identity')
if identity:
raven_context['user'] = {
'id': identity.get('cognitoIdentityId', None),
Expand All @@ -163,11 +163,12 @@ def decorated(event, context):
}

# Add additional tags for AWS_PROXY endpoints
raven_context['tags'] = {
'api_id': event['requestContext']['apiId'],
'api_stage': event['requestContext']['stage'],
'http_method': event['requestContext']['httpMethod']
}
if 'apiId' in event['requestContext']:
raven_context['tags'] = {
'api_id': event['requestContext']['apiId'],
'api_stage': event['requestContext']['stage'],
'http_method': event['requestContext']['httpMethod']
}

# Add cloudwatch event context
if event.get('detail'):
Expand All @@ -189,7 +190,7 @@ def decorated(event, context):
'data': {}
}

if event.get('requestContext'):
if event.get('requestContext') and 'httpMethod' in event['requestContext']:
breadcrumb['data'] = {
'http_method': event['requestContext']['httpMethod'],
'host': (event['headers'] or {}).get('Host'),
Expand Down
15 changes: 14 additions & 1 deletion raven_python_lambda/tests/test_decorator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import threading
from time import sleep
import os

import pytest

Expand Down Expand Up @@ -75,3 +74,17 @@ def f(event, context):
wrapper = RavenLambdaWrapper()
assert wrapper.config['enabled']
assert wrapper.config['raven_client']


def test_doesnt_error_out_if_request_context_is_present_but_not_all_keys():
"""You can use lambda together with Application Load Balancer (ALB)
which uses a different set of keys than previously set. This test
covers all the keys that are available when called by an ALB.
"""
event = dict(requestContext=dict(elb=dict(targetGroupArn='arn:aws:something')))

@RavenLambdaWrapper()
def test_func(event, context):
return dict(success=True)

assert test_func(event, FakeContext()) == dict(success=True)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py36
envlist = py27,py36,py37

[testenv]
passenv =
Expand Down

0 comments on commit 127f8df

Please sign in to comment.