Closed jahtoe closed 3 years ago
Greetings @skinny85, I was wondering if you could look at the following as well Regards jahtoe
Hey @jahtoe ,
thanks for opening the issue. Can you explain what are you trying to achieve here?
I'm interested to get the value of the mapping: 10.0.0.0/16
Then I would suggest using Fn.findInMap("CidrMappings", "vpc", "CIDR")
.
Thanks, Adam
Hi @skinny85 , I'm trying to dynamically retrieve the value 10.0.0.0/16 from the mappings by using the following code
stack.template.**getMapping**(MapName).**findInMap**(TopLevelKey, SecondLevelKey);
Ideally I would like to be able to do this dynamically for any mapping.
findInMap takes two not null string parameters
Regads Jahtoe
So, the way Mappings are represented in CloudFormation is the Fn::FindInMap
function. You can get it from either the CfnMapping
class instance, like this:
var cfnMapping = stack.template.getMapping("CidrMappings");
var cirdr = cfnMapping.findInMap("vpc", "CIDR");
or you can construct the function directly:
var cirdr = Fn.findInMap("CidrMappings", "vpc", "CIDR");
In any case, you can pass cirdr
as the value of a property of a different construct, and it will get resolved to what you need.
Hope this helps!
Thanks, Adam
Hi @skinny85,
Okay thanks for that response. I think the issue might be that I'm trying to access the value 10.0.0.0/16
In testing
LOG.debug("Fn.findInMap " + stack.resolve(Fn.findInMap(MapName, TopLevelKey, SecondLevelKey)).toString());
Fn.findInMap returns a token which outputs the following
Fn.findInMap {Fn::FindInMap=[CidrMappings, vpc, CIDR]}
I don't think then there is a way to access the value 10.0.0.0/16
Regards Jahtoe
Yes. That token that you see, at deployment time, will resolve to the value 10.0.0.0/16
. So using it will achieve what you want here.
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
:question: General Issue
How do I access mapping values
Given a template with a Mapping
The following code
Output the following logging
I'm interested to get the value of the mapping: 10.0.0.0/16
But instead the findInMap function returns {Fn::FindInMap=[CidrMappings, vpc, CIDR]}
I'm wondering if that is the expected behavior?
Environment
Other information
Full template