profile picture

@clementvial

I'm a full Stack JavaScript developer from Canada ðŸ‡¨ðŸ‡¦ Building with TypeScript, React, AI/ML & more.

Check out my links and posts

Migrating CDK Pipelines from CodeCommit to GitHub

AWS closed new customer access to CodeCommit on July 25, 2024. Time to migrate your CDK Pipelines to GitHub. Good news: it’s straightforward and you don’t need to rebuild everything.

First, push your code to GitHub:

# Add GitHub as a new remote
git remote add github https://github.com/your-username/your-repo.git
# Push everything to GitHub
git push github --all && git push github --tags

Create a GitHub personal access token (Settings > Developer settings) with repo scope and store it in AWS Secrets Manager as github-token.

Now swap the source in your CDK code:

pipeline-stack.ts
import { CodePipeline, CodePipelineSource } from 'aws-cdk-lib/pipelines';
import { Repository } from 'aws-cdk-lib/aws-codecommit';
const codeCommitRepository = Repository.fromRepositoryName(this, 'my-codecommit-repo-id', 'my-codecommit-repo-name');
const pipeline = new CodePipeline(this, 'Pipeline', {
pipelineName: 'my-pipeline',
synth: new ShellStep('Synth', {
// Replace CodeCommit source with GitHub
input: CodePipelineSource.codeCommit(codeCommitRepository, 'main'),
input: CodePipelineSource.gitHub('your-username/your-repo', 'main'),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});

Deploy through CodeCommit one last time, then switch remotes:

# Commit and push the changes to CodeCommit
git add .
git commit -m "chore: migrate pipeline source to GitHub"
git push origin main
# Push to GitHub to ensure both repos are in sync
git push github main
# Switch GitHub to be primary remote, but keep CodeCommit as backup
git remote rename origin codecommit-backup
git remote rename github origin
# After validating the pipeline works with GitHub, you can remove the old remote
# git remote remove codecommit-backup

CodePipeline handles the transition without recreating anything. Your deployment history stays intact 🎉.