AttachThingPrincipalCommand

Attaches the specified principal to the specified thing. A principal can be X.509 certificates, Amazon Cognito identities or federated identities.

Requires permission to access the AttachThingPrincipal  action.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { IoTClient, AttachThingPrincipalCommand } from "@aws-sdk/client-iot"; // ES Modules import
// const { IoTClient, AttachThingPrincipalCommand } = require("@aws-sdk/client-iot"); // CommonJS import
const client = new IoTClient(config);
const input = { // AttachThingPrincipalRequest
  thingName: "STRING_VALUE", // required
  principal: "STRING_VALUE", // required
  thingPrincipalType: "EXCLUSIVE_THING" || "NON_EXCLUSIVE_THING",
};
const command = new AttachThingPrincipalCommand(input);
const response = await client.send(command);
// {};

AttachThingPrincipalCommand Input

Parameter
Type
Description
principal
Required
string | undefined

The principal, which can be a certificate ARN (as returned from the CreateCertificate operation) or an Amazon Cognito ID.

thingName
Required
string | undefined

The name of the thing.

thingPrincipalType
ThingPrincipalType | undefined

The type of the relation you want to specify when you attach a principal to a thing.

  • EXCLUSIVE_THING - Attaches the specified principal to the specified thing, exclusively. The thing will be the only thing that’s attached to the principal.

  • NON_EXCLUSIVE_THING - Attaches the specified principal to the specified thing. Multiple things can be attached to the principal.

AttachThingPrincipalCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.

Throws

Name
Fault
Details
InternalFailureException
server

An unexpected error has occurred.

InvalidRequestException
client

The request is not valid.

ResourceNotFoundException
client

The specified resource does not exist.

ServiceUnavailableException
server

The service is temporarily unavailable.

ThrottlingException
client

The rate exceeds the limit.

UnauthorizedException
client

You are not authorized to perform this operation.

IoTServiceException
Base exception class for all service exceptions from IoT service.