AWS Cloudformation:将环境变量作为参数传递给lambda函数 [英] AWS Cloudformation : Passing environmental variables as parameters to lambda functions

查看:279
本文介绍了AWS Cloudformation:将环境变量作为参数传递给lambda函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为lambda创建云层。我想要一个创建lambda的通用lambda脚本。我在从外部注入 Environment参数时遇到问题。

I am creating a cloud formation for lambda . I want to have a generic lambda script that created lambda . I am having problem injecting "Environment" parameter from outside .

我想将键值对对象作为parameter传递。有人能告诉我怎么做吗。我在下面突出显示了它

I want to pass the key value pair object as parameter . Can some one tell me how to do it . I have highlighted it below

{
  "Variables" : **{ String:String, ... }**
}

{
  "Type" : "AWS::Lambda::Function",
  "Properties" : {
    "Code" : Code,
    "DeadLetterConfig" : DeadLetterConfig,
    "Description" : String,
    "Environment" : Environment,
    "FunctionName" : String,
    "Handler" : String,
    "KmsKeyArn" : String,
    "MemorySize" : Integer,
    "ReservedConcurrentExecutions" : Integer,
    "Role" : String,
    "Runtime" : String,
    "Timeout" : Integer,
    "TracingConfig" : TracingConfig,
    "VpcConfig" : VPCConfig,
    "Tags" : [ Resource Tag, ... ]
  }
}


推荐答案

cloudformation模板中有一个特殊的部分- Parameters

For this purpose there is special section in cloudformation template - Parameters

"Parameters" : {
  "MyVariable" : {
    "Type" : "String",
    "Default" : "test",
    "AllowedValues" : ["test", "non-test"],
    "Description" : "My very important variable."
  }
}

然后在函数声明:

"Environment":{  
   "Variables":{  
      "SomeVariable":{  
         "Ref":"MyVariable"
      }
   }
}

然后从cloudformation模板创建堆栈时传递此Parameters块的值:

And then pass values for this Parameters block when creating stack from cloudformation template:

aws cloudformation create-stack --stack-name S1 --template-body example template --parameters ParameterKey=MyVariable,ParameterValue=myValue

更多信息-此处

这篇关于AWS Cloudformation:将环境变量作为参数传递给lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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