Skip to content
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

AWS Lambda unhandled exception #824

Closed
s1moe2 opened this issue Mar 26, 2024 · 9 comments
Closed

AWS Lambda unhandled exception #824

s1moe2 opened this issue Mar 26, 2024 · 9 comments

Comments

@s1moe2
Copy link
Contributor

s1moe2 commented Mar 26, 2024

Followed documentation to deploy PR Agent on AWS Lambda, to use in a github app.

When github tests with a ping request the response is a 502. Tried to use the app in the configured repo but it's not even making a request, I assume because the app is not in a ready state.

image

In CloudWatch I see logs related to the request, noticeably this warning:

LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html
[ERROR] Runtime.ImportModuleError: Unable to import module 'pr_agent.servers.serverless': No module named 'fastapi'
Traceback (most recent call last):

image

I've tried a few things related to env vars, as I was not sure it could be the problem, but I noticed no difference in any approach I tried.

@mrT23
Copy link
Collaborator

mrT23 commented Mar 26, 2024

@s1moe2

AWS lambda was added as a contribution by the community:
#92

We personally are not working with AWS LAMBDA, and are limited in our ability to support specific problems people encounter. I am not sure if its related to PR-Agent code, or the deployment. probably the latter

It's weird you see a "no module named fastapi" error, since its in a requirement.txt

Maybe try asking people who have worked with AWS LAMBDA with PR-Agent
https://github.com/search?q=repo%3ACodium-ai%2Fpr-agent+AWS+Lambda+&type=pullrequests

@koid were you able to deploy to AWS Lambda ?

@s1moe2
Copy link
Contributor Author

s1moe2 commented Mar 26, 2024

@mrT23 see my PR ☝️
I do have other problems, but at least this solves the missing dependencies.

Edit: the follow up problem was also related to the docker image created for Lambda, as it was missing git

@s1moe2
Copy link
Contributor Author

s1moe2 commented Mar 27, 2024

After resolving the Lambda issues I finally ran some tests. I'e tried to add a "/review" comment and to open a PR.
As seen in the image below, ignored events responded with success to the webhook. However, both meaningful events (review and new PR) responded with 502 but there are no logs of errors/exceptions.

image

image

@mrT23
Copy link
Collaborator

mrT23 commented Mar 27, 2024

@s1moe2
Why would it timeout after 3 seconds ?? Inference takes longer than that (usually 30-120 seconds)

I don't think this is something that comes from PR-Agent definitions

@mrT23
Copy link
Collaborator

mrT23 commented Mar 27, 2024

image

@s1moe2
Copy link
Contributor Author

s1moe2 commented Mar 27, 2024

Ah yes, my bad. I had not changed the default timeout. Thanks.

@s1moe2 s1moe2 closed this as completed Mar 27, 2024
@taimaruuu
Copy link

@s1moe2 How did you handle putting the github__private_key in the lambda environment variables. I've tried multiple ways of setting multi line strings and such but they all result in errors.

@s1moe2
Copy link
Contributor Author

s1moe2 commented Sep 3, 2024

@taimaruuu No idea how you are deploying. In my case, I am using OpenTofu, so I'm reading the content of a file using its features:

resource "aws_lambda_function" "codium_lambda" {
  ...

  environment {
    variables = {
      ...
      "GITHUB__PRIVATE_KEY"  = file(var.gh_app_pem_file)
    }
  }
}

I believe you should be able to also set the string directly by using \n characters.

@taimaruuu
Copy link

@s1moe2 I was having issues with it and tried multiple ways of doing it with \n, \n and more. Eventually settled for just storing the private key as a base64 encoded string in the variables and then adding code to decode it before using it for authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants