15

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
  • Which is the highlighted portion? Where have you declared your external environment variable? Commented Jul 22, 2018 at 1:35

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.