put_resource_policy
¶
put_resource_policy(
resource_arn: ResourcePolicyResourceArn,
policy: ResourcePolicy,
*,
config_overrides: Optional[ContextClientConfig] = None,
expected_revision_id: Optional[RevisionId] = None,
) -> PutResourcePolicyResponse
Attaches a resource-based policy to an agent context, or replaces the one it has. The policy controls which other accounts can call operations on the agent context. Returns the policy's revision ID.
Parameters:
-
resource_arn(ResourcePolicyResourceArn) –ARN of the agent context to attach the policy to.
-
policy(ResourcePolicy) –The resource-based policy document.
-
expected_revision_id(Optional[RevisionId], default:None) –The revision that you last read. The write succeeds only if it matches the stored revision.
Raises:
-
AccessDeniedException–You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.
-
InternalServerException–The request failed because of an internal error. Retry the request.
-
ThrottlingException–The request was denied because it exceeded a request rate quota. Wait, then retry the request.
-
ValidationException–The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.
-
ConflictException–The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.
-
ResourceNotFoundException–The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Attach a resource-based policy to an agent context The following example lets account 444455556666 also get an agent context, in addition to searching and traversing it, replacing the policy at the revision that GetResourcePolicy returned.
>>> client.put_resource_policy(resource_arn='arn:aws:context:us-east-1:111122223333:agent-context/ac-3f9c2e7a1b8d4c56a0e4f7b29d1c8e53', policy='{"Version":"2012-10-17","Statement":[{"Sid":"AllowAnalyticsAccountRead","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::444455556666:root"},"Action":["context:GetAgentContext","context:SearchAgentContext","context:TraverseAgentContext"],"Resource":"arn:aws:context:us-east-1:111122223333:agent-context/ac-3f9c2e7a1b8d4c56a0e4f7b29d1c8e53"}]}', expected_revision_id='3c7e1a9f-2b4d-4e6a-8f0c-5d9b1e3a7c2f')
Put a policy with a stale revision ID, which fails with ConflictException
The following example shows the ConflictException returned when expectedRevisionId doesn't match the stored revision because another writer changed the policy first.
>>> client.put_resource_policy(resource_arn='arn:aws:context:us-east-1:111122223333:agent-context/ac-3f9c2e7a1b8d4c56a0e4f7b29d1c8e53', policy='{"Version":"2012-10-17","Statement":[{"Sid":"AllowAnalyticsAccountRead","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::444455556666:root"},"Action":["context:SearchAgentContext","context:TraverseAgentContext"],"Resource":"arn:aws:context:us-east-1:111122223333:agent-context/ac-3f9c2e7a1b8d4c56a0e4f7b29d1c8e53"}]}', expected_revision_id='3c7e1a9f-2b4d-4e6a-8f0c-5d9b1e3a7c2f')
Source code in docs_src/capo_context/_services/context.py
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 | |