Menu
AWS IoT
Developer Guide

CreatePolicy

Creates an AWS 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.

Request syntax:

POST /policies/policyName Content-type: application/json { "policyDocument": "string" }

URI Request Parameters:

Name

Type

Req?

Description

policyName

PolicyName

yes

The policy name.

Request Body Parameters:

Name

Type

Req?

Description

policyDocument

PolicyDocument

yes

The JSON document that describes the policy. policyDocument must have a minimum length of 1, with a maximum length of 2048, excluding whitespace.

Response syntax:

Content-type: application/json { "policyName": "string", "policyArn": "string", "policyDocument": "string", "policyVersionId": "string" }

Response Body Parameters:

Name

Type

Req?

Description

policyName

PolicyName

no

The policy name.

policyArn

PolicyArn

no

The policy ARN.

policyDocument

PolicyDocument

no

The JSON document that describes the policy.

policyVersionId

PolicyVersionId

no

The policy version ID.

Errors:

ResourceAlreadyExistsException

The resource already exists.

HTTP response code: 409

MalformedPolicyException

The policy documentation is not valid.

HTTP response code: 400

InvalidRequestException

The contents of the request were invalid. For example, this code is returned when an UpdateJobExecution request contains invalid status details. The message contains details about the error.

HTTP response code: 400

ThrottlingException

The rate exceeds the limit.

HTTP response code: 429

UnauthorizedException

You are not authorized to perform this operation.

HTTP response code: 401

ServiceUnavailableException

The service is temporarily unavailable.

HTTP response code: 503

InternalFailureException

An unexpected error has occurred.

HTTP response code: 500

CLI

Synopsis:

aws iot create-policy \ --policy-name <value> \ --policy-document <value> \ [--cli-input-json <value>] \ [--generate-cli-skeleton]

cli-input-json format:

{ "policyName": "string", "policyDocument": "string" }

cli-input-json fields:

Name

Type

Description

policyName

string

length max:128 min:1

pattern: [w+=,.@-]+

The policy name.

policyDocument

string

The JSON document that describes the policy. policyDocument must have a minimum length of 1, with a maximum length of 2048, excluding whitespace.

Output:

{ "policyName": "string", "policyArn": "string", "policyDocument": "string", "policyVersionId": "string" }

cli output fields:

Name

Type

Description

policyName

string

length max:128 min:1

pattern: [w+=,.@-]+

The policy name.

policyArn

string

The policy ARN.

policyDocument

string

The JSON document that describes the policy.

policyVersionId

string

pattern: [0-9]+

The policy version ID.

On this page: