put_resource_policy
async
¶
put_resource_policy(
resource_arn: ResourcePolicyResourceArn,
policy: ResourcePolicy,
*,
config_overrides: Optional[AsyncContextClientConfig] = 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.
>>> await 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.
>>> await 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/async_context.py
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 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 | |