我试图在 Visaul Studio Code 中使用 lambda (python) 的调试功能。我按照 AWS Docs 上的说明进行操作,但无法在调试模式下触发 python 应用程序。
请看看您是否知道这个问题以及我是否设置错误,谢谢。
观察
开始申请
似乎应用程序未在指定的调试端口上启动?
请求致电
无法到达端点并且未进入python应用程序
如果通过端口 3000 访问,应用程序可以成功完成
初始化项目并按照指示安装ptvsd
在 python 代码上启用 ptvsd
添加启动配置
Python源码
这基本上只是 python 的官方 helloworld 示例
import json
# import requests
import ptvsd
# Enable ptvsd on 0.0.0.0 address and on port 5890 that we'll connect later with our IDE
ptvsd.enable_attach(address=('localhost', 5890), redirect_output=True)
ptvsd.wait_for_attach()
def lambda_handler(event, context):
"""Sample pure Lambda function
Parameters
----------
event: dict, required
API Gateway Lambda Proxy Input Format
Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
API Gateway Lambda Proxy Output Format: dict
Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
"""
# try:
# ip = requests.get("http://checkip.amazonaws.com/")
# except requests.RequestException as e:
# # Send some context about this error to Lambda Logs
# print(e)
# raise e
return {
"statusCode": 200,
"body": json.dumps({
"message": "hello world",
# "location": ip.text.replace("\n", "")
}),
}
慕标琳琳
相关分类