AWS CodeCommit is a version control service that enables you to privately store and manage Git repositories in the AWS cloud.
To add a AWS CodeCommit Repository to your AWS CDK stack please do the following:
Open NorthwindCdk.sln
in Visual Studio.
Add Amazon.CDK.AWS.CodeCommit
Nuget package to the project:
Open NorthwindCdkStack.cs
.
Add following using statement:
using Amazon.CDK.AWS.CodeCommit;
Please add the following changes at the end of NorthwindCdkStack constructor:
namespace NorthwindCdk
{
public class NorthwindCdkStack : Stack
{
internal NorthwindCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
.......
// CodeCommit
var codeRepository = new Repository(this, "NorthwindCodeRepository", new RepositoryProps
{
RepositoryName = "Northwind",
Description = "Northwind code repository"
});
new CfnOutput(this, "CodeRepository", new CfnOutputProps
{
Value = codeRepository.RepositoryCloneUrlHttp
});
}
}
}
The code above creates new AWS CodeCommit repository and outputs it’s HTTP url.
Save changes and compile the project.
Run cdk diff
to take a look at the changes that are going to be deployed.
cdk diff
The output should look like this:
Stack NorthwindCdkStack
Resources
[+] AWS::CodeCommit::Repository NorthwindCodeRepository NorthwindCodeRepository9CDB75DD
Outputs
[+] Output CodeRepository CodeRepository: {"Value":{"Fn::GetAtt":["NorthwindCodeRepository9CDB75DD","CloneUrlHttp"]}}
Next deploy the updates using cdk deploy
command.
cdk deploy
The output should look like this:
NorthwindCdkStack: deploying...
NorthwindCdkStack: creating CloudFormation changeset...
0/3 | 10:14:54 AM | CREATE_IN_PROGRESS | AWS::CodeCommit::Repository | NorthwindCodeRepository (NorthwindCodeRepository9CDB75DD)
✅ NorthwindCdkStack
Outputs:
NorthwindCdkStack.CodeRepository = https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/Northwind
NorthwindCdkStack.PostgreSQLEndpointAddress = northwind-postgresql.cluster-cyhlwzws5aoz.eu-west-1.rds.amazonaws.com
Stack ARN:
arn:aws:cloudformation:eu-west-1:404486542784:stack/NorthwindCdkStack/f78fb1c0-8ed1-11ea-8a83-0a0af0d573f8
Please note code repository URL from the stack output above https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/Northwind
. You will need it later to configure remote repository.