# Repository

Provides a CodeCommit Repository.

Extends: Construct › Resource › Repository
Implements: IResource, IRepository, INotificationRuleSource, IEnvironmentAware, IRepositoryRef, IConstruct, IDependable

- CloudFormation: [`AWS::CodeCommit::Repository`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-codecommit-repository.html)
- L1 type: [`CfnRepository`](/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.CfnRepository.html)
- Source: [`aws-codecommit/lib/repository.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts#L548)
- Type last changed: v2.227.0 · 21 Nov 2025

## Example

```ts
declare const project: codebuild.PipelineProject;
const repository = new codecommit.Repository(this, 'MyRepository', {
  repositoryName: 'MyRepository',
});
const project = new codebuild.PipelineProject(this, 'MyProject');

const sourceOutput = new codepipeline.Artifact();
const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
  actionName: 'CodeCommit',
  repository,
  output: sourceOutput,
});
const buildAction = new codepipeline_actions.CodeBuildAction({
  actionName: 'CodeBuild',
  project,
  input: sourceOutput,
  outputs: [new codepipeline.Artifact()], // optional
  executeBatchBuild: true, // optional, defaults to false
  combineBatchBuildArtifacts: true, // optional, defaults to false
});

new codepipeline.Pipeline(this, 'MyPipeline', {
  stages: [
    {
      stageName: 'Source',
      actions: [sourceAction],
    },
    {
      stageName: 'Build',
      actions: [buildAction],
    },
  ],
});
```

## Initializer

```ts
new Repository(scope: Construct, id: string, props: RepositoryProps)
```

## Construct Props

- `code`: [Code](/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.Code.html) = No initialization (create empty repo) — The contents with which to initialize the repository after it has been created.

  **Default:** No initialization (create empty repo)

- `description`: string = No description. — A description of the repository.

  Use the description to identify the
  purpose of the repository.

- `kmsKey`: [IKeyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_kms.IKeyRef.html) = Use an AWS managed key — The customer managed key used to encrypt and decrypt the data in repository.

- `repositoryName`: string (required) — Name of the repository.

  This property is required for all CodeCommit repositories.

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `grants`: [RepositoryGrants](/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.RepositoryGrants.html) (required) — Collection of grant methods for a Repository.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `repositoryArn`: string (required) — The ARN of this Repository.

- `repositoryCloneUrlGrc`: string (required) — The HTTPS (GRC) clone URL.

  HTTPS (GRC) is the protocol to use with git-remote-codecommit (GRC).

  It is the recommended method for supporting connections made with federated
  access, identity providers, and temporary credentials.

- `repositoryCloneUrlHttp`: string (required) — The HTTP clone URL.

- `repositoryCloneUrlSsh`: string (required) — The SSH clone URL.

- `repositoryName`: string (required) — The human-visible name of this Repository.

- `repositoryRef`: [RepositoryReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_codecommit.RepositoryReference.html) (required) — A reference to a Repository resource.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — 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`).

- `bindAsNotificationRuleSource(_scope: Construct): NotificationRuleSourceConfig` — Returns a source configuration for notification rule.

- `fromRepositoryArn(scope: Construct, id: string, repositoryArn: string): IRepository` (static) — Imports a codecommit repository.

  **Parameters**

  - `repositoryArn` — (e.g. `arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo`).

- `fromRepositoryName(scope: Construct, id: string, repositoryName: string): IRepository` (static)

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — [disable-awslint:no-grants].

- `grantPull(grantee: IGrantable): Grant` — The use of this method is discouraged. Please use `grants.pull()` instead.

  [disable-awslint:no-grants]

- `grantPullPush(grantee: IGrantable): Grant` — The use of this method is discouraged. Please use `grants.pullPush()` instead.

  [disable-awslint:no-grants]

- `grantRead(grantee: IGrantable): Grant` — The use of this method is discouraged. Please use `grants.read()` instead.

  [disable-awslint:no-grants]

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `notifiyOnPullRequestMerged(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a pull request is merged.

- `notify(arn: string, options?: RepositoryTriggerOptions): Repository // chainable` — Create a trigger to notify another service to run actions on repository events.

  **Parameters**

  - `arn` — Arn of the resource that repository events will notify.
  - `options` — Trigger options to run actions.

- `notifyOn(id: string, target: INotificationRuleTarget, options: RepositoryNotifyOnOptions): INotificationRule` — Defines a CodeStar Notification rule triggered when the project events specified by you are emitted. Similar to `onEvent` API.

  You can also use the methods to define rules for the specific event emitted.
  e.g. `notifyOnPullRequestCreated`.

- `notifyOnApprovalRuleOverridden(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when an approval rule is overridden.

- `notifyOnApprovalStatusChanged(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when an approval status is changed.

- `notifyOnBranchOrTagCreated(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a new branch or tag is created.

- `notifyOnBranchOrTagDeleted(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a branch or tag is deleted.

- `notifyOnPullRequestComment(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a comment is made on a pull request.

- `notifyOnPullRequestCreated(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a pull request is created.

- `notifyOnPullRequestMerged(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Defines a CodeStar Notification rule which triggers when a pull request is merged.

- `onCommentOnCommit(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a comment is made on a commit.

- `onCommentOnPullRequest(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a comment is made on a pull request.

- `onCommit(id: string, options?: OnCommitOptions): Rule` — Defines a CloudWatch event rule which triggers when a commit is pushed to a branch.

- `onEvent(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers for repository events.

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

- `onPullRequestStateChange(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a pull request state is changed.

- `onReferenceCreated(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a reference is created (i.e. a new branch/tag is created) to the repository.

- `onReferenceDeleted(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a reference is delete (i.e. a branch/tag is deleted) from the repository.

- `onReferenceUpdated(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a reference is updated (i.e. a commit is pushed to an existing or new branch) from the repository.

- `onStateChange(id: string, options?: OnEventOptions): Rule` — Defines a CloudWatch event rule which triggers when a "CodeCommit Repository State Change" event occurs.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
