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

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

问题描述

我正在编写一个应用程序,我想将它作为 AWS Lambda 函数运行,但同时也遵守十二要素应用程序指南.特别是 第三部分.Config 需要使用环境变量进行配置.

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.

但是,我找不到为 AWS Lambda 实例设置环境变量的方法.谁能指出我正确的方向?

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

如果无法使用环境变量,您能否推荐一种使用环境变量进行本地开发的方法,并将它们转换为可以使用 AWS 中的应用程序代码访问的有效配置系统.

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.

谢谢.

推荐答案

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

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

环境变量可以使用 AWS 控制台和 AWS CLI指定.这就是您使用 AWS CLI 创建具有 LD_LIBRARY_PATH 环境变量的 Lambda 的方式:

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天全站免登陆