Skip to content

create_policy

create_policy(
    policy_name: PolicyName,
    policy_document: PolicyDocument,
    *,
    config_overrides: Optional[IoTClientConfig] = None,
    tags: Optional[TagList] = None,
) -> CreatePolicyResponse

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.

Parameters:

  • policy_name (PolicyName) –

    The policy name.

  • policy_document (PolicyDocument) –

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

  • tags (Optional[TagList], default: None ) –

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

Raises:

Source code in docs_src/capo_iot/_services/io_t.py
def create_policy(
    self,
    policy_name: "capo_iot.types.policy_name.PolicyName",
    policy_document: "capo_iot.types.policy_document.PolicyDocument",
    *,
    config_overrides: Optional[IoTClientConfig] = None,
    tags: Optional["capo_iot.types.tag_list.TagList"] = None,
) -> "capo_iot.types.create_policy_response.CreatePolicyResponse":
    """<p>Creates an IoT policy.</p> <p>The created policy is the default version for the policy. This operation creates a policy version with a version identifier of <b>1</b> and sets <b>1</b> as the policy's default version.</p> <p>Requires permission to access the <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions">CreatePolicy</a> action.</p>

    Args:
        policy_name: <p>The policy name.</p>
        policy_document: <p>The JSON document that describes the policy. <b>policyDocument</b> must have a minimum length of 1, with a maximum length of 2048, excluding whitespace.</p>
        tags: <p>Metadata which can be used to manage the policy.</p> <note> <p>For URI Request parameters use format: ...key1=value1&key2=value2...</p> <p>For the CLI command-line parameter use format: &&tags "key1=value1&key2=value2..."</p> <p>For the cli-input-json file use format: "tags": "key1=value1&key2=value2..."</p> </note>

    Raises:
        capo_iot.errors.internal_failure_exception.InternalFailureException: <p>An unexpected error has occurred.</p>
        capo_iot.errors.invalid_request_exception.InvalidRequestException: <p>The request is not valid.</p>
        capo_iot.errors.malformed_policy_exception.MalformedPolicyException: <p>The policy documentation is not valid.</p>
        capo_iot.errors.resource_already_exists_exception.ResourceAlreadyExistsException: <p>The resource already exists.</p>
        capo_iot.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is temporarily unavailable.</p>
        capo_iot.errors.throttling_exception.ThrottlingException: <p>The rate exceeds the limit.</p>
        capo_iot.errors.unauthorized_exception.UnauthorizedException: <p>You are not authorized to perform this operation.</p>
        capo_iot.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_iot.types.create_policy_request.CreatePolicyRequest]",
    ) -> OperationResponse[
        "capo_iot.types.create_policy_response.CreatePolicyResponse"
    ]:
        import capo_iot._operations.aws_iot_service.create_policy

        output, http_response = (
            capo_iot._operations.aws_iot_service.create_policy.create_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreatePolicy")
    )
    input_: capo_iot.types.create_policy_request.CreatePolicyRequest = {
        "policy_name": policy_name,
        "policy_document": policy_document,
    }
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output