AttachPolicyCommand

Attaches the specified policy to the specified principal (certificate or other credential).

Requires permission to access the AttachPolicy  action.

Example Syntax

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

import { IoTClient, AttachPolicyCommand } from "@aws-sdk/client-iot"; // ES Modules import
// const { IoTClient, AttachPolicyCommand } = require("@aws-sdk/client-iot"); // CommonJS import
const client = new IoTClient(config);
const input = { // AttachPolicyRequest
  policyName: "STRING_VALUE", // required
  target: "STRING_VALUE", // required
};
const command = new AttachPolicyCommand(input);
const response = await client.send(command);
// {};

AttachPolicyCommand Input

See AttachPolicyCommandInput for more details

Parameter
Type
Description
policyName
Required
string | undefined

The name of the policy to attach.

target
Required
string | undefined

The identity  to which the policy is attached. For example, a thing group or a certificate.

AttachPolicyCommand 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.

LimitExceededException
client

A limit has been exceeded.

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.