You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS Cloud Directory JDK创建对象时遇节点类型判定错误求助

AWS Cloud Directory创建对象报错:Unable to determine if node is one of LeafNode, Node, Policy, Index

错误信息

Unable to determine if node is one of LeafNode, Node, Policy, Index
(Service: CloudDirectory, Status Code: 400, Request ID:
3448687c-d30f-434e-a4e6-76fbb057f5f1)

代码片段

TestAWSCloudDirectory.java

package com.pontusvision.graphutils;

import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.services.clouddirectory.CloudDirectoryClient;
import software.amazon.awssdk.services.clouddirectory.model.*;
import java.util.ArrayList;
import java.util.Collection;

public class TestAWSCloudDirectory {

  public static void main(String[] args) throws Exception {
    DefaultCredentialsProvider credentials = null;
    try {
      credentials =  DefaultCredentialsProvider.create(); // where is the file ?!
    } catch (Exception e) {
      throw new Exception(
        "Cannot load the credentials from the credential profiles file. " +
          "Please make sure that your credentials file is at the correct " +
          "location, and is in valid format.",
        e);
    }

    CloudDirectoryClient client = CloudDirectoryClient.builder()
      .credentialsProvider(credentials).build();

    AttributeKey attributeKey = AttributeKey.builder().schemaArn("***********************************************************")
      .facetName("DynamicObjectFacet")
      .name("Person_Natural").build();

    TypedAttributeValue attributeValue = TypedAttributeValue.fromStringValue("Leo");
    AttributeKeyAndValue attrib = AttributeKeyAndValue.builder().key(attributeKey).value(attributeValue).build();

    SchemaFacet schemaFacet = SchemaFacet.builder().facetName("DynamicObjectFacet").schemaArn("***********************************************************").build();

    Collection<AttributeKeyAndValue> objectAttributeList = new ArrayList<>();
    objectAttributeList.add(attrib);
    ObjectReference objectReference = ObjectReference.builder().selector("/").build();


    client.createObject(CreateObjectRequest.builder().directoryArn("***********************************************************")
      .objectAttributeList(objectAttributeList)
      .schemaFacets(schemaFacet)
      .build());

    client.close();

  }
}

pom.xml依赖

(...)
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>clouddirectory</artifactId>
      <version>2.20.26</version>
    </dependency>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>auth</artifactId>
      <version>2.20.26</version>
    </dependency>
(...)

解决建议

  • 自定义Facet必须继承Cloud Directory提供的基础节点类型之一:LeafNode、Node、Policy或Index。你的DynamicObjectFacet未继承这些类型,导致服务无法识别对象的节点类别,触发400错误。
  • 修改Schema中DynamicObjectFacet的定义,添加对基础节点类型的继承。例如,如果创建的是普通层级节点,继承Node;如果是无子节点的叶子对象,继承LeafNode。
  • 确认Schema已经正确发布并关联到目标Directory,代码中使用的Schema ARN准确无误。
  • 若Schema已完成基础类型继承,代码中仅需指定自定义Facet即可;若未在Schema中配置继承,也可在创建对象时的schemaFacets中同时包含基础类型Facet和自定义Facet(不推荐,建议在Schema层面完成继承)。

内容的提问来源于stack exchange,提问作者omarghoche

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 16:42:45