[英]Know when running lambda locally
Is there a way with the AWS CLI to tell that you are running your lambda locally programmatically? AWS CLI 有没有办法告诉您正在以编程方式在本地运行 lambda? I'm trying to avoid adding extra data in the request.
我试图避免在请求中添加额外的数据。
I have some functionality that I don't want kicked off when I'm running locally, but I do once its up in the AWS cloud.我有一些我不想在本地运行时启动的功能,但一旦它在 AWS 云中运行,我就会启动。
Thanks谢谢
A first option is to use one of the environment variables that are available when a Lambda function is executed.第一个选项是使用在执行 Lambda function 时可用的环境变量之一。 The
AWS_EXECUTION_ENV
- like you stated in your comment - can be a good pick for this. AWS_EXECUTION_ENV
- 正如您在评论中所述 - 可能是一个不错的选择。
A second option is using the context object which is passed in as a second parameter to your handler function. This contains very specific information about the request, such as the awsRequestId
which could also help you in determining whether or not your code is running on the cloud or locally.第二种选择是使用上下文 object ,它作为第二个参数传递给您的处理程序 function。这包含有关请求的非常具体的信息,例如
awsRequestId
,它还可以帮助您确定您的代码是否正在运行云端或本地。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.