Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[neptune] AssociatedRoles for CfnDBCluster #10224

Closed
2 tasks
namedgraph opened this issue Sep 7, 2020 · 15 comments
Closed
2 tasks

[neptune] AssociatedRoles for CfnDBCluster #10224

namedgraph opened this issue Sep 7, 2020 · 15 comments
Assignees
Labels
@aws-cdk/aws-neptune Related Amazon Neptune guidance Question that needs advice or information.

Comments

@namedgraph
Copy link

namedgraph commented Sep 7, 2020

AssociatedRoles is now supported by CF templates for Amazon Neptune, but not available in the CDK (as of v1.62.0).

Use Case

Associating an IAM role with a Neptune's CfnDBCluster.

Proposed Solution

Should be possible as AssociatedRoles is available for other types of DBCluster.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@namedgraph namedgraph added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 7, 2020
@SomayaB SomayaB changed the title [software.amazon.awscdk/neptune] AssociatedRoles for CfnDBCluster [neptune] AssociatedRoles for CfnDBCluster Sep 8, 2020
@github-actions github-actions bot added the @aws-cdk/aws-neptune Related Amazon Neptune label Sep 8, 2020
@njlynch
Copy link
Contributor

njlynch commented Sep 10, 2020

This is being done as part of #10201. Closing this out as a duplicate.

@njlynch njlynch closed this as completed Sep 10, 2020
@namedgraph
Copy link
Author

@njlynch so when is this going to be released?

I see CfnDBCluster::setAssociatedRoles in the documentation, but the method is not available in the latest CDK version 1.63.0.

@njlynch
Copy link
Contributor

njlynch commented Sep 28, 2020

@namedgraph - This was released in 1.64.0 (released 2020-09-22).

@namedgraph
Copy link
Author

Thanks!

@namedgraph
Copy link
Author

namedgraph commented Sep 28, 2020

@njlynch I'm getting circular reference error when attempting to assign an associated role to a Neptune cluster:

Caused by: software.amazon.jsii.JsiiException: Resolution error: Resolution error: Unable to resolve object tree with circular reference. Path:
/Resources/${Token[CdkTestStack.NeptuneCluster.LogicalID.157]}/Properties/associatedRoles/0/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host..

What could be the problem?

Role code:

Role bulkLoaderRole = new Role(this, "RDFBulkLoaderRole", RoleProps.builder().
        assumedBy(new ServicePrincipal("rds.amazonaws.com")).
        build());
bulkLoaderRole.addToPolicy(PolicyStatement.Builder.create().
        effect(Effect.ALLOW).
        actions(Arrays.asList("s3:Get*", "s3:List*")).
        resources(Arrays.asList("*")).
        build());

Cluster code:

return CfnDBCluster.Builder.create(this, "NeptuneCluster").
        dbSubnetGroupName(subnetGroup.getDbSubnetGroupName()).
        vpcSecurityGroupIds(securityGroups).
        associatedRoles(Arrays.asList(bulkLoaderRole)).
        dbClusterIdentifier("OctopusTriplestoreCluster").
        iamAuthEnabled(Boolean.TRUE).
        deletionProtection(Boolean.TRUE).
        engineVersion("1.0.2.2").
        availabilityZones(getAvailabilityZones()).
        port(8182).
        deletionProtection(false).
        //enableCloudwatchLogsExports(securityGroups).
        build();

@njlynch
Copy link
Contributor

njlynch commented Sep 28, 2020

Caused by: software.amazon.jsii.JsiiException: Resolution error: Resolution error: Unable to resolve object tree with circular reference. Path:
/Resources/${Token[CdkTestStack.NeptuneCluster.LogicalID.157]}/Properties/associatedRoles/0/node/host/node/host/node/host/node/host/...

That repeating '/node/host/node/host' is certainly suspect. I'm not seeing anything from your code above. I suspect the issue lies somewhere in the translation from bulkLoaderRole to associatedRole in the cluster code. Do you have any constructs/nodes named 'host' there, and/or referencing the 'host' property of another construct?

@namedgraph
Copy link
Author

namedgraph commented Sep 28, 2020

The only related code that I can see is the following -- which I commented out, but still get the same error:

//        String neptuneHost = Token.asString("https://" + neptune.getAttrEndpoint() + ":" + neptune.getAttrPort());

        Function bulkLoader = bulkLoader(vpc, neptuneSg);
//        bulkLoader.addEnvironment("ENDPOINT_URI", neptuneHost).
//                addEnvironment("FORMAT", "ntriples").
//                addEnvironment("IAM_ROLE_ARN", bulkLoaderRole.getRoleArn()).
//                addEnvironment("REGION", getRegion());

@namedgraph
Copy link
Author

I can try to make a minimal case if that helps. So far the only way to get rid of the error is to remove the associatedRoles() call from the cluster.

@njlynch
Copy link
Contributor

njlynch commented Sep 28, 2020

Sure, a minimal case would be useful.

@njlynch njlynch reopened this Sep 28, 2020
@njlynch njlynch added guidance Question that needs advice or information. and removed feature-request A feature should be added or improved. labels Sep 28, 2020
@namedgraph
Copy link
Author

namedgraph commented Sep 28, 2020

@njlynch here you go: https://github.com/namedgraph/neptune-cdk-test/blob/master/src/main/java/com/myorg/NeptuneCdkTestStack.java

I hope it's enough to demonstrate the problem (running cdk synth leads to the Resolution error: Unable to resolve object tree with circular reference.). Very possibly something's wrong in my code, but I just cannot spot it.

@namedgraph
Copy link
Author

@njlynch can you confirm?

@SomayaB SomayaB added needs-reproduction This issue needs reproduction. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2020
@njlynch
Copy link
Contributor

njlynch commented Sep 30, 2020

Ah, I see it now.

tl;dr - Here's the fix to your code:

CfnDBCluster.DBClusterRoleProperty clusterRole = new CfnDBCluster.DBClusterRoleProperty.Builder().
    roleArn(associatedRole.getRoleArn()).
    build();

return CfnDBCluster.Builder.create(this, "NeptuneCluster").
    // ...
    associatedRoles(Arrays.asList(clusterRole)).
    // ...
    .build();

The associated roles isn't just an IAM Role, it's a specific type expected by CloudFormation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-neptune-dbcluster.html#cfn-neptune-dbcluster-associatedroles

The Java docs are not helpful here, showing the type of associatedRoles as java.util.List<? extends java.lang.Object>.
https://docs.aws.amazon.com/cdk/api/latest/java/software/amazon/awscdk/services/neptune/CfnDBCluster.Builder.html#associatedRoles-java.util.List- . What it should be is java.util.List<CfnDBCluster.DBClusterRoleProperty>.
https://docs.aws.amazon.com/cdk/api/latest/java/software/amazon/awscdk/services/neptune/CfnDBCluster.DBClusterRoleProperty.html

If you look at the Typescript or Python docs, you'll see slightly more helpful types:

  • Typescript - Type: IResolvable | DBClusterRoleProperty | IResolvable[]
  • Python - Union[IResolvable, List[Union[DBClusterRoleProperty, IResolvable]], None]

I am really intrigued by the bad error message you got, and by the poor Java docs in this example. I'll follow up on our jsii project -- responsible for both -- and see if we can't make some improvements.

Either way, hopefully this gets you up and running now.

@njlynch njlynch added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-reproduction This issue needs reproduction. labels Sep 30, 2020
@RomainMuller
Copy link
Contributor

This is type-union-induced, hence this RFC is relevant: aws/aws-cdk-rfcs#193

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 1, 2020
@njlynch
Copy link
Contributor

njlynch commented Oct 5, 2020

I'm closing this out, as it seems to be resolved; feel free to comment/re-open if you have any other follow-ups. The fixes to the messaging and docs are being tracked as part of the above RFC.

@njlynch njlynch closed this as completed Oct 5, 2020
@github-actions
Copy link

github-actions bot commented Oct 5, 2020

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-neptune Related Amazon Neptune guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants