Namespace Amazon.CDK.AWS.CodeCommit
AWS CodeCommit Construct Library
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:
var repo = new Repository(this, "Repository", new RepositoryProps {
RepositoryName = "MyRepositoryName",
Description = "Some description."
});
Use the repositoryCloneUrlHttp
, repositoryCloneUrlSsh
or repositoryCloneUrlGrc
property to clone your repository.
To add an Amazon SNS trigger to your repository:
Repository repo;
// trigger is established for all repository actions on all branches by default.
repo.Notify("arn:aws:sns:*:123456789012:my_topic");
Add initial commit
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:
var repo = new Repository(this, "Repository", new RepositoryProps {
RepositoryName = "MyRepositoryName",
Code = Code.FromDirectory(Join(__dirname, "directory/"), "develop")
});
Use a customer managed key
CodeCommit repositories are automatically encrypted with an AWS managed key. To use
a customer managed key, specify the kmsKey
property.
For more information, see AWS Key Management Service and encryption for AWS CodeCommit repositories.
using Amazon.CDK.AWS.KMS;
IKey kmsKey;
var repo = new Repository(this, "Repository", new RepositoryProps {
RepositoryName = "MyRepositoryName",
KmsKey = kmsKey
});
Events
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:
using Amazon.CDK.AWS.SNS;
using Amazon.CDK.AWS.Events.Targets;
Repository repo;
PipelineProject project;
Topic myTopic;
// starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.OnCommit("CommitToMain", new OnCommitOptions {
Target = new CodeBuildProject(project),
Branches = new [] { "main" }
});
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
var rule = repo.OnCommentOnPullRequest("CommentOnPullRequest", new OnEventOptions {
Target = new SnsTopic(myTopic)
});
CodeStar Notifications
To define CodeStar Notification rules for Repositories, use one of the notifyOnXxx()
methods.
They are very similar to onXxx()
methods for CloudWatch events:
using Amazon.CDK.AWS.Chatbot;
Repository repository;
var target = new SlackChannelConfiguration(this, "MySlackChannel", new SlackChannelConfigurationProps {
SlackChannelConfigurationName = "YOUR_CHANNEL_NAME",
SlackWorkspaceId = "YOUR_SLACK_WORKSPACE_ID",
SlackChannelId = "YOUR_SLACK_CHANNEL_ID"
});
var rule = repository.NotifyOnPullRequestCreated("NotifyOnPullRequestCreated", target);
Classes
CfnRepository | Creates a new, empty repository. |
CfnRepository.CodeProperty | Information about code to be committed. |
CfnRepository.RepositoryTriggerProperty | Information about a trigger for a repository. |
CfnRepository.S3Property | Information about the Amazon S3 bucket that contains the code that will be committed to the new repository. |
CfnRepositoryProps | Properties for defining a |
Code | Represents the contents to initialize the repository with. |
CodeConfig | Represents the structure to pass into the underlying CfnRepository class. |
OnCommitOptions | Options for the onCommit() method. |
ReferenceEvent | Fields of CloudWatch Events that change references. |
Repository | Provides a CodeCommit Repository. |
RepositoryEventTrigger | Repository events that will cause the trigger to run actions in another service. |
RepositoryNotificationEvents | List of event types for AWS CodeCommit. |
RepositoryNotifyOnOptions | Additional options to pass to the notification rule. |
RepositoryProps | |
RepositoryTriggerOptions | Creates for a repository trigger to an SNS topic or Lambda function. |
Interfaces
CfnRepository.ICodeProperty | Information about code to be committed. |
CfnRepository.IRepositoryTriggerProperty | Information about a trigger for a repository. |
CfnRepository.IS3Property | Information about the Amazon S3 bucket that contains the code that will be committed to the new repository. |
ICfnRepositoryProps | Properties for defining a |
ICodeConfig | Represents the structure to pass into the underlying CfnRepository class. |
IOnCommitOptions | Options for the onCommit() method. |
IRepository | |
IRepositoryNotifyOnOptions | Additional options to pass to the notification rule. |
IRepositoryProps | |
IRepositoryTriggerOptions | Creates for a repository trigger to an SNS topic or Lambda function. |