Coding Spirit

一位程序员,比较帅的那种

AWS Cloudformation allows user attach condition to resource, so resource will be created only if the given condition has been fulfilled(conditional resource). But things get tricky when using AWS CDK, user must use getNode method to get the Cfnxxxxx resource from original CDK resource and attach conditions afterwards. Take S3 Bucket as an example:

1
2
3
((CfnBucket)myBucket.getNode().getDefaultChild()).getCfnOptions().setCondition(
myCondition
);

We can construct a Map<String, Object> from a JSON string with the help of reflect:

1
2
3
4
5
6
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

var mapType = new TypeToken<Map<String, Object>>() {
}.getType();
Map<String, Object> myMap = new Gson().fromJson(jsonString, mapType);
0%