如何检查 Python 应用程序是否在 AWS lambda 函数中运行?

编程入门 行业动态 更新时间:2024-10-25 06:24:02
本文介绍了如何检查 Python 应用程序是否在 AWS lambda 函数中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个连接到数据库的 Python 应用程序,我希望数据库凭据在本地环境(用于测试)或 lambda 函数(用于生产)中运行时不同.

I've got a Python application that connects to a database and I would like the db credentials to be different when it's running in local env (for testing) or within a lambda function (for production).

有什么方法可以从 Python 应用程序中检测它是否在 lambda 函数内运行?

Is there any way, from the Python app, to detect that it is running inside the lambda function?

推荐答案

查看其他答案,这是一个更好的解决方案:

See the other answer, this is a better solution:

os.environ.get("AWS_EXECUTION_ENV") is not None


原答案:


Original answer:

如何检查处理函数中是否存在 context 对象?http://docs.aws.amazon/lambda/latest/dg/python-programming-model-handler-types.html

How about checking for the existence of the context object in the handler function? http://docs.aws.amazon/lambda/latest/dg/python-programming-model-handler-types.html

这篇关于如何检查 Python 应用程序是否在 AWS lambda 函数中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 04:26:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034863.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   函数   Python   lambda   AWS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!