AWS Cloudformation:将环境变量作为参数传递给 lambda 函数

2024-02-29

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

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

{
  "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

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

然后使用这些参数Function宣言:

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

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

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

更多信息 -here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AWS Cloudformation:将环境变量作为参数传递给 lambda 函数 的相关文章

随机推荐