Associates an agent-enforced policy with the specified WorkSpace, replacing its current agent-enforced policy. If the WorkSpace can't apply the policy, the policy stays associated and the operation returns PolicyApplyFailedException. If the WorkSpace is in a state that doesn't allow the change, the policy is being deleted, or another request changed the WorkSpace's agent-enforced policy at the same time, the operation returns ConflictException.
Parameters:
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.
-
PolicyApplyFailedException
–
The service associated the enforced policy, but it couldn't apply it: the WorkSpace or its agent rejected it, or the service couldn't deliver it to the WorkSpace. Don't retry. Fix the policy and associate it again. To see why, call GetAgenticWorkspaceConfiguration.
-
ResourceNotFoundException
–
The resource could not be found.
-
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 – Applying an agent-enforced policy to a WorkSpace
The following example applies an agent-enforced policy to a WorkSpace.
>>> client.associate_agent_enforced_policy(workspace_id='ws-dk1example1', policy_id='wsae-a1b2c3d4')
Source code in docs_src/capo_workspaces/_services/work_spaces.py
| def associate_agent_enforced_policy(
self,
workspace_id: "capo_workspaces.types.workspace_id.WorkspaceId",
policy_id: "capo_workspaces.types.agent_enforced_policy_id.AgentEnforcedPolicyId",
*,
config_overrides: Optional[WorkSpacesClientConfig] = None,
) -> "capo_workspaces.types.associate_agent_enforced_policy_result.AssociateAgentEnforcedPolicyResult":
"""<p>Associates an agent-enforced policy with the specified WorkSpace, replacing its current agent-enforced policy. If the WorkSpace can't apply the policy, the policy stays associated and the operation returns <code>PolicyApplyFailedException</code>. If the WorkSpace is in a state that doesn't allow the change, the policy is being deleted, or another request changed the WorkSpace's agent-enforced policy at the same time, the operation returns <code>ConflictException</code>.</p>
Args:
workspace_id: <p>The identifier of the WorkSpace.</p>
policy_id: <p>The identifier of the policy.</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.policy_apply_failed_exception.PolicyApplyFailedException: <p>The service associated the enforced policy, but it couldn't apply it: the WorkSpace or its agent rejected it, or the service couldn't deliver it to the WorkSpace. Don't retry. Fix the policy and associate it again. To see why, call <code>GetAgenticWorkspaceConfiguration</code>.</p>
capo_workspaces.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource could not be found.</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 – Applying an agent-enforced policy to a WorkSpace
The following example applies an agent-enforced policy to a WorkSpace.
>>> client.associate_agent_enforced_policy(workspace_id='ws-dk1example1', policy_id='wsae-a1b2c3d4')
"""
def _handler(
req: "OperationRequest[capo_workspaces.types.associate_agent_enforced_policy_request.AssociateAgentEnforcedPolicyRequest]",
) -> OperationResponse[
"capo_workspaces.types.associate_agent_enforced_policy_result.AssociateAgentEnforcedPolicyResult"
]:
if req.options.protocol == "awsJson1_1":
import capo_workspaces._operations.workspaces_service.aws_json1_1.associate_agent_enforced_policy
output, http_response = (
capo_workspaces._operations.workspaces_service.aws_json1_1.associate_agent_enforced_policy.associate_agent_enforced_policy(
req.options, req.input
)
)
elif req.options.protocol == "rpcv2Cbor":
import capo_workspaces._operations.workspaces_service.rpcv2_cbor.associate_agent_enforced_policy
output, http_response = (
capo_workspaces._operations.workspaces_service.rpcv2_cbor.associate_agent_enforced_policy.associate_agent_enforced_policy(
req.options, req.input
)
)
else:
raise ValueError(f"unknown protocol {req.options.protocol!r}")
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("AssociateAgentEnforcedPolicy")
)
input_: capo_workspaces.types.associate_agent_enforced_policy_request.AssociateAgentEnforcedPolicyRequest = {
"workspace_id": workspace_id,
"policy_id": policy_id,
}
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|