Repository
- class aws_cdk.aws_ecr.Repository(scope, id, *, encryption=None, encryption_key=None, image_scan_on_push=None, image_tag_mutability=None, lifecycle_registry_id=None, lifecycle_rules=None, removal_policy=None, repository_name=None)
Bases:
RepositoryBase
Define an ECR repository.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_ecr as ecr apprunner.Service(self, "Service", source=apprunner.Source.from_ecr( image_configuration=apprunner.ImageConfiguration(port=80), repository=ecr.Repository.from_repository_name(self, "NginxRepository", "nginx"), tag_or_digest="latest" ) )
- Parameters:
scope (
Construct
) –id (
str
) –encryption (
Optional
[RepositoryEncryption
]) – The kind of server-side encryption to apply to this repository. If you choose KMS, you can specify a KMS key viaencryptionKey
. If encryptionKey is not specified, an AWS managed KMS key is used. Default: -KMS
ifencryptionKey
is specified, orAES256
otherwise.encryption_key (
Optional
[IKey
]) – External KMS key to use for repository encryption. The ‘encryption’ property must be either not specified or set to “KMS”. An error will be emitted if encryption is set to “AES256”. Default: - If encryption is set toKMS
and this property is undefined, an AWS managed KMS key is used.image_scan_on_push (
Optional
[bool
]) – Enable the scan on push when creating the repository. Default: falseimage_tag_mutability (
Optional
[TagMutability
]) – The tag mutability setting for the repository. If this parameter is omitted, the default setting of MUTABLE will be used which will allow image tags to be overwritten. Default: TagMutability.MUTABLElifecycle_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
[Sequence
[Union
[LifecycleRule
,Dict
[str
,Any
]]]]) – Life cycle rules to apply to this registry. Default: No life cycle rulesremoval_policy (
Optional
[RemovalPolicy
]) – Determine what happens to the repository when the resource/stack is deleted. Default: RemovalPolicy.Retainrepository_name (
Optional
[str
]) – Name for this repository. Default: Automatically generated name.
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 descriptionmax_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 assignedtag_prefix_list (
Optional
[Sequence
[str
]]) – Select images that have ALL the given prefixes in their tag. Only if tagStatus == TagStatus.Taggedtag_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:
- apply_removal_policy(policy)
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.
The resource can be deleted (
RemovalPolicy.DESTROY
), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN
).- Parameters:
policy (
RemovalPolicy
) –- Return type:
None
- grant(grantee, *actions)
Grant the given principal identity permissions to perform the actions on this repository.
- Parameters:
grantee (
IGrantable
) –actions (
str
) –
- Return type:
- grant_pull(grantee)
Grant the given identity permissions to use the images in this repository.
- Parameters:
grantee (
IGrantable
) –- Return type:
- grant_pull_push(grantee)
Grant the given identity permissions to pull and push images to this repository.
- Parameters:
grantee (
IGrantable
) –- Return type:
- 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 descriptionevent_pattern (
Union
[EventPattern
,Dict
[str
,Any
],None
]) – 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. UseaddTarget()
to add a target.
- Return type:
- 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 tagsdescription (
Optional
[str
]) – A description of the rule’s purpose. Default: - No descriptionevent_pattern (
Union
[EventPattern
,Dict
[str
,Any
],None
]) – 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. UseaddTarget()
to add a target.
- Return type:
- 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 descriptionevent_pattern (
Union
[EventPattern
,Dict
[str
,Any
],None
]) – 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. UseaddTarget()
to add a target.
- Return type:
- 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
[Sequence
[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 tagsdescription (
Optional
[str
]) – A description of the rule’s purpose. Default: - No descriptionevent_pattern (
Union
[EventPattern
,Dict
[str
,Any
],None
]) – 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. UseaddTarget()
to add a target.
- Return type:
- repository_uri_for_digest(digest=None)
Returns the URL of the repository. Can be used in
docker push/pull
.ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
- Parameters:
digest (
Optional
[str
]) – Optional image digest.- Return type:
str
- 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
- repository_uri_for_tag_or_digest(tag_or_digest=None)
Returns the URL of the repository. Can be used in
docker push/pull
.ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[:TAG] ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
- Parameters:
tag_or_digest (
Optional
[str
]) – Optional image tag or digest (digests must start withsha256:
).- Return type:
str
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- env
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
- node
The construct tree node associated with this construct.
- repository_arn
The ARN of the repository.
- repository_name
The name of the repository.
- repository_uri
.
ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY
- Type:
The URI of this repository (represents the latest image)
- stack
The stack in which this resource is defined.
Static Methods
- classmethod arn_for_local_repository(repository_name, scope, account=None)
Returns an ECR ARN for a repository that resides in the same account/region as the current stack.
- Parameters:
repository_name (
str
) –scope (
IConstruct
) –account (
Optional
[str
]) –
- Return type:
str
- classmethod from_repository_arn(scope, id, repository_arn)
- Parameters:
scope (
Construct
) –id (
str
) –repository_arn (
str
) –
- Return type:
- 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:
- classmethod from_repository_name(scope, id, repository_name)
- Parameters:
scope (
Construct
) –id (
str
) –repository_name (
str
) –
- Return type:
- classmethod is_construct(x)
Return whether the given object is a Construct.
- Parameters:
x (
Any
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool