amazon-web-services - AWS 云信息 : Passing environmental variables as parameters to lambda functions

标签 amazon-web-services aws-lambda cloud aws-cloudformation

我正在为 lambda 创建云结构。我想要一个创建 lambda 的通用 lambda 脚本。我在从外部注入(inject)“环境”参数时遇到问题。

我想将键值对对象作为参数传递。有人可以告诉我该怎么做吗?我在下面突出显示了它

{
  "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" : {
  "MyVariable" : {
    "Type" : "String",
    "Default" : "test",
    "AllowedValues" : ["test", "non-test"],
    "Description" : "My very important variable."
  }
}

然后在Function声明中使用这些参数:

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

然后在从 cloudformation 模板创建堆栈时传递此参数 block 的值:

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

更多信息 - here

关于amazon-web-services - AWS 云信息 : Passing environmental variables as parameters to lambda functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51439163/

相关文章:

java - SQS FIFO 使用 MessageGroupId 接收消息

amazon-web-services - 如何处理对 Amazon Lex 的 lambda 响应?

javascript - Cloud Code 向响应添加属性

java - 需要更改Spring Cloud中的bootstrap环境

apache - 在 Elastic beanstalk 上设置 https 代理

android - 适用于 Android/iOS AWS 的最佳视频流选项

linux - 从终端输出中替换 Amazon EC2 SSH 主机名(文本文件)

amazon-web-services - 隐藏 Aws Lambda 函数内联代码

amazon-web-services - ALB 每 35 秒重复调用一次 AWS Lambda

azure - 在云中部署非基于http的服务