question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS Lambda uses ThreadedHTTPTransport instead of HTTPTransport

See original GitHub issue

In AWS Lambda environment, HTTPTransport should be used instead of the default ThreadedHTTPTransport (this was added in #828). Which HTTP transport to use is determined based on the presence of the LAMBDA_TASK_ROOT environment variable. But in my case ThreadedHTTPTransport is used, even though LAMBDA_TASK_ROOT is there.

I discovered this when noticing that some of the errors were not being reported to Sentry.

Why this happens?

It seems that when instantiating the Client from DSN, the default transport is used, and the one determined by discover_default_transport is ignored.

How to fix this?

The discover_default_transport should be taken into account when using RemoteConfig.from_string. If this is not acceptable, the docs should mention that transport needs to be manually set to raven.transport.http.HTTPTransport when using Sentry on AWS Lambda.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ashwoodscommented, Aug 23, 2017

Im porting https://github.com/Netflix-Skunkworks/raven-python-lambda to raven, but in the meanwhile you can Check out their implementation. On Wed, 23 Aug 2017 at 12:08, Jure Cerjak notifications@github.com wrote:

Not sure why it doesn’t work, maybe I’m doing something wrong…

Steps to reproduce the issue

  1. Create a lambda function with content:

import os from raven import Client

client = Client(os.environ[‘SENTRY_DSN’])

@client.capture_exceptions def lambda_handler(event, context): raise Exception(‘Error!’)

  1. Package the lambda for Python 2.7 as per AWS instructions http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html, together with dependencies (raven==6.1.0 and contextlib2==0.5.5). I’ve built the package in the AWS environment http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html, though in this case it probably doesn’t make a difference, since there are no C extensions.
  2. Deploy the lambda package to AWS, with Python 2.7 environment. Set SENTRY_DSN environment variable (https://…)
  3. Trigger the lambda. No errors are logged in Sentry.
  4. Replace the lambda code with:

import os from raven import Client from raven.transport.http import HTTPTransport

client = Client(os.environ[‘SENTRY_DSN’], transport=HTTPTransport)

@client.capture_exceptions def lambda_handler(event, context): raise Exception(‘Error!’)

  1. Trigger the lambda again. Now the error should show up in Sentry.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/getsentry/raven-python/issues/1063#issuecomment-324284102, or mute the thread https://github.com/notifications/unsubscribe-auth/AAW4tclk1F6JgFPn8szQjDqMPb4-UP3Mks5sa_oZgaJpZM4O-0XS .

0reactions
riteshshrvcommented, Jan 6, 2018

SentryHandler does not send errors to sentry when log level is set to ERROR on Lambda. I’m using dictConfig to configure logging with this handler, is there something I need to do to get this working?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lambda functions as targets - Elastic Load Balancing
Learn how to register a Lambda function as a target with an Application Load Balancer.
Read more >
Announcing AWS Lambda Function URLs: Built-in HTTPS ...
When creating a new function, I check Enable function URL in Advanced Settings. Here, I select Auth type: AWS_IAM or NONE. My webhook...
Read more >
Invoking Lambda function URLs - AWS Documentation
Invoke your Lambda function through a dedicated HTTP(S) endpoint using a web ... URL uses the AWS_IAM auth type, you must sign each...
Read more >
Lambda execution environment - AWS Documentation
For example, if your Lambda function establishes a database connection, instead of reestablishing the connection, the original connection is used in subsequent ...
Read more >
When not to use a Lambda function - AWS Documentation
In most cases, moving the orchestration flow to AWS Step Functions creates a more maintainable and resilient state machine, and can help reduce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found