class Repository (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ECR.Repository |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsecr#Repository |
Java | software.amazon.awscdk.services.ecr.Repository |
Python | aws_cdk.aws_ecr.Repository |
TypeScript (source) | aws-cdk-lib » aws_ecr » Repository |
Implements
IConstruct
, IDependable
, IResource
, IRepository
Define an ECR repository.
Example
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
const repo = new ecr.Repository(this, 'Repo');
const lambdaHandler = new lambda.Function(this, 'LambdaFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
code: lambda.Code.fromInline('# dummy func'),
handler: 'index.handler',
});
repo.onEvent('OnEventTargetLambda', {
target: new LambdaFunction(lambdaHandler),
});
Initializer
new Repository(scope: Construct, id: string, props?: RepositoryProps)
Parameters
- scope
Construct
- id
string
- props
Repository
Props
Construct Props
Name | Type | Description |
---|---|---|
auto | boolean | Whether all images should be automatically deleted when the repository is removed from the stack or when the stack is deleted. |
empty | boolean | If true, deleting the repository force deletes the contents of the repository. |
encryption? | Repository | The kind of server-side encryption to apply to this repository. |
encryption | IKey | External KMS key to use for repository encryption. |
image | boolean | Enable the scan on push when creating the repository. |
image | Tag | The tag mutability setting for the repository. |
lifecycle | string | The AWS account ID associated with the registry that contains the repository. |
lifecycle | Lifecycle [] | Life cycle rules to apply to this registry. |
removal | Removal | Determine what happens to the repository when the resource/stack is deleted. |
repository | string | Name for this repository. |
autoDeleteImages?
⚠️ Deprecated: Use emptyOnDelete
instead.
Type:
boolean
(optional, default: false)
Whether all images should be automatically deleted when the repository is removed from the stack or when the stack is deleted.
Requires the removalPolicy
to be set to RemovalPolicy.DESTROY
.
emptyOnDelete?
Type:
boolean
(optional, default: false)
If true, deleting the repository force deletes the contents of the repository.
If false, the repository must be empty before attempting to delete it.
encryption?
Type:
Repository
(optional, default: KMS
if encryptionKey
is specified, or AES256
otherwise.)
The kind of server-side encryption to apply to this repository.
If you choose KMS, you can specify a KMS key via encryptionKey
. If
encryptionKey is not specified, an AWS managed KMS key is used.
encryptionKey?
Type:
IKey
(optional, default: If encryption is set to KMS
and this property is undefined,
an AWS managed KMS key is used.)
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".
imageScanOnPush?
Type:
boolean
(optional, default: false)
Enable the scan on push when creating the repository.
imageTagMutability?
Type:
Tag
(optional, default: TagMutability.MUTABLE)
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.
lifecycleRegistryId?
Type:
string
(optional, default: The default registry is assumed.)
The AWS account ID associated with the registry that contains the repository.
lifecycleRules?
Type:
Lifecycle
[]
(optional, default: No life cycle rules)
Life cycle rules to apply to this registry.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.Retain)
Determine what happens to the repository when the resource/stack is deleted.
repositoryName?
Type:
string
(optional, default: Automatically generated name.)
Name for this repository.
The repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, and forward slashes.
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
repository | string | The ARN of the repository. |
repository | string | The name of the repository. |
repository | string | The URI of this repository (represents the latest image):. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
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
Type:
Node
The tree node.
repositoryArn
Type:
string
The ARN of the repository.
repositoryName
Type:
string
The name of the repository.
repositoryUri
Type:
string
The URI of this repository (represents the latest image):.
ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
add | Add a life cycle rule to the repository. |
add | Add a policy statement to the repository's resource policy. |
apply | Apply the given removal policy to this resource. |
grant(grantee, ...actions) | Grant the given principal identity permissions to perform the actions on this repository. |
grant | Grant the given identity permissions to use the images in this repository. |
grant | Grant the given identity permissions to pull and push images to this repository. |
grant | Grant the given identity permissions to use the images in this repository. |
grant | Grant the given identity permissions to read the images in this repository. |
on | Define a CloudWatch event that triggers when something happens to this repository. |
on | Defines an AWS CloudWatch event rule that can trigger a target when an image is pushed to this repository. |
on | Defines a CloudWatch event rule which triggers for repository events. |
on | Defines an AWS CloudWatch event rule that can trigger a target when an image scan is completed. |
repository | Returns the URL of the repository. Can be used in docker push/pull . |
repository | Returns the URL of the repository. Can be used in docker push/pull . |
repository | Returns the URL of the repository. Can be used in docker push/pull . |
to | Returns a string representation of this construct. |
static arn | Returns an ECR ARN for a repository that resides in the same account/region as the current stack. |
static from | |
static from | Import a repository. |
static from |
addLifecycleRule(rule)
public addLifecycleRule(rule: LifecycleRule): void
Parameters
- rule
Lifecycle
Rule
Add a life cycle rule to the repository.
Life cycle rules automatically expire images from the repository that match certain conditions.
addToResourcePolicy(statement)
public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
Statement
Returns
Add a policy statement to the repository's resource policy.
While other resources policies in AWS either require or accept a resource section, Cfn for ECR does not allow us to specify a resource policy. It will fail if a resource section is present at all.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
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
).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
- actions
string
Returns
Grant the given principal identity permissions to perform the actions on this repository.
grantPull(grantee)
public grantPull(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant the given identity permissions to use the images in this repository.
grantPullPush(grantee)
public grantPullPush(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant the given identity permissions to pull and push images to this repository.
grantPush(grantee)
public grantPush(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant the given identity permissions to use the images in this repository.
grantRead(grantee)
public grantRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant the given identity permissions to read the images in this repository.
onCloudTrailEvent(id, options?)
public onCloudTrailEvent(id: string, options?: OnEventOptions): Rule
Parameters
- id
string
— The id of the rule. - options
On
— Options for adding the rule.Event Options
Returns
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.
onCloudTrailImagePushed(id, options?)
public onCloudTrailImagePushed(id: string, options?: OnCloudTrailImagePushedOptions): Rule
Parameters
- id
string
— The id of the rule. - options
On
— Options for adding the rule.Cloud Trail Image Pushed Options
Returns
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.
onEvent(id, options?)
public onEvent(id: string, options?: OnEventOptions): Rule
Parameters
- id
string
- options
On
Event Options
Returns
Defines a CloudWatch event rule which triggers for repository events.
Use
rule.addEventPattern(pattern)
to specify a filter.
onImageScanCompleted(id, options?)
public onImageScanCompleted(id: string, options?: OnImageScanCompletedOptions): Rule
Parameters
- id
string
— The id of the rule. - options
On
— Options for adding the rule.Image Scan Completed Options
Returns
Defines an AWS CloudWatch event rule that can trigger a target when an image scan is completed.
repositoryUriForDigest(digest?)
public repositoryUriForDigest(digest?: string): string
Parameters
- digest
string
— Optional image digest.
Returns
string
Returns the URL of the repository. Can be used in docker push/pull
.
ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
repositoryUriForTag(tag?)
public repositoryUriForTag(tag?: string): string
Parameters
- tag
string
— Optional image tag.
Returns
string
Returns the URL of the repository. Can be used in docker push/pull
.
ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[:TAG]
repositoryUriForTagOrDigest(tagOrDigest?)
public repositoryUriForTagOrDigest(tagOrDigest?: string): string
Parameters
- tagOrDigest
string
— Optional image tag or digest (digests must start withsha256:
).
Returns
string
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]
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static arnForLocalRepository(repositoryName, scope, account?)
public static arnForLocalRepository(repositoryName: string, scope: IConstruct, account?: string): string
Parameters
- repositoryName
string
- scope
IConstruct
- account
string
Returns
string
Returns an ECR ARN for a repository that resides in the same account/region as the current stack.
static fromRepositoryArn(scope, id, repositoryArn)
public static fromRepositoryArn(scope: Construct, id: string, repositoryArn: string): IRepository
Parameters
- scope
Construct
- id
string
- repositoryArn
string
Returns
static fromRepositoryAttributes(scope, id, attrs)
public static fromRepositoryAttributes(scope: Construct, id: string, attrs: RepositoryAttributes): IRepository
Parameters
- scope
Construct
- id
string
- attrs
Repository
Attributes
Returns
Import a repository.
static fromRepositoryName(scope, id, repositoryName)
public static fromRepositoryName(scope: Construct, id: string, repositoryName: string): IRepository
Parameters
- scope
Construct
- id
string
- repositoryName
string
Returns