- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
CreatePolicyCommand
Creates an IoT policy.
The created policy is the default version for the policy. This operation creates a policy version with a version identifier of 1 and sets 1 as the policy's default version.
Requires permission to access the CreatePolicy action.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { IoTClient, CreatePolicyCommand } from "@aws-sdk/client-iot"; // ES Modules import
// const { IoTClient, CreatePolicyCommand } = require("@aws-sdk/client-iot"); // CommonJS import
const client = new IoTClient(config);
const input = { // CreatePolicyRequest
policyName: "STRING_VALUE", // required
policyDocument: "STRING_VALUE", // required
tags: [ // TagList
{ // Tag
Key: "STRING_VALUE", // required
Value: "STRING_VALUE",
},
],
};
const command = new CreatePolicyCommand(input);
const response = await client.send(command);
// { // CreatePolicyResponse
// policyName: "STRING_VALUE",
// policyArn: "STRING_VALUE",
// policyDocument: "STRING_VALUE",
// policyVersionId: "STRING_VALUE",
// };
CreatePolicyCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
policyDocument Required | string | undefined | The JSON document that describes the policy. policyDocument must have a minimum length of 1, with a maximum length of 2048, excluding whitespace. |
policyName Required | string | undefined | The policy name. |
tags | Tag[] | undefined | Metadata which can be used to manage the policy. For URI Request parameters use format: ...key1=value1&key2=value2... For the CLI command-line parameter use format: &&tags "key1=value1&key2=value2..." For the cli-input-json file use format: "tags": "key1=value1&key2=value2..." |
CreatePolicyCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
policyArn | string | undefined | The policy ARN. |
policyDocument | string | undefined | The JSON document that describes the policy. |
policyName | string | undefined | The policy name. |
policyVersionId | string | undefined | The policy version ID. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
InternalFailureException | server | An unexpected error has occurred. |
InvalidRequestException | client | The request is not valid. |
MalformedPolicyException | client | The policy documentation is not valid. |
ResourceAlreadyExistsException | client | The resource already exists. |
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. |