Skip to content

create_workspace_enforced_policy

create_workspace_enforced_policy(
    name: EnforcedPolicyName,
    policy_body: EnforcedPolicyBody,
    *,
    config_overrides: Optional[WorkSpacesClientConfig] = None,
    client_token: Optional[IdempotencyToken] = None,
    tags: Optional[TagList] = None,
) -> CreateWorkspaceEnforcedPolicyResult

Creates a WorkSpace-enforced policy, which the WorkSpace applies. The name must be unique among the WorkSpace-enforced policies in your account. If it isn't, the operation returns ConflictException, and its ResourceId identifies the existing policy. If your account would exceed its maximum number of WorkSpace-enforced policies, the operation returns ServiceQuotaExceededException.

Parameters:

  • client_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request with the same parameters, the service returns the result of that request and doesn't create another WorkSpace-enforced policy.

    If you reuse the token with different parameters, the operation returns ValidationException. If you deleted the policy created with this token, the operation returns ConflictException.

  • name (EnforcedPolicyName) –

    The name of the WorkSpace-enforced policy.

  • policy_body (EnforcedPolicyBody) –

    Specifies the policy document, in JSON format, that defines the enforced policy. It can be up to 65,536 characters long and can't contain control characters other than tab, line feed, and carriage return.

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

    The tags to add to the WorkSpace-enforced policy. Each tag key can appear only once.

Raises:

  • AccessDeniedException –

    The user is not authorized to access a resource.

  • ConflictException –

    The request conflicts with the current state of a resource, for example because a name is already in use or the resource is still in use. Resolve the conflict, and then retry your request.

  • ServiceQuotaExceededException –

    The request would exceed a service quota. Request a quota increase or reduce the number of resources in your request.

  • ThrottlingException –

    The request was throttled. Retry the request with exponential backoff.

  • ValidationException –

    Your request failed validation. Check the error message for the parameter that isn't valid.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Example – Creating a WorkSpace-enforced policy The following example creates a WorkSpace-enforced policy that keeps internet access on.

>>> client.create_workspace_enforced_policy(client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', name='default-network', policy_body='{"disableInternetAccess":false,"deniedPaths":[]}')
Source code in docs_src/capo_workspaces/_services/work_spaces.py
def create_workspace_enforced_policy(
    self,
    name: "capo_workspaces.types.enforced_policy_name.EnforcedPolicyName",
    policy_body: "capo_workspaces.types.enforced_policy_body.EnforcedPolicyBody",
    *,
    config_overrides: Optional[WorkSpacesClientConfig] = None,
    client_token: Optional[
        "capo_workspaces.types.idempotency_token.IdempotencyToken"
    ] = None,
    tags: Optional["capo_workspaces.types.tag_list.TagList"] = None,
) -> "capo_workspaces.types.create_workspace_enforced_policy_result.CreateWorkspaceEnforcedPolicyResult":
    """<p>Creates a WorkSpace-enforced policy, which the WorkSpace applies. The name must be unique among the WorkSpace-enforced policies in your account. If it isn't, the operation returns <code>ConflictException</code>, and its <code>ResourceId</code> identifies the existing policy. If your account would exceed its maximum number of WorkSpace-enforced policies, the operation returns <code>ServiceQuotaExceededException</code>.</p>

    Args:
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request with the same parameters, the service returns the result of that request and doesn't create another WorkSpace-enforced policy.</p> <p>If you reuse the token with different parameters, the operation returns <code>ValidationException</code>. If you deleted the policy created with this token, the operation returns <code>ConflictException</code>.</p>
        name: <p>The name of the WorkSpace-enforced policy.</p>
        policy_body: <p>Specifies the policy document, in JSON format, that defines the enforced policy. It can be up to 65,536 characters long and can't contain control characters other than tab, line feed, and carriage return.</p>
        tags: <p>The tags to add to the WorkSpace-enforced policy. Each tag key can appear only once.</p>

    Raises:
        capo_workspaces.errors.access_denied_exception.AccessDeniedException: <p>The user is not authorized to access a resource.</p>
        capo_workspaces.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of a resource, for example because a name is already in use or the resource is still in use. Resolve the conflict, and then retry your request.</p>
        capo_workspaces.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota. Request a quota increase or reduce the number of resources in your request.</p>
        capo_workspaces.errors.throttling_exception.ThrottlingException: <p>The request was throttled. Retry the request with exponential backoff.</p>
        capo_workspaces.errors.validation_exception.ValidationException: <p>Your request failed validation. Check the error message for the parameter that isn't valid.</p>
        capo_workspaces.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Example – Creating a WorkSpace-enforced policy
        The following example creates a WorkSpace-enforced policy that keeps internet access on.

        >>> client.create_workspace_enforced_policy(client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', name='default-network', policy_body='{"disableInternetAccess":false,"deniedPaths":[]}')
    """

    def _handler(
        req: "OperationRequest[capo_workspaces.types.create_workspace_enforced_policy_request.CreateWorkspaceEnforcedPolicyRequest]",
    ) -> OperationResponse[
        "capo_workspaces.types.create_workspace_enforced_policy_result.CreateWorkspaceEnforcedPolicyResult"
    ]:
        if req.options.protocol == "awsJson1_1":
            import capo_workspaces._operations.workspaces_service.aws_json1_1.create_workspace_enforced_policy

            output, http_response = (
                capo_workspaces._operations.workspaces_service.aws_json1_1.create_workspace_enforced_policy.create_workspace_enforced_policy(
                    req.options, req.input
                )
            )
        elif req.options.protocol == "rpcv2Cbor":
            import capo_workspaces._operations.workspaces_service.rpcv2_cbor.create_workspace_enforced_policy

            output, http_response = (
                capo_workspaces._operations.workspaces_service.rpcv2_cbor.create_workspace_enforced_policy.create_workspace_enforced_policy(
                    req.options, req.input
                )
            )
        else:
            raise ValueError(f"unknown protocol {req.options.protocol!r}")
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_workspaces.types.create_workspace_enforced_policy_request.CreateWorkspaceEnforcedPolicyRequest",
    ) -> dict[str, Any]:
        import capo_workspaces.types.create_workspace_enforced_policy_request

        return capo_workspaces.types.create_workspace_enforced_policy_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateWorkspaceEnforcedPolicy", redact_input=_redact_input
        ),
    )
    input_: capo_workspaces.types.create_workspace_enforced_policy_request.CreateWorkspaceEnforcedPolicyRequest = {
        "name": name,
        "policy_body": policy_body,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    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