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, ... ]
}
}
You are right that there is no concept of environment variables for Lambda Layers.
All in all, CloudFormation makes deploying AWS Lambda functions incredibly simple. Start by creating the template file that will define your resources. This will be your working folder for your code. Next, create your function in the appropriate file for your desired Lambda runtime.
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
"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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With