Skip to content

set_repository_policy async

set_repository_policy(
    repository_name: RepositoryName,
    policy_text: RepositoryPolicyText,
    *,
    config_overrides: Optional[AsyncECRClientConfig] = None,
    registry_id: Optional[RegistryId] = None,
    force: Optional[ForceFlag] = None,
) -> SetRepositoryPolicyResponse

Applies a repository policy to the specified repository to control access permissions. For more information, see Amazon ECR Repository policies in the Amazon Elastic Container Registry User Guide.

Parameters:

  • registry_id (Optional[RegistryId], default: None ) –

    The Amazon Web Services account ID associated with the registry that contains the repository. If you do not specify a registry, the default registry is assumed.

  • repository_name (RepositoryName) –

    The name of the repository to receive the policy.

  • policy_text (RepositoryPolicyText) –

    The JSON repository policy text to apply to the repository. For more information, see Amazon ECR repository policies in the Amazon Elastic Container Registry User Guide.

  • force (Optional[ForceFlag], default: None ) –

    If the policy you are attempting to set on a repository policy would prevent you from setting another policy in the future, you must force the SetRepositoryPolicy operation. This is intended to prevent accidental repository lock outs.

Raises:

  • InvalidParameterException –

    The specified parameter is invalid. Review the available parameters for the API request.

  • RepositoryNotFoundException –

    The specified repository could not be found. Check the spelling of the specified repository and ensure that you are performing operations on the correct registry.

  • ServerException –

    These errors are usually caused by a server-side issue.

  • UnknownServiceError –

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

Source code in docs_src/capo_ecr/_services/async_ecr.py
async def set_repository_policy(
    self,
    repository_name: "capo_ecr.types.repository_name.RepositoryName",
    policy_text: "capo_ecr.types.repository_policy_text.RepositoryPolicyText",
    *,
    config_overrides: Optional[AsyncECRClientConfig] = None,
    registry_id: Optional["capo_ecr.types.registry_id.RegistryId"] = None,
    force: Optional["capo_ecr.types.force_flag.ForceFlag"] = None,
) -> "capo_ecr.types.set_repository_policy_response.SetRepositoryPolicyResponse":
    """<p>Applies a repository policy to the specified repository to control access permissions. For more information, see <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policies.html">Amazon ECR Repository policies</a> in the <i>Amazon Elastic Container Registry User Guide</i>.</p>

    Args:
        registry_id: <p>The Amazon Web Services account ID associated with the registry that contains the repository. If you do not specify a registry, the default registry is assumed.</p>
        repository_name: <p>The name of the repository to receive the policy.</p>
        policy_text: <p>The JSON repository policy text to apply to the repository. For more information, see <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html">Amazon ECR repository policies</a> in the <i>Amazon Elastic Container Registry User Guide</i>.</p>
        force: <p>If the policy you are attempting to set on a repository policy would prevent you from setting another policy in the future, you must force the <a>SetRepositoryPolicy</a> operation. This is intended to prevent accidental repository lock outs.</p>

    Raises:
        capo_ecr.errors.invalid_parameter_exception.InvalidParameterException: <p>The specified parameter is invalid. Review the available parameters for the API request.</p>
        capo_ecr.errors.repository_not_found_exception.RepositoryNotFoundException: <p>The specified repository could not be found. Check the spelling of the specified repository and ensure that you are performing operations on the correct registry.</p>
        capo_ecr.errors.server_exception.ServerException: <p>These errors are usually caused by a server-side issue.</p>
        capo_ecr.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ecr.types.set_repository_policy_request.SetRepositoryPolicyRequest]",
    ) -> AsyncOperationResponse[
        "capo_ecr.types.set_repository_policy_response.SetRepositoryPolicyResponse"
    ]:
        import capo_ecr._operations.amazon_ec2_container_registry_v20150921.set_repository_policy

        (
            output,
            http_response,
        ) = await capo_ecr._operations.amazon_ec2_container_registry_v20150921.set_repository_policy.async_set_repository_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SetRepositoryPolicy")
    )
    input_: capo_ecr.types.set_repository_policy_request.SetRepositoryPolicyRequest = {
        "repository_name": repository_name,
        "policy_text": policy_text,
    }
    if registry_id is not None:
        input_["registry_id"] = registry_id
    if force is not None:
        input_["force"] = force

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