问题
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 .
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, ... ]
}
}
回答1:
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."
}
}
And then use these parameters in Function
declaration:
"Environment":{
"Variables":{
"SomeVariable":{
"Ref":"MyVariable"
}
}
}
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
More information - here
回答2:
"I want to pass the key value pair object as parameter"
You cannot pass key-value pairs as parameters in AWS CF templates. For the accepted parameter types please see this
来源:https://stackoverflow.com/questions/51439163/aws-cloudformation-passing-environmental-variables-as-parameters-to-lambda-fun