Getting this exception cryptic error:
Caused by: software.amazon.jsii.JsiiException: Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
at Function.fromJson (/tmp/jsii-kernel-nmlfpf/node_modules/@aws-cdk/aws-iam/lib/policy-document.js:27:58)
at /tmp/jsii-java-runtime9121798313176500348/jsii-runtime.js:7685:51
git clone [email protected]:vbudilov/aws-cdk-starter.git
Uncomment this line and run
mvn package && cdk synth && cdk deploy '*'
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project cdk: An exception occured while executing the Java class. Cannot read property 'map' of undefined
[ERROR] TypeError: Cannot read property 'map' of undefined
[ERROR] at Function.fromJson (/tmp/jsii-kernel-x3Tnwv/node_modules/@aws-cdk/aws-iam/lib/policy-document.js:27:58)
[ERROR] at /tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7687:51
[ERROR] at Kernel._wrapSandboxCode (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:8301:19)
[ERROR] at /tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7687:25
[ERROR] at Kernel._ensureSync (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:8274:20)
[ERROR] at Kernel.sinvoke (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7686:26)
[ERROR] at KernelHost.processRequest (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7372:28)
[ERROR] at KernelHost.run (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7312:14)
[ERROR] at Immediate._onImmediate (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7315:37)
[ERROR] at processImmediate (internal/timers.js:456:21)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project cdk: An exception occured while executing the Java class. Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
at Function.fromJson (/tmp/jsii-kernel-x3Tnwv/node_modules/@aws-cdk/aws-iam/lib/policy-document.js:27:58)
at /tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7687:51
at Kernel._wrapSandboxCode (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:8301:19)
at /tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7687:25
at Kernel._ensureSync (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:8274:20)
at Kernel.sinvoke (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7686:26)
at KernelHost.processRequest (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7372:28)
at KernelHost.run (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7312:14)
at Immediate._onImmediate (/tmp/jsii-java-runtime10417679301776872566/jsii-runtime.js:7315:37)
at processImmediate (internal/timers.js:456:21)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. Cannot read property 'map' of undefined
This is :bug: Bug Report
So I commented out this part and everything was deployed:
// .accessPolicies(PolicyDocument.fromJson(Properties.readResourceFileContents("elasticsearch-access-policy.json",
// Map.of("ACCOUNT_NAME_REPLACE_ME", Properties.ACCOUNT,
// "ROLE_NAME_REPLACE_ME", Properties.ES_ALLOWED_ROLE_NAME,
// "REGION_REPLACE_ME", Properties.REGION,
// "ES_DOMAIN_NAME_REPLACE_ME", Properties.ES_NAME,
// "EXTERNAL_IP_ADDRESS_REPLACE_ME", getMyExternalIP() // For testing purposes
// ))))
BTW my readResourceFileContents() does produce a valid JSON file....here's an example it prints out:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::540403165297:role/LiveStreamingRoleToElasticSearch"
},
"Action": "es:*",
"Resource": "arn:aws:es:us-east-1:540403165297:domain/LSES/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "es:*",
"Resource": "arn:aws:es:us-east-1:540403165297:domain/LSES/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "108.52.199.76"
}
}
}
]
}
This error is caused by passing String (output of Properties.readResourceFileContents) into PolicyDocument.fromJson -- which expects a map-like object (Jackson ObjectNode, Map<String, ?>, IResolvable, ...).
Using new ObjectMapper().readTree(Properties.readResourceFileContents(/*...*/)) gets the synthesis to pass.
Most helpful comment
This error is caused by passing
String(output ofProperties.readResourceFileContents) intoPolicyDocument.fromJson-- which expects a map-like object (JacksonObjectNode,Map<String, ?>,IResolvable, ...).Using
new ObjectMapper().readTree(Properties.readResourceFileContents(/*...*/))gets the synthesis to pass.