Java CfnJson Example
CfnJson and Java example
Couldn't find the best way to use CfnJson with Java and I getting the following error
The Question
String provider = eksCluster.getClusterOpenIdConnectIssuer();
CfnJson provider_str = CfnJson.Builder.create(this, "CfnJson")
.value(provider+":aud")
.build();
Map<String, Object> level = new HashMap<String, Object>();
Map<String, Object> level2 = new HashMap<String, Object>();
level2.put(provider_str.toJSON(), "sts.amazonaws.com");
level.put("StringEquals",level2);
FederatedPrincipal federatedPrincipal = new FederatedPrincipal("arn:aws:iam::account:oidc-provider/"+provider,level,"sts:AssumeRoleWithWebIdentity");
And having the following error:
An exception occured while executing the Java class. Resolution error: Resolution error: Resolution error: "${Token[TOKEN.617]}" is used as the key in a map so must resolve to a string, but it resolves to: {"Fn::Join":["",["\"",{"Fn::GetAtt":["EKScluster","OpenIdConnectIssuer"]},":aud\""]]}. Consider using "CfnJson" to delay resolution to deployment-time.
Environment
- CDK CLI Version: 1.115.0 (build f0ca40f)
- OS: n/a
- Language (Version): Java (8)
Other information
I have been looking also https://github.com/aws/aws-cdk/issues/5352 but not idea how it will work with Java
Fixed with this piece of code:
Map<String, Object> level = new HashMap<String, Object>();
Map<String, String> level2 = new HashMap<String, String>();
level2.put(oidcProviderEndpoint+":aud", "sts.amazonaws.com");
CfnJson oidc_issuer_condition_str = CfnJson.Builder.create(this, "CfnJson")
.value(level2)
.build();
level.put("StringEquals",oidc_issuer_condition_str);
ServicePrincipal eksFargatePodPrincipal = ServicePrincipal.Builder.create("eks-fargate-pods.amazonaws.com").build();
FederatedPrincipal federatedPrincipal = new FederatedPrincipal("arn:aws:iam:123456789:oidc-provider/"+oidcProviderEndpoint,level,"sts:AssumeRoleWithWebIdentity");
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.