如何检查 Python 应用程序是否在 AWS lambda 函数中运行? [英] How to check if Python app is running within AWS lambda function?

查看:28
本文介绍了如何检查 Python 应用程序是否在 AWS lambda 函数中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到数据库的 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.com/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.com/lambda/latest/dg/python-programming-model-handler-types.html

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