AWS CodeCommit

Site admins can sync Git repositories hosted on AWS CodeCommit with Sourcegraph so that users can search and navigate the repositories.

To connect AWS CodeCommit to Sourcegraph:

  1. Go to Site admin > Manage code hosts > Add repositories
  2. Select AWS CodeCommit repositories.
  3. Configure the connection to AWS CodeCommit using the action buttons above the text field, and additional fields can be added using Cmd/Ctrl+Space for auto-completion. See the configuration documentation below.
  4. Press Add repositories.

AWS CodeCommit Git credentials

Since version 3.4 of Sourcegraph, the AWS CodeCommit service requires Git credentials in order to clone repositories via HTTPS. Git credentials consist of a username and a password that you can create in AWS IAM.

For detailed instructions on how to create the credentials in IAM, see: Setup for HTTPS Users Using Git Credentials

Configuration

AWS CodeCommit connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.

admin/external_service/aws_codecommit.schema.json

{
	// The AWS access key ID to use when listing and updating repositories from AWS CodeCommit. Must have the AWSCodeCommitReadOnly IAM policy.
	"accessKeyID": null,

	// A list of repositories to never mirror from AWS CodeCommit. 
	//
	// Supports excluding by name ({"name": "git-codecommit.us-west-1.amazonaws.com/repo-name"}) or by ARN ({"id": "arn:aws:codecommit:us-west-1:999999999999:name"}).
	"exclude": null,
	// Other example values:
	// - [
	//     {
	//       "name": "go-monorepo"
	//     },
	//     {
	//       "id": "f001337a-3450-46fd-b7d2-650c0EXAMPLE"
	//     }
	//   ]
	// - [
	//     {
	//       "name": "go-monorepo"
	//     },
	//     {
	//       "name": "go-client"
	//     }
	//   ]

	// The Git credentials used for authentication when cloning an AWS CodeCommit repository over HTTPS.
	//
	// See the AWS CodeCommit documentation on Git credentials for CodeCommit: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_ssh-keys.html#git-credentials-code-commit.
	// For detailed instructions on how to create the credentials in IAM, see this page: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html
	"gitCredentials": null,

	// Deprecated and ignored field which will be removed entirely in the next release. AWS CodeCommit repositories can no longer be enabled or disabled explicitly. Configure which repositories should not be mirrored via "exclude" instead.
	"initialRepositoryEnablement": false,

	// The AWS region in which to access AWS CodeCommit. See the list of supported regions at https://docs.aws.amazon.com/codecommit/latest/userguide/regions.html#regions-git.
	"region": "us-east-1",

	// The pattern used to generate a the corresponding Sourcegraph repository name for an AWS CodeCommit repository. In the pattern, the variable "{name}" is replaced with the repository's name.
	//
	// For example, if your Sourcegraph instance is at https://src.example.com, then a repositoryPathPattern of "awsrepos/{name}" would mean that a AWS CodeCommit repository named "myrepo" is available on Sourcegraph at https://src.example.com/awsrepos/myrepo.
	//
	// It is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined.
	"repositoryPathPattern": "{name}",
	// Other example values:
	// - "git-codecommit.us-west-1.amazonaws.com/{name}"
	// - "git-codecommit.eu-central-1.amazonaws.com/{name}"

	// The AWS secret access key (that corresponds to the AWS access key ID set in `accessKeyID`).
	"secretAccessKey": null
}

Setup steps for SSH connections to AWS CodeCommit repositories

To add CodeCommit repositories in Docker Container:

  1. Generate a public/private rsa key pair that does not require passphrase as listed in the Step 3.1 of the AWS SSH setup guide. Sourcegraph does not work withe key pair that requires passphrase.
  2. Follow the rest of the steps detailed in the AWS SSH setup guide to make sure you can connect to the code host locally.
  3. Confirm you have the connection by running the following ssh command locally: ssh git-codecommit.us-west-1.amazonaws.com (Update link with your server region)
  4. Confirm you can clone the repository locally.
  5. Copy all the files at your $HOME/.ssh directory to $HOME/.sourcegraph/config/ssh directory. See docs for more information about our ssh file system.
    1. Read our guide here for Docker Compose deployments
    2. Read our guide here for Kubernetes deployments
  6. Start (or restart) the container.
  7. Connect Sourcegraph to AWS CodeCommit by going to Sourcegraph > Site Admin > Manage code hosts > Generic Git host and add the following:
"url": "ssh://git-codecommit.us-west-1.amazonaws.com", //Please replace the 'us-east-1' region with yours
  "repos": [
    "v1/repos/REPO_NAME_1",
    "v1/repos/REPO_NAME_2",
  ]