简体   繁体   English

aws lambda 实际运行什么命令来执行 Python 的处理程序?

[英]What command is aws lambda actually running to execute the handler for Python?

I can't find this in the docs我在文档中找不到这个

How is AWS lambda executing the Python handler? AWS lambda 如何执行 Python 处理程序? What is the actual python.exe commands being executed?正在执行的实际 python.exe 命令是什么? I would like to understand this better.我想更好地理解这一点。 Lambda behind the scenes is surely starting a container and somehow copying the uploaded package onto a volume or something. Lambda 在幕后肯定是在启动一个容器,并以某种方式将上传的 package 复制到一个卷或其他东西上。 But what command is it actually running to execute it?但是它实际上是在运行什么命令来执行它呢?

Edit编辑

I found this article which shows how to get a console session open to a lambda, have not checked to see if it still works:https://epsagon.com/blog/lambda-internals-exploring-aws-lambda/我发现这篇文章展示了如何让控制台 session 打开到 lambda,没有检查它是否仍然有效:Z5E056C500A1C4B6A7110B50D807BADE5-内部-exploring-awsblog/lambda-in/ternals-exploring-com

I don't have the exact answer as I think implementation details are secret, but to see how it could work, or potentially could be implemented in AWS, is the following project: lambci / docker-lambda :我没有确切的答案,因为我认为实施细节是秘密的,但要了解它如何工作,或者可能在 AWS 中实施,是以下项目: lambci / docker-lambda

A sandboxed local environment that replicates the live AWS Lambda environment almost identically – including installed software and libraries, file structure and permissions, environment variables, context objects and behaviors – even the user and running process are the same.一个沙盒本地环境,几乎完全相同地复制实时 AWS Lambda 环境——包括已安装的软件和库、文件结构和权限、环境变量、上下文对象和行为——甚至用户和运行过程都是相同的。

Since its open sourced, one would have to go through its source code to locate the exact thing you are after.由于它是开源的,因此必须通过其源代码 go 才能找到您想要的确切内容。

Obviously, this is not official AWS docker repository , but it should provide some good insights on how real AWS lambda environment could work in the back-end.显然,这不是官方的 AWS docker 存储库,但它应该为真正的 AWS lambda 环境如何在后端工作提供一些很好的见解。

This docker project is also recommended by AWS for using local lambda environment: AWS 还推荐此 docker 项目用于使用本地 lambda 环境:

When you get its python 3.8 runtime: https://lambci.s3.amazonaws.com/fs/python3.8.tgz you can find bootstrap.py file there.当你得到它的 python 3.8 运行时: https://lambci.s3.amazonaws.com/fs/python3.8.tgz你可以在那里找到bootstrap.py文件。 In the file there is the following function (only part is shown):在文件中有以下 function(仅显示部分):

123 def handle_event_request(lambda_runtime_client, request_handler, invoke_id, event_body, content_type,
124                          client_context_json, cognito_identity_json, invoked_function_arn, epoch_deadline_time_in_ms,
125                          log_sink):
126     error_result = None
127     try:
128         lambda_context = create_lambda_context(client_context_json, cognito_identity_json, epoch_deadline_time_in_ms,
129                                                invoke_id, invoked_function_arn)
130         event = lambda_runtime_client.marshaller.unmarshal_request(event_body, content_type)
131         response = request_handler(event, lambda_context)

The last line, response = request_handler(event, lambda_context) is actual invocation of your handler.最后一行response = request_handler(event, lambda_context)是处理程序的实际调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM