简体   繁体   English

AWS Lambda:如何获取环境变量

[英]AWS Lambda: How to get environment variables

Inside my lambda_handler function, how can I get the environment variables that I have defined?在我的lambda_handler function 中,如何获取我定义的环境变量?

def lambda_handler(event, context):
     
    # Get environment variables (see screenshot below)   
    key1 = event[0]
    key2 = event[1]
    key3 = event[2]

    return {
        'statusCode': 200,
        'body': key1
    }

Environment Variables环境变量在此处输入图像描述

These are not actually the environment variables, this is the event payload passed into the Lambda.这些实际上不是环境变量,这是传递给 Lambda 的事件负载。

In your case you would access this by accessing its keys in the structure ie event['key1'] .在您的情况下,您可以通过访问其结构中的键来访问它,即event['key1'] To reiterate this event contents are the payload passed in by the invoker (be that a service or the SDK).重申一下这个事件内容是调用者(无论是服务还是 SDK)传入的有效负载。

Environment variables do exist in Lambda, but are accessed in the native way the language would access the environment variables. Lambda 中确实存在环境变量,但是以语言访问环境变量的本机方式访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM