Skip to content

create_pull_through_cache_rule

create_pull_through_cache_rule(
    ecr_repository_prefix: PullThroughCacheRuleRepositoryPrefix,
    upstream_registry_url: Url,
    *,
    config_overrides: Optional[ECRClientConfig] = None,
    registry_id: Optional[RegistryId] = None,
    upstream_registry: Optional[UpstreamRegistry] = None,
    credential_arn: Optional[CredentialArn] = None,
    custom_role_arn: Optional[CustomRoleArn] = None,
    upstream_repository_prefix: Optional[PullThroughCacheRuleRepositoryPrefix] = None,
) -> CreatePullThroughCacheRuleResponse

Creates a pull through cache rule. A pull through cache rule provides a way to cache images from an upstream registry source in your Amazon ECR private registry. For more information, see Using pull through cache rules in the Amazon Elastic Container Registry User Guide.

Parameters:

  • ecr_repository_prefix (PullThroughCacheRuleRepositoryPrefix) –

    The repository name prefix to use when caching images from the source registry.

    There is always an assumed / applied to the end of the prefix. If you specify ecr-public as the prefix, Amazon ECR treats that as ecr-public/.

  • upstream_registry_url (Url) –

    The registry URL of the upstream public registry to use as the source for the pull through cache rule. The following is the syntax to use for each supported upstream registry.

    • Amazon ECR (ecr) – .dkr.ecr..amazonaws.com

    • Amazon ECR Public (ecr-public) – public.ecr.aws

    • Docker Hub (docker-hub) – registry-1.docker.io

    • GitHub Container Registry (github-container-registry) – ghcr.io

    • GitLab Container Registry (gitlab-container-registry) – registry.gitlab.com

    • Kubernetes (k8s) – registry.k8s.io

    • Microsoft Azure Container Registry (azure-container-registry) – .azurecr.io

    • Quay (quay) – quay.io

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

    The Amazon Web Services account ID associated with the registry to create the pull through cache rule for. If you do not specify a registry, the default registry is assumed.

  • upstream_registry (Optional[UpstreamRegistry], default: None ) –

    The name of the upstream registry.

  • credential_arn (Optional[CredentialArn], default: None ) –

    The Amazon Resource Name (ARN) of the Amazon Web Services Secrets Manager secret that identifies the credentials to authenticate to the upstream registry.

  • custom_role_arn (Optional[CustomRoleArn], default: None ) –

    Amazon Resource Name (ARN) of the IAM role to be assumed by Amazon ECR to authenticate to the ECR upstream registry. This role must be in the same account as the registry that you are configuring.

  • upstream_repository_prefix (Optional[PullThroughCacheRuleRepositoryPrefix], default: None ) –

    The repository name prefix of the upstream registry to match with the upstream repository name. When this field isn't specified, Amazon ECR will use the ROOT.

Raises:

Source code in docs_src/capo_ecr/_services/ecr.py
def create_pull_through_cache_rule(
    self,
    ecr_repository_prefix: "capo_ecr.types.pull_through_cache_rule_repository_prefix.PullThroughCacheRuleRepositoryPrefix",
    upstream_registry_url: "capo_ecr.types.url.Url",
    *,
    config_overrides: Optional[ECRClientConfig] = None,
    registry_id: Optional["capo_ecr.types.registry_id.RegistryId"] = None,
    upstream_registry: Optional[
        "capo_ecr.types.upstream_registry.UpstreamRegistry"
    ] = None,
    credential_arn: Optional["capo_ecr.types.credential_arn.CredentialArn"] = None,
    custom_role_arn: Optional[
        "capo_ecr.types.custom_role_arn.CustomRoleArn"
    ] = None,
    upstream_repository_prefix: Optional[
        "capo_ecr.types.pull_through_cache_rule_repository_prefix.PullThroughCacheRuleRepositoryPrefix"
    ] = None,
) -> "capo_ecr.types.create_pull_through_cache_rule_response.CreatePullThroughCacheRuleResponse":
    """<p>Creates a pull through cache rule. A pull through cache rule provides a way to cache images from an upstream registry source in your Amazon ECR private registry. For more information, see <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/pull-through-cache.html">Using pull through cache rules</a> in the <i>Amazon Elastic Container Registry User Guide</i>.</p>

    Args:
        ecr_repository_prefix: <p>The repository name prefix to use when caching images from the source registry.</p> <important> <p>There is always an assumed <code>/</code> applied to the end of the prefix. If you specify <code>ecr-public</code> as the prefix, Amazon ECR treats that as <code>ecr-public/</code>.</p> </important>
        upstream_registry_url: <p>The registry URL of the upstream public registry to use as the source for the pull through cache rule. The following is the syntax to use for each supported upstream registry.</p> <ul> <li> <p>Amazon ECR (<code>ecr</code>) – <code><accountId>.dkr.ecr.<region>.amazonaws.com</code> </p> </li> <li> <p>Amazon ECR Public (<code>ecr-public</code>) – <code>public.ecr.aws</code> </p> </li> <li> <p>Docker Hub (<code>docker-hub</code>) – <code>registry-1.docker.io</code> </p> </li> <li> <p>GitHub Container Registry (<code>github-container-registry</code>) – <code>ghcr.io</code> </p> </li> <li> <p>GitLab Container Registry (<code>gitlab-container-registry</code>) – <code>registry.gitlab.com</code> </p> </li> <li> <p>Kubernetes (<code>k8s</code>) – <code>registry.k8s.io</code> </p> </li> <li> <p>Microsoft Azure Container Registry (<code>azure-container-registry</code>) – <code><custom>.azurecr.io</code> </p> </li> <li> <p>Quay (<code>quay</code>) – <code>quay.io</code> </p> </li> </ul>
        registry_id: <p>The Amazon Web Services account ID associated with the registry to create the pull through cache rule for. If you do not specify a registry, the default registry is assumed.</p>
        upstream_registry: <p>The name of the upstream registry.</p>
        credential_arn: <p>The Amazon Resource Name (ARN) of the Amazon Web Services Secrets Manager secret that identifies the credentials to authenticate to the upstream registry.</p>
        custom_role_arn: <p>Amazon Resource Name (ARN) of the IAM role to be assumed by Amazon ECR to authenticate to the ECR upstream registry. This role must be in the same account as the registry that you are configuring.</p>
        upstream_repository_prefix: <p>The repository name prefix of the upstream registry to match with the upstream repository name. When this field isn't specified, Amazon ECR will use the <code>ROOT</code>.</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.limit_exceeded_exception.LimitExceededException: <p>The operation did not succeed because it would have exceeded a service limit for your account. For more information, see <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/service-quotas.html">Amazon ECR service quotas</a> in the Amazon Elastic Container Registry User Guide.</p>
        capo_ecr.errors.pull_through_cache_rule_already_exists_exception.PullThroughCacheRuleAlreadyExistsException: <p>A pull through cache rule with these settings already exists for the private registry.</p>
        capo_ecr.errors.secret_not_found_exception.SecretNotFoundException: <p>The ARN of the secret specified in the pull through cache rule was not found. Update the pull through cache rule with a valid secret ARN and try again.</p>
        capo_ecr.errors.server_exception.ServerException: <p>These errors are usually caused by a server-side issue.</p>
        capo_ecr.errors.unable_to_access_secret_exception.UnableToAccessSecretException: <p>The secret is unable to be accessed. Verify the resource permissions for the secret and try again.</p>
        capo_ecr.errors.unable_to_decrypt_secret_value_exception.UnableToDecryptSecretValueException: <p>The secret is accessible but is unable to be decrypted. Verify the resource permisisons and try again.</p>
        capo_ecr.errors.unsupported_upstream_registry_exception.UnsupportedUpstreamRegistryException: <p>The specified upstream registry isn't supported.</p>
        capo_ecr.errors.validation_exception.ValidationException: <p>There was an exception validating this request.</p>
        capo_ecr.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_ecr.types.create_pull_through_cache_rule_request.CreatePullThroughCacheRuleRequest]",
    ) -> OperationResponse[
        "capo_ecr.types.create_pull_through_cache_rule_response.CreatePullThroughCacheRuleResponse"
    ]:
        import capo_ecr._operations.amazon_ec2_container_registry_v20150921.create_pull_through_cache_rule

        output, http_response = (
            capo_ecr._operations.amazon_ec2_container_registry_v20150921.create_pull_through_cache_rule.create_pull_through_cache_rule(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreatePullThroughCacheRule")
    )
    input_: capo_ecr.types.create_pull_through_cache_rule_request.CreatePullThroughCacheRuleRequest = {
        "ecr_repository_prefix": ecr_repository_prefix,
        "upstream_registry_url": upstream_registry_url,
    }
    if registry_id is not None:
        input_["registry_id"] = registry_id
    if upstream_registry is not None:
        input_["upstream_registry"] = upstream_registry
    if credential_arn is not None:
        input_["credential_arn"] = credential_arn
    if custom_role_arn is not None:
        input_["custom_role_arn"] = custom_role_arn
    if upstream_repository_prefix is not None:
        input_["upstream_repository_prefix"] = upstream_repository_prefix

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output