Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active March 8, 2021 03:00
Show Gist options
  • Save rpivo/620c0629c0fffa162ac4aad60e2746f4 to your computer and use it in GitHub Desktop.
Save rpivo/620c0629c0fffa162ac4aad60e2746f4 to your computer and use it in GitHub Desktop.
Creating a GitHub Action That Forwards Commits to an AWS CodeCommit Repo

Creating a GitHub Action That Forwards Commits to an AWS CodeCommit Repo

You can use pixta-dev's repository-mirroring-action to forward commits to an AWS CodeCommit repo.

  1. You'll first need to create an AWS CodeCommit repo.
  2. You'll need to generate an SSH key pair (or have one ready to use).
  3. There is a section called SSH Keys for AWS CodeCommit inside the AWS IAM dashboard. Here, you'll upload the public portion of the SSH key pair.
  4. Copy the SSH Key ID that gets generated in the AWS IAM dashboard after you've uploaded the SSH public key.
  5. In the repo where the GitHub Action will be active, create a secret called CODECOMMIT_SSH_PRIVATE_KEY_ID. Paste in the SSH Key ID as the value of this secret and save it.
  6. Get the SSH URL of the CodeCommit repo. You can get this from the main CodeCommit dashboard where you see all your repos. This is the SSH URL that you would use to clone the repo via SSH.
  7. Create another secret inside the GitHub repo called CODECOMMIT_SSH_URL and set it equal to this SSH URL.
  8. Copy the private portion of the SSH key. Create another secret inside the GitHub repo called CODECOMMIT_SSH_PRIVATE_KEY and paste the private key as the value of this secret.
  9. Create a folder path .github/workflows/main.yml inside the repo. Inside main.yml paste the code below.
name: CodeCommit Mirror
on: [push, delete]
jobs:
  to_codecommit:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - uses: pixta-dev/repository-mirroring-action@v1
        with:
          target_repo_url: ${{ secrets.CODECOMMIT_SSH_URL }}
          ssh_private_key: ${{ secrets.CODECOMMIT_SSH_PRIVATE_KEY }}
          ssh_username: ${{ secrets.CODECOMMIT_SSH_PRIVATE_KEY_ID }}

After you push this code, the GitHub Action should now work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment