Repository

class aws_cdk.aws_ecr.Repository(scope, id, *, image_scan_on_push=None, lifecycle_registry_id=None, lifecycle_rules=None, removal_policy=None, repository_name=None)

Bases: aws_cdk.aws_ecr.RepositoryBase

Define an ECR repository.

__init__(scope, id, *, image_scan_on_push=None, lifecycle_registry_id=None, lifecycle_rules=None, removal_policy=None, repository_name=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • image_scan_on_push (Optional[bool]) – Enable the scan on push when creating the repository. Default: false

  • lifecycle_registry_id (Optional[str]) – The AWS account ID associated with the registry that contains the repository. Default: The default registry is assumed.

  • lifecycle_rules (Optional[List[LifecycleRule]]) – Life cycle rules to apply to this registry. Default: No life cycle rules

  • removal_policy (Optional[RemovalPolicy]) – Determine what happens to the repository when the resource/stack is deleted. Default: RemovalPolicy.Retain

  • repository_name (Optional[str]) – Name for this repository. Default: Automatically generated name.

Return type

None

Methods

add_lifecycle_rule(*, description=None, max_image_age=None, max_image_count=None, rule_priority=None, tag_prefix_list=None, tag_status=None)

Add a life cycle rule to the repository.

Life cycle rules automatically expire images from the repository that match certain conditions.

Parameters
  • description (Optional[str]) – Describes the purpose of the rule. Default: No description

  • max_image_age (Optional[Duration]) – The maximum age of images to retain. The value must represent a number of days. Specify exactly one of maxImageCount and maxImageAge.

  • max_image_count (Union[int, float, None]) – The maximum number of images to retain. Specify exactly one of maxImageCount and maxImageAge.

  • rule_priority (Union[int, float, None]) – Controls the order in which rules are evaluated (low to high). All rules must have a unique priority, where lower numbers have higher precedence. The first rule that matches is applied to an image. There can only be one rule with a tagStatus of Any, and it must have the highest rulePriority. All rules without a specified priority will have incrementing priorities automatically assigned to them, higher than any rules that DO have priorities. Default: Automatically assigned

  • tag_prefix_list (Optional[List[str]]) – Select images that have ALL the given prefixes in their tag. Only if tagStatus == TagStatus.Tagged

  • tag_status (Optional[TagStatus]) – Select images based on tags. Only one rule is allowed to select untagged images, and it must have the highest rulePriority. Default: TagStatus.Tagged if tagPrefixList is given, TagStatus.Any otherwise

Return type

None

add_to_resource_policy(statement)

Add a policy statement to the repository’s resource policy.

Parameters

statement (PolicyStatement) –

Return type

AddToResourcePolicyResult

grant(grantee, *actions)

Grant the given principal identity permissions to perform the actions on this repository.

Parameters
Return type

Grant

grant_pull(grantee)

Grant the given identity permissions to use the images in this repository.

Parameters

grantee (IGrantable) –

Return type

Grant

grant_pull_push(grantee)

Grant the given identity permissions to pull and push images to this repository.

Parameters

grantee (IGrantable) –

Return type

Grant

on_cloud_trail_event(id, *, description=None, event_pattern=None, rule_name=None, target=None)

Define a CloudWatch event that triggers when something happens to this repository.

Requires that there exists at least one CloudTrail Trail in your account that captures the event. This method will not create the Trail.

Parameters
  • id (str) – The id of the rule.

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Optional[EventPattern]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

Return type

Rule

on_cloud_trail_image_pushed(id, *, image_tag=None, description=None, event_pattern=None, rule_name=None, target=None)

Defines an AWS CloudWatch event rule that can trigger a target when an image is pushed to this repository.

Requires that there exists at least one CloudTrail Trail in your account that captures the event. This method will not create the Trail.

Parameters
  • id (str) – The id of the rule.

  • image_tag (Optional[str]) – Only watch changes to this image tag. Default: - Watch changes to all tags

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Optional[EventPattern]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

Return type

Rule

on_event(id, *, description=None, event_pattern=None, rule_name=None, target=None)

Defines a CloudWatch event rule which triggers for repository events.

Use rule.addEventPattern(pattern) to specify a filter.

Parameters
  • id (str) –

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Optional[EventPattern]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

Return type

Rule

on_image_scan_completed(id, *, image_tags=None, description=None, event_pattern=None, rule_name=None, target=None)

Defines an AWS CloudWatch event rule that can trigger a target when an image scan is completed.

Parameters
  • id (str) – The id of the rule.

  • image_tags (Optional[List[str]]) – Only watch changes to the image tags spedified. Leave it undefined to watch the full repository. Default: - Watch the changes to the repository with all image tags

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Optional[EventPattern]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

Return type

Rule

repository_uri_for_tag(tag=None)

Returns the URL of the repository. Can be used in docker push/pull.

ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[:TAG]

Parameters

tag (Optional[str]) – Optional image tag.

Return type

str

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

node

The construct tree node associated with this construct.

Return type

ConstructNode

repository_arn

The ARN of the repository.

Return type

str

repository_name

The name of the repository.

Return type

str

repository_uri

.

ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY

Type

The URI of this repository (represents the latest image)

Return type

str

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod arn_for_local_repository(repository_name, scope)

Returns an ECR ARN for a repository that resides in the same account/region as the current stack.

Parameters
  • repository_name (str) –

  • scope (IConstruct) –

Return type

str

classmethod from_repository_arn(scope, id, repository_arn)
Parameters
  • scope (Construct) –

  • id (str) –

  • repository_arn (str) –

Return type

IRepository

classmethod from_repository_attributes(scope, id, *, repository_arn, repository_name)

Import a repository.

Parameters
  • scope (Construct) –

  • id (str) –

  • repository_arn (str) –

  • repository_name (str) –

Return type

IRepository

classmethod from_repository_name(scope, id, repository_name)
Parameters
  • scope (Construct) –

  • id (str) –

  • repository_name (str) –

Return type

IRepository

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool