简体   繁体   English

本地运行lambda时知道

[英]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.

相关问题 无法从另一个本地运行的应用程序调用本地运行的 lambda - Cannot invoke a locally running lambda from another locally running application 在本地运行 CDK API - Lambda function 在本地不起作用 - Running CDK API Locally - Lambda function doesn't work locally 本地测试时Lambda超时 - Lambda times out when testing locally 用 curl 在本地测试 lambda - Test lambda locally with curl 在 Fedora 32 上使用 AWS SAM 命令在本地运行 lambda function 时出现问题。Docker 问题 - Problem running lambda function locally with AWS SAM command on Fedora 32. Docker problem 在本地测试 Cloud Functions 时 Cloud Firestore 模拟器未运行 - Cloud Firestore emulator not running when testing Cloud Functions locally 在本地调试 AWS Lambda 层 - Debug AWS Lambda Layer locally 无法在 Rider 中本地调试 Lambda - Unable to Debug Lambda locally in Rider 通过无服务器离线在本地运行时加载环境变量 - Load environment variables when running locally via serverless offline 使用 Lambda 的 AWS SAM API 端点在使用“sam start local-api”在本地运行时抛出错误 - AWS SAM API endpoint using a Lambda is throwing error when it runs locally with "sam start local-api"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM