[英]How is it possible to debug an AWS Lambda function from remote?
We are taking over a whole application from another company, and they have built the whole pipeline for deploying, but we still don't have access to it.我们正在从另一家公司接管整个应用程序,他们已经构建了整个部署管道,但我们仍然无法访问它。 What we know, that there's a lambda function is running triggered by certain SNS messages, and all the code is in Node.js, and the development is in VS Code.我们知道,有一个 lambda 函数正在运行,由某些 SNS 消息触发,所有代码都在 Node.js 中,开发是在 VS Code 中。 We also have issues debugging it locally, but it's a bigger problem, that we need to debug it remotely.我们在本地调试它也有问题,但这是一个更大的问题,我们需要远程调试它。
Since I am new in AWS services, I'd really appreciate if somebody could help me in this.由于我是 AWS 服务的新手,如果有人能在这方面帮助我,我将不胜感激。 Does it necessary to open a port?有必要开一个端口吗? How is it possible to connect to a lambda?如何连接到 lambda? Do we need serverless to setup?我们需要无服务器来设置吗? Many unresolved questions.许多未解决的问题。
I don't think there is way you can debug a lambda function remotely.我认为没有办法可以远程调试 lambda 函数。 Your best bet is to download the code on local machine, setup the env variables as you have set up on your lambda function and take it from there.你最好的办法是在本地机器上下载代码,设置你在 lambda 函数上设置的环境变量,然后从那里获取它。
Remember at the end of the day lambda is just a container which is running the code for you.请记住,在一天结束时,lambda 只是一个为您运行代码的容器。 AWS doesn't allow any ssh or connection with those container. AWS 不允许任何 ssh 或与这些容器的连接。 In your case you should be able to debug it on local till you have the same env variables.在您的情况下,您应该能够在本地调试它,直到您拥有相同的环境变量。 There are other things as well which are lambda specific but considering it is a running code which you have got so you should be able to find out the issue.还有其他一些特定于 lambda 的东西,但考虑到它是您拥有的运行代码,因此您应该能够找出问题所在。
Hope it makes sense.希望这是有道理的。
Thundra ( https://www.thundra.io/aws-lambda-debugger ) 通过其原生 IDE 插件(VSCode 和 IntelliJ IDEA)为 AWS Lambda 提供实时/远程调试支持。
While far from ideal, any console-printing actions would likely get logged to CloudWatch, which you could then access to go through printed data.虽然远非理想,但任何控制台打印操作都可能会记录到 CloudWatch,然后您可以访问它以查看打印的数据。
For local debugging, there are many Github projects with Dockerfile
s which which you can build a docker container locally, just like AWS does when your Lambda is invoked.对于本地调试,有许多带有Dockerfile
的 Github 项目,您可以在本地构建一个 docker 容器,就像 AWS 在调用您的 Lambda 时所做的那样。
The way AWS have you 'remote' debug is to execute the lambda locally through Docker as it proxies the requests to the cloud for you, using AWS Toolkit. AWS 让您“远程”调试的方式是通过 Docker 在本地执行 lambda,因为它使用 AWS Toolkit 为您代理对云的请求。 You have a lambda running on your local computer via docker that can access resources on the cloud, such as databases, api's etc. You can step through debug them using editors like vscode.您有一个通过 docker 在本地计算机上运行的 lambda,它可以访问云上的资源,例如数据库、api 等。您可以使用 vscode 等编辑器逐步调试它们。
I use SAM with a template.yaml .我将 SAM 与 template.yaml 一起使用。 This way, I can pass event data to the handler, reference dependency layers (shared code libraries) and have a deployment manifest to create a Cloudformation stack (release instance with history and resource management).这样,我可以将事件数据传递给处理程序、引用依赖层(共享代码库)并拥有一个部署清单来创建 Cloudformation 堆栈(发布具有历史和资源管理的实例)。
Debugging can be a bit slow as it compiles, deploys to Docker and invokes, but allows step through debugging and variable inspection.调试在编译、部署到 Docker 和调用时可能会有点慢,但允许逐步调试和变量检查。
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging.html https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.