AWS CDK Construct Library for CodeCommit
The `aws-cdk-aws-codecommit` library provides AWS Cloud Development Kit (CDK) constructs for defining AWS CodeCommit resources programmatically using Python. It allows developers to create, configure, and manage CodeCommit repositories as part of their infrastructure-as-code deployments. This entry specifically covers version 1.204.0, which is part of the AWS CDK v1 ecosystem. AWS CDK typically follows a rapid release cadence, often with weekly updates for bug fixes and new feature support.
Common errors
-
ModuleNotFoundError: No module named 'aws_cdk.core'
cause The core AWS CDK library, `aws-cdk.core`, is not installed or available in the Python environment.fixEnsure `aws-cdk.core` is installed: `pip install aws-cdk.core`. -
AttributeError: module 'aws_cdk.aws_codecommit' has no attribute 'Repository'
cause This typically occurs when trying to use the CDK v2 import style (`from aws_cdk.aws_codecommit import Repository`) with a CDK v1 package (`aws-cdk-aws-codecommit`).fixFor CDK v1, use `from aws_cdk import aws_codecommit as codecommit` and then refer to the class as `codecommit.Repository`. -
jsii.errors.JavaScriptError: repositoryName must be specified. (Service: CodeCommit, Status Code: 400, Request ID: ...)
cause The `repository_name` property is a required parameter when defining a `codecommit.Repository` construct.fixEnsure you provide a `repository_name` when instantiating `codecommit.Repository`: `codecommit.Repository(self, 'MyRepo', repository_name='my-unique-repo-name')`. -
Error: Resolution error: Resolution error: No default region is configured. Please configure a default region.
cause The CDK application or CLI cannot determine which AWS region to deploy to. This often happens if `CDK_DEFAULT_REGION` is not set or AWS CLI is not configured.fixConfigure your AWS environment: `export CDK_DEFAULT_REGION=us-east-1` (or your desired region) and `export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query 'Account' --output text)`.
Warnings
- breaking This package (`aws-cdk-aws-codecommit==1.204.0`) is part of AWS CDK v1. AWS CDK v2 is the current major version, which introduces significant breaking changes, especially in import paths (`aws-cdk.core` is replaced by `aws_cdk.lib`) and module structure. Code written for v1 is not directly compatible with v2.
- gotcha CDK applications require the AWS CDK Toolkit (CLI) to be installed globally via Node.js (`npm install -g aws-cdk`). Without it, commands like `cdk synth` or `cdk deploy` will fail.
- gotcha The `repository_name` property for a CodeCommit repository must be unique within an AWS account and region. Attempting to deploy a stack with a duplicate repository name will result in a deployment failure.
- gotcha CDK v1 requires an explicit `from aws_cdk import core as cdk` or similar alias for core components like `App` and `Stack`. Many examples on the web for CDK v2 might show `from aws_cdk import App, Stack`, which will not work with v1.
Install
-
pip install aws-cdk-aws-codecommit aws-cdk.core -
npm install -g aws-cdk
Imports
- Repository
from aws_cdk.aws_codecommit import Repository
from aws_cdk import aws_codecommit as codecommit # then: codecommit.Repository(...)
- App
from aws_cdk import App
from aws_cdk import core as cdk # then: cdk.App()
Quickstart
import os
from aws_cdk import (
core as cdk,
aws_codecommit as codecommit
)
class CodeCommitStack(cdk.Stack):
def __init__(self, scope: cdk.App, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# Create a new CodeCommit repository
repo = codecommit.Repository(
self, "MyCodeCommitRepo",
repository_name="my-application-repo"
)
# Output the repository clone URL for convenience
cdk.CfnOutput(
self, "RepositoryCloneUrlHttp",
value=repo.repository_clone_url_http,
description="HTTP URL to clone the CodeCommit repository"
)
app = cdk.App()
CodeCommitStack(
app, "CodeCommitQuickstartStack",
env=cdk.Environment(
account=os.environ.get("CDK_DEFAULT_ACCOUNT", ""),
region=os.environ.get("CDK_DEFAULT_REGION", "us-east-1")
)
)
app.synth()