14 types
AWS CodeCommit is a version control service that enables you to privately store and manage Git repositories in the AWS cloud.
For further information on CodeCommit, see the AWS CodeCommit documentation.
To add a CodeCommit Repository to your stack:
repo = AWSCDK::Codecommit::Repository.new(self, "Repository", {
repository_name: "MyRepositoryName",
description: "Some description.",
})
Use the repository_clone_url_http, repository_clone_url_ssh or repository_clone_url_grc
property to clone your repository.
To add an Amazon SNS trigger to your repository:
repo = nil # AWSCDK::Codecommit::Repository
# trigger is established for all repository actions on all branches by default.
repo.notify("arn:aws:sns:*:123456789012:my_topic")
It is possible to initialize the Repository via the Code class.
It provides methods for loading code from a directory, .zip file and from a pre-created CDK Asset.
Example:
repo = AWSCDK::Codecommit::Repository.new(self, "Repository", {
repository_name: "MyRepositoryName",
code: AWSCDK::Codecommit::Code.from_directory(path.join(__dirname, "directory/"), "develop"),
})
CodeCommit repositories are automatically encrypted with an AWS managed key. To use
a customer managed key, specify the kms_key property.
For more information, see AWS Key Management Service and encryption for AWS CodeCommit repositories.
require 'aws-cdk-lib'
kms_key = nil # AWSCDK::KMS::IKey
repo = AWSCDK::Codecommit::Repository.new(self, "Repository", {
repository_name: "MyRepositoryName",
kms_key: kms_key,
})
CodeCommit repositories emit Amazon CloudWatch events for certain activities.
Use the repo.onXxx methods to define rules that trigger on these events
and invoke targets as a result:
require 'aws-cdk-lib'
repo = nil # AWSCDK::Codecommit::Repository
project = nil # AWSCDK::CodeBuild::PipelineProject
my_topic = nil # AWSCDK::SNS::Topic
# starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.on_commit("CommitToMain", {
target: AWSCDK::EventsTargets::CodeBuildProject.new(project),
branches: ["main"],
})
# publishes a message to an Amazon SNS topic when a comment is made on a pull request
rule = repo.on_comment_on_pull_request("CommentOnPullRequest", {
target: AWSCDK::EventsTargets::SNSTopic.new(my_topic),
})
To define CodeStar Notification rules for Repositories, use one of the notify_on_xxx() methods.
They are very similar to on_xxx() methods for CloudWatch events:
require 'aws-cdk-lib'
repository = nil # AWSCDK::Codecommit::Repository
target = AWSCDK::Chatbot::SlackChannelConfiguration.new(self, "MySlackChannel", {
slack_channel_configuration_name: "YOUR_CHANNEL_NAME",
slack_workspace_id: "YOUR_SLACK_WORKSPACE_ID",
slack_channel_id: "YOUR_SLACK_CHANNEL_ID",
})
rule = repository.notify_on_pull_request_created("NotifyOnPullRequestCreated", target)