Skip to content

Feature request: improve error messaging around IdempotencyPersistenceLayerError #1772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
cgoettel opened this issue Dec 9, 2022 · 10 comments
Closed
2 tasks done
Assignees
Labels
feature-request feature request idempotency Idempotency utility

Comments

@cgoettel
Copy link

cgoettel commented Dec 9, 2022

Use case

I was trying to implement the basic example using Terraform to deploy the Lambda and DynamoDB. However, I had forgotten to include the policy for the Lambda to talk to DynamoDB and kept getting the following error:

[ERROR] IdempotencyPersistenceLayerError: Failed to save in progress record to idempotency store
Traceback (most recent call last):
  File "/var/task/aws_lambda_powertools/middleware_factory/factory.py", line 134, in wrapper
    response = middleware()
  File "/var/task/aws_lambda_powertools/utilities/idempotency/idempotency.py", line 79, in idempotent
    return idempotency_handler.handle()
  File "/var/task/aws_lambda_powertools/utilities/idempotency/base.py", line 97, in handle
    return self._process_idempotency()
  File "/var/task/aws_lambda_powertools/utilities/idempotency/base.py", line 116, in _process_idempotency
    raise IdempotencyPersistenceLayerError("Failed to save in progress record to idempotency store") from exc

Each error message is the same which isn't entirely helpful. So I dug through the code and could see that it was exception chaining, but that also wasn't particularly helpful. It wasn't until I tried to implement the basic example using AWS SAM that I was able to see the policy that I'd forgotten to attach.

Solution/User Experience

Ideally, something in the error chain would receive a bad permissions error and that information would percolate up to the user. Every other time I deploy into AWS I get clear permissions errors and the reason I didn't even consider a permissions issue is because it was always so clear previously when that was it.

Alternative solutions

No response

Acknowledgment

@cgoettel cgoettel added feature-request feature request triage Pending triage from maintainers labels Dec 9, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 9, 2022

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our AWS Lambda Powertools Discord: Invite link

@mploski mploski self-assigned this Dec 13, 2022
@mploski
Copy link
Contributor

mploski commented Dec 13, 2022

Hey @cgoettel, thanks for raising this issue. I agree we need to enrich the error message here to be more meaningful. I will start working on this in a few coming days (probably end of the week or beginning of the next one). Will update you about the progress

@heitorlessa heitorlessa added idempotency Idempotency utility and removed triage Pending triage from maintainers labels Dec 15, 2022
@mploski
Copy link
Contributor

mploski commented Dec 20, 2022

Hey @cgoettel. I was able to reproduce mentioned issue and I can confirm your observation, that lambda emits logs in the shape you shared in the ticket itself. Let me share some details about it, just for future reference or interested readers :-)


In idempotency feature we rely on “raise from” statement to raise an exception with extra information whenever we have problem. That works if I trigger handler code directly from my local environment (not from lambda). Then we get chained traces like in the following snippet:



urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPSConnection object at 0x11324b520>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

....


During handling of the above exception, another exception occurred:


raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: 
...
The above exception was the direct cause of the following exception:

...
aws_lambda_powertools.utilities.idempotency.exceptions.IdempotencyPersistenceLayerError: Failed to save in progress record to idempotency store




Lambda runtime behaves differently though. In a runtime bootstrap action we modify logging behavior.


We do multiple different actions there, but for our case what's important is that exceptions not handled gracefully in handler itself are managed by another exception block. This block is responsible for extracting an exception and traceback, formatting message and sending it to a stdout. Specifically, we use sys.exc_info() function to extract raised exception. It also means we skip all other nested exceptions as they are not returned by exc_info() function. That's why we cannot see them in Cloudwatch logs.





If you are interested in details please take a look at a lambda runtime bootstrap code: https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/970e9c1d2613e0ce9c388547c76ac30992ad0e96/awslambdaric/bootstrap.py#L157





I will work on exposing additional context from nested exceptions to make it visible in CloudWatch Logs.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jan 9, 2023
@mploski
Copy link
Contributor

mploski commented Jan 9, 2023

hey @cgoettel, we just merged changes to the Idempotency feature, that will improve error messaging and hopefully will simplify debugging or reasoning about potential issues in future. Thank you one more time for the contribution and making Lambda Powertools better :-)

@mploski mploski closed this as completed Jan 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions
Copy link
Contributor

This is now released under 2.6.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jan 12, 2023
@mattyweb
Copy link

mattyweb commented Feb 5, 2023

Lifesaver! Thanks!

Just found this thread and upgraded to the new PowerTools in order to troubleshoot. Trying an idempotent lambda in python and this was my first time using DynamoDB.

Had to add the following actions to my lambda config:
"Action": [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
],

Don't know how I would have figured this out otherwise. Might be good to add this to the PowerTools Idempotency docs! (Unless I just missed it!)

@heitorlessa
Copy link
Contributor

heitorlessa commented Feb 6, 2023 via email

@heitorlessa
Copy link
Contributor

@mattyweb we've just patched the live documentation with the IAM section for Idempotency - took us slightly longer to avoid leaking new features coming in the next release.

https://awslabs.github.io/aws-lambda-powertools-python/2.7.1/utilities/idempotency/#iam-permissions

Thank you again for flagging this!

@mattyweb
Copy link

mattyweb commented Apr 7, 2023

Totally missed the update here. Thanks so much for the doc fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request idempotency Idempotency utility
Projects
None yet
Development

No branches or pull requests

5 participants