How to use FindInMap to set property of number type?
See original GitHub issueFn.findInMap returns a string token. However, how to use it set a property which is number type?
The following usage will throw Exception in thread "main" java.lang.NumberFormatException: For input string: "${Token[TOKEN.14]}"
Mapping writeCapacityMapping = new Mapping(parent, "TableWriteCapacityMapping", MappingProps.builder()
.withMapping(ImmutableMap.of(
Stage.beta.name(), ImmutableMap.of(
"min", 5,
"max", 100),
Stage.prod.name(), ImmutableMap.of(
"min", 400,
"max", 1200)))
.build());
...
String minCapacity = Fn.findInMap("TableWriteCapacityMapping", stageParameter.getValueAsString(), "min");
String maxCapacity = Fn.findInMap("TableWriteCapacityMapping", stageParameter.getValueAsString(), "max");
ScalableTargetProps props = ScalableTargetProps.builder()
.withMinCapacity(Integer.valueOf(minCapacity))
.withMaxCapacity(Integer.valueOf(maxCapacity))
.build();
And the expected cloudformation template will be:
Mappings:
WriteCapacityMap:
beta:
min: 5
max: 100
prod:
min: 400
max: 1200
TableWriteCapacityScalableTarget:
Type: "AWS::ApplicationAutoScaling::ScalableTarget"
Properties:
MinCapacity:
Fn::FindInMap: [WriteCapacityMap, { Ref: "Stage" }, min]
MaxCapacity:
Fn::FindInMap: [WriteCapacityMap, { Ref: "Stage" }, max]
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to use AWS CDK FindInMap to set property of number ...
ScalableTarget accepts parameter of Number type. void setMinCapacity(final java.lang.Number value);. AWS CloudFormation library: ...
Read more >Fn::FindInMap - AWS CloudFormation
The following example shows how to use Fn::FindInMap for a template with a Mappings ... resource whose ImageId property is set by the...
Read more >Fn::FindInMap in CloudFormation explained with an example
Welcome to part 3.5 of this tutorial series on AWS CloudFormation. In this tutorial, I have covered the intrinsic function ...
Read more >What is FindInMap in AWS CloudFormation? | by Tek Loon
Mappings allow you to define a set of mapping in the CloudFormation template and ! ... FindInMap in the ImageId property and we...
Read more >Can FindInMap return a list? - Server Fault
I've tried various combinations of the example below, but I always get the same error Value of property Subnets must be of type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Token.asNumber()
is the right way to force tokens to the right type.@eladb I’m re-opening this one, let me know if you disagree!