투케이2K

149. (Aws/Amazon) [Aws Iot Core] Aws Iot Core Thing 사물에 생성된 인증서 목록 정보 확인 ListThingPrincipals API 설명 본문

Aws (Amazon)

149. (Aws/Amazon) [Aws Iot Core] Aws Iot Core Thing 사물에 생성된 인증서 목록 정보 확인 ListThingPrincipals API 설명

투케이2K 2025. 12. 8. 21:10
728x90

[개발 환경 설정]

개발 환경 : Aws / Amazon Web Services

 

[설명 정리]

// --------------------------------------------------------------------------------------
[개발 및 환경]
// --------------------------------------------------------------------------------------

- 인프라 : Aws / Amazon Web Services


- 기술 구분 : Aws / Aws Iot Core


- 사전) Aws Iot Core 간단 설명 : 

  >> AWS IoT 는 IoT 디바이스를 다른 디바이스 및 AWS 클라우드 서비스에 연결하는 클라우드 서비스를 제공합니다.

  >> 디바이스가에 연결할 수 있는 경우 AWS IoT는 AWS 가 제공하는 클라우드 서비스에 디바이스를 AWS IoT 연결할 수 있습니다.

  >> AWS IoT Core 메시지 브로커는 MQTT 및 MQTT over WSS 프로토콜을 사용하여 메시지를 게시하고 구독하는 디바이스 및 클라이언트를 지원합니다. 
  
    - HTTPS 프로토콜을 사용하여 메시지를 게시하는 디바이스와 클라이언트도 지원합니다.

// --------------------------------------------------------------------------------------






// --------------------------------------------------------------------------------------
[설 명]
// --------------------------------------------------------------------------------------

1. AWS IoT ListThingPrincipals 는 지정된 “thing” (사물) 에 연결된 principals — 즉 인증이나 권한을 나타내는 주체 (principal) 목록을 조회하는 API 입니다

  >> AWS 사이트 : https://docs.aws.amazon.com/iot/latest/apireference/API_ListThingPrincipals.html


2. AWS IoT ListThingPrincipals API 요청 형식 및 주요 매개변수

  >> GET /things/thingName/principals?maxResults=maxResults&nextToken=nextToken HTTP/1.1

  >> thingName : 조회하려는 thing 의 이름 (문자열, 길이 1~128, 패턴 [a-zA-Z0-9:_-]+)

  >> maxResults : 한 번에 반환할 최대 결과 갯수 (1 ~ 250) 

  >> nextToken : 페이지네이션을 위해, 이전 호출의 응답에서 받은 토큰 값 (없으면 처음 페이지)


3. AWS IoT ListThingPrincipals 응답 본문 예시 구문 

  HTTP/1.1 200
  Content-type: application/json

  {
    "nextToken": "string",
    "principals": [ "string" ]
  }

  >> principals : 주체들(principal)의 리스트. 일반적으로 ARN(예: 인증서 ARN) 형식의 문자열 배열

  >> nextToken : 결과가 많을 경우 다음 페이지를 가져오기 위한 토큰. 더 이상 없으면 null

  >> 주요 Exception 에러 코드 

    - ResourceNotFoundException : 지정된 thing 이 존재하지 않을 때 

    - ThrottlingException : 호출 빈도 제한 초과 시


4. AWS IoT ListThingPrincipals 이 사용되는 시점

  >> ListThingPrincipals API 를 이용하면 “어떤 인증서 또는 IAM 주체가 이 사물에 연결돼 있는가”를 확인할 수 있습니다


5. AWS IoT ListThingPrincipals 사용 예시 코드 (자바스크립트)

<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1416.0.min.js"></script>


const region = 'ap-northeast-2'; // [AWS 리전]
const accessKeyId = 'AK..A6'; // [IAM 액세스 키]
const secretAccessKey = 'mP..5J'; // [IAM 시크릿 키]


// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
// IAM 계정 정보를 사용해 AWS.config 정보 업데이트 수행
// -----------------------------------------            
AWS.config.update({
  region: region,
  accessKeyId: accessKeyId,
  secretAccessKey: secretAccessKey
});


// -----------------------------------------
// [AWS.Iot 객체 생성]
// -----------------------------------------
const iot = new AWS.Iot();


// -----------------------------------------
// [요청 파라미터 생성]
// -----------------------------------------
const params = {
    thingName: "T_TWK_0000000001" // Thing에 연결된 Principal(인증서 등) 조회
};


// -----------------------------------------
// [listThingPrincipals] : Aws Iot Core 에 생성 된 특정 IoT Thing 에 매핑된 정책(Policy) 정보를 확인
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/ko_kr/iot/latest/apireference/API_ListPrincipalPolicies.html
// -----------------------------------------
iot.listThingPrincipals( params , function(err, data) { 
  if (err) {
    console.error("[listThingPrincipals] : [Error] : ", err);

  } else {
    console.log("[listThingPrincipals] : [Success] : ", JSON.stringify(data));
    
  }
});

// --------------------------------------------------------------------------------------






// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------

[AWS 사이트 : ListThingPrincipals]

https://docs.aws.amazon.com/iot/latest/apireference/API_ListThingPrincipals.html


[자바스크립트 AWS Iot Core 특정 IoT Thing 에 매핑된 정책 (Policy) 정보 확인 - ListPrincipalPolicies]

https://kkh0977.tistory.com/8371

https://blog.naver.com/kkh0977/224061787533


[자바스크립트 AWS Iot Core 에 생성 된 Thing Info 사물 정보 조회 - DescribeThing]

https://blog.naver.com/kkh0977/224068807852


[자바스크립트 AWS Iot Core 특정 IoT Thing 에 생성 된 특정 정책 (Policy) 의 정보 조회 - getPolicy]

https://blog.naver.com/kkh0977/224061809820

// --------------------------------------------------------------------------------------
 
728x90
반응형
Comments