PagerDuty / pdpyras

Low-level PagerDuty REST/Events API client for Python
MIT License
129 stars 29 forks source link

Error encountered when invoking AWS Lambda function - PDClientError #135

Closed Paankajshah closed 1 month ago

Paankajshah commented 2 months ago

Every time I run my AWS Lambda code, I encounter the following error: [ERROR] PDClientError: POST https://events.pagerduty.com/v2/enqueue: Non-transient network error; exceeded maximum number of attempts (3) to connect to the API.

I am using AWS Lambda to trigger events in PagerDuty, however, I am consistently facing this error message. It seems to be related to a non-transient network error when attempting to connect to the PagerDuty API.

python version: 3.9 pdpyras versoin: 5.2.0

code:

from pdpyras.pdpyras import *

ROUTING_KEY = 'xyz'
def send_notification(title, description, trigger=False):
    if trigger:
        events_session = EventsAPISession(ROUTING_KEY)
        dedup_key = events_session.trigger(title, description)

this works fine in my local environment.

Deconstrained commented 2 months ago

Hi @Paankajshah ,

The following code in the lambda should result in a status 405 (method not allowed) from PagerDuty in the form of a urllib.error.HTTPError:

import urllib.request
urllib.request.urlopen('https://events.pagerduty.com/v2/enqueue')

Otherwise, it might tell us more specifically what kind of connection error results.

One way or another I suspect something in the lambda's network or DNS configuration that caused this and not the routing key, based on the error message. If the routing key doesn't match the expected format, the response would be 400, and if it did match the format the response would be 202, either of which would elicit different messages from pdpyras.

Deconstrained commented 2 months ago

Any luck reproducing the connection / DNS / etc error with urllib?