Skip to content

put_resource_policy async

put_resource_policy(
    resource_arn: ResourceArnString,
    policy: Policy,
    *,
    config_overrides: Optional[AsyncSSMClientConfig] = None,
    policy_id: Optional[PolicyId] = None,
    policy_hash: Optional[PolicyHash] = None,
) -> PutResourcePolicyResponse

Creates or updates a Systems Manager resource policy. A resource policy helps you to define the IAM entity (for example, an Amazon Web Services account) that can manage your Systems Manager resources. The following resources support Systems Manager resource policies.

  • OpsItemGroup - The resource policy for OpsItemGroup enables Amazon Web Services accounts to view and interact with OpsCenter operational work items (OpsItems).

  • Parameter - The resource policy is used to share a parameter with other accounts using Resource Access Manager (RAM).

    To share a parameter, it must be in the advanced parameter tier. For information about parameter tiers, see Managing parameter tiers. For information about changing an existing standard parameter to an advanced parameter, see Changing a standard parameter to an advanced parameter.

    To share a SecureString parameter, it must be encrypted with a customer managed key, and you must share the key separately through Key Management Service. Amazon Web Services managed keys cannot be shared. Parameters encrypted with the default Amazon Web Services managed key can be updated to use a customer managed key instead. For KMS key definitions, see KMS concepts in the Key Management Service Developer Guide.

    While you can share a parameter using the Systems Manager PutResourcePolicy operation, we recommend using Resource Access Manager (RAM) instead. This is because using PutResourcePolicy requires the extra step of promoting the parameter to a standard RAM Resource Share using the RAM PromoteResourceShareCreatedFromPolicy API operation. Otherwise, the parameter won't be returned by the Systems Manager DescribeParameters API operation using the --shared option.

    For more information, see Sharing a parameter in the Amazon Web Services Systems Manager User Guide

  • Document – Shares the document using Resource Access Manager (RAM). For more information about sharing documents, see Sharing Systems Manager documents in the Amazon Web Services Systems Manager User Guide.

While you can share a document using the Systems Manager PutResourcePolicy operation, we recommend using Resource Access Manager (RAM) instead. Using PutResourcePolicy requires an extra step. You must promote the document to a standard RAM Resource Share using the RAM PromoteResourceShareCreatedFromPolicy API operation. Otherwise, the Systems Manager ListDocuments API operation won't return the document when filtering for shared documents. The Amazon Web Services Config PutRemediationConfigurations API operation also can't use the document.

Parameters:

  • resource_arn (ResourceArnString) –

    Amazon Resource Name (ARN) of the resource to which you want to attach a policy.

  • policy (Policy) –

    A policy you want to associate with a resource.

  • policy_id (Optional[PolicyId], default: None ) –

    The policy ID.

  • policy_hash (Optional[PolicyHash], default: None ) –

    ID of the current policy version. The hash helps to prevent a situation where multiple users attempt to overwrite a policy. You must provide this hash when updating or deleting a policy.

Raises:

