如何在AWS Lambda上使用环境变量? [英] How can I use environmental variables on AWS Lambda?

查看:662
本文介绍了如何在AWS Lambda上使用环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个我想作为AWS Lambda功能运行的应用程序,但也遵循十二要素应用程序指南。特别是第三部分。配置,它需要使用环境变量进行配置。



但是,我找不到一种为AWS Lambda实例设置环境变量的方法。任何人都可以指向正确的方向吗?



如果不可能使用环境变量,您可以建议一种方法来使用环境变量进行本地开发,并将其转换为有效的配置系统,可以使用AWS中的应用程序代码访问。



谢谢。

解决方案

截至2016年11月18日,AWS Lambda 支持环境变量。



环境变量可以是指定都使用AWS控制台和AWS CLI。这就是您将如何使用AWS CLI创建具有 LD_LIBRARY_PATH 环境变量的Lambda:

  aws lambda create-function \ 
--region us-east-1
--function-name myTestFunction
--zip文件fileb:// path / package。 zip
--role role-arn
--environment变量= {LD_LIBRARY_PATH = / usr / bin / test / lib64}
--handler index.handler
--runtime nodejs4 .3
--profile default


I'm writing an application which I want to run as an AWS Lambda function but also adhere to the Twelve-Factor app guidelines. In particular Part III. Config which requires the use of environmental variables for configuration.

However, I cannot find a way to set environmental variables for AWS Lambda instances. Can anyone point me in the right direction?

If it isn't possible to use environmental variables can you please recommend a way to use environmental variables for local development and have them transformed to a valid configuration system that can be accessed using the application code in AWS.

Thanks.

解决方案

As of November 18, 2016, AWS Lambda supports environment variables.

Environment variables can be specified both using AWS console and AWS CLI. This is how you would create a Lambda with an LD_LIBRARY_PATH environment variable using AWS CLI:

aws lambda create-function \
  --region us-east-1
  --function-name myTestFunction
  --zip-file fileb://path/package.zip
  --role role-arn
  --environment Variables={LD_LIBRARY_PATH=/usr/bin/test/lib64}
  --handler index.handler
  --runtime nodejs4.3
  --profile default

这篇关于如何在AWS Lambda上使用环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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