Source code in docs_src/capo_ssm/_services/async_ssm.py
async def put_resource_policy(
    self,
    resource_arn: "capo_ssm.types.resource_arn_string.ResourceArnString",
    policy: "capo_ssm.types.policy.Policy",
    *,
    config_overrides: Optional[AsyncSSMClientConfig] = None,
    policy_id: Optional["capo_ssm.types.policy_id.PolicyId"] = None,
    policy_hash: Optional["capo_ssm.types.policy_hash.PolicyHash"] = None,
) -> "capo_ssm.types.put_resource_policy_response.PutResourcePolicyResponse":
    """<p>Creates or updates a Systems Manager resource policy. A resource policy helps you to define the IAM entity (for example, an Amazon Web Services account) that can manage your Systems Manager resources. The following resources support Systems Manager resource policies.</p> <ul> <li> <p> <code>OpsItemGroup</code> - The resource policy for <code>OpsItemGroup</code> enables Amazon Web Services accounts to view and interact with OpsCenter operational work items (OpsItems).</p> </li> <li> <p> <code>Parameter</code> - The resource policy is used to share a parameter with other accounts using Resource Access Manager (RAM). </p> <p>To share a parameter, it must be in the advanced parameter tier. For information about parameter tiers, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html">Managing parameter tiers</a>. For information about changing an existing standard parameter to an advanced parameter, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html#parameter-store-advanced-parameters-enabling">Changing a standard parameter to an advanced parameter</a>.</p> <p>To share a <code>SecureString</code> parameter, it must be encrypted with a customer managed key, and you must share the key separately through Key Management Service. Amazon Web Services managed keys cannot be shared. Parameters encrypted with the default Amazon Web Services managed key can be updated to use a customer managed key instead. For KMS key definitions, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html">KMS concepts</a> in the <i>Key Management Service Developer Guide</i>.</p> <important> <p>While you can share a parameter using the Systems Manager <code>PutResourcePolicy</code> operation, we recommend using Resource Access Manager (RAM) instead. This is because using <code>PutResourcePolicy</code> requires the extra step of promoting the parameter to a standard RAM Resource Share using the RAM <a href="https://docs.aws.amazon.com/ram/latest/APIReference/API_PromoteResourceShareCreatedFromPolicy.html">PromoteResourceShareCreatedFromPolicy</a> API operation. Otherwise, the parameter won't be returned by the Systems Manager <a href="https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DescribeParameters.html">DescribeParameters</a> API operation using the <code>--shared</code> option.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-shared-parameters.html#share">Sharing a parameter</a> in the <i>Amazon Web Services Systems Manager User Guide</i> </p> </important> </li> <li> <p> <code>Document</code> – Shares the document using Resource Access Manager (RAM). For more information about sharing documents, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/documents-ssm-sharing.html">Sharing Systems Manager documents</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p> </li> </ul> <important> <p>While you can share a document using the Systems Manager <code>PutResourcePolicy</code> operation, we recommend using Resource Access Manager (RAM) instead. Using <code>PutResourcePolicy</code> requires an extra step. You must promote the document to a standard RAM Resource Share using the RAM <a href="https://docs.aws.amazon.com/ram/latest/APIReference/API_PromoteResourceShareCreatedFromPolicy.html">PromoteResourceShareCreatedFromPolicy</a> API operation. Otherwise, the Systems Manager <a href="https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_ListDocuments.html">ListDocuments</a> API operation won't return the document when filtering for shared documents. The Amazon Web Services Config <a href="https://docs.aws.amazon.com/config/latest/APIReference/API_PutRemediationConfigurations.html">PutRemediationConfigurations</a> API operation also can't use the document.</p> </important>

    Args:
        resource_arn: <p>Amazon Resource Name (ARN) of the resource to which you want to attach a policy.</p>
        policy: <p>A policy you want to associate with a resource.</p>
        policy_id: <p>The policy ID.</p>
        policy_hash: <p>ID of the current policy version. The hash helps to prevent a situation where multiple users attempt to overwrite a policy. You must provide this hash when updating or deleting a policy.</p>

    Raises:
        capo_ssm.errors.internal_server_error.InternalServerError: <p>An error occurred on the server side.</p>
        capo_ssm.errors.malformed_resource_policy_document_exception.MalformedResourcePolicyDocumentException: <p>The specified policy document is malformed or invalid, or excessive <code>PutResourcePolicy</code> or <code>DeleteResourcePolicy</code> calls have been made.</p>
        capo_ssm.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified parameter to be shared could not be found.</p>
        capo_ssm.errors.resource_policy_conflict_exception.ResourcePolicyConflictException: <p>The hash provided in the call doesn't match the stored hash. This exception is thrown when trying to update an obsolete policy version or when multiple requests to update a policy are sent.</p>
        capo_ssm.errors.resource_policy_invalid_parameter_exception.ResourcePolicyInvalidParameterException: <p>One or more parameters specified for the call aren't valid. Verify the parameters and their values and try again.</p>
        capo_ssm.errors.resource_policy_limit_exceeded_exception.ResourcePolicyLimitExceededException: <p>The <a>PutResourcePolicy</a> API action enforces two limits. A policy can't be greater than 1024 bytes in size. And only one policy can be attached to <code>OpsItemGroup</code>. Verify these limits and try again.</p>
        capo_ssm.errors.resource_policy_not_found_exception.ResourcePolicyNotFoundException: <p>No policies with the specified policy ID and hash could be found.</p>
        capo_ssm.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ssm.types.put_resource_policy_request.PutResourcePolicyRequest]",
    ) -> AsyncOperationResponse[
        "capo_ssm.types.put_resource_policy_response.PutResourcePolicyResponse"
    ]:
        import capo_ssm._operations.amazon_ssm.put_resource_policy

        (
            output,
            http_response,
        ) = await capo_ssm._operations.amazon_ssm.put_resource_policy.async_put_resource_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutResourcePolicy")
    )
    input_: capo_ssm.types.put_resource_policy_request.PutResourcePolicyRequest = {
        "resource_arn": resource_arn,
        "policy": policy,
    }
    if policy_id is not None:
        input_["policy_id"] = policy_id
    if policy_hash is not None:
        input_["policy_hash"] = policy_hash

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output