This section explains the procedure for synchronizing a workspace in Bitbucket to codecommit. This allows each new repository to be automatically synchronized using a global SSH key provided to the Bitbucket workspace and the pipeline corresponding to the synchronization. (This procedure assumes you have a codecommit repository already created)
- SSH key without passphrase
ssh-keygen -t rsa -f ~/.ssh/[KEY-NAME] -C [USER-NAME] -N ''
e.g.
ssh-keygen -t rsa -f ~/.ssh/codecommit_rsa -C myUserCodeCommit -N ''
Upload the ssh key generated in the previous step into the AWS user credentials section.
- Go to the AWS console and click "Upload SSH Public Key" in the "SSH Keys for AWS CodeCommit" section. Paste, accept.
- copy the SSH key ID
Create a configuration file in ~/.ssh/
- config file
Host git-codecommit.*.amazonaws.com
User APKAQWUUSDIVPDEW3DRH <-- AWS SSH Key ID
IdentityFile ~/.ssh/codecommit_rsa
- Environment variables in the Bitbucket workspace (take into account that the config and key variables must be encoded in base64)
base64 ~/.ssh/config
base64 ~/.ssh/codecommit_rsa
Define the workspace global variables to be use for all the new repositories
Now, we will create the bitbucket-pipelines.yml
file, add it with your favorite editor to your project root (repository) or click "Configure bitbucket-pipelines.yml" and modify it directly at http://bitbucket.org.
pipelines:
default:
- step:
script:
- echo $CodeCommitKey > ~/.ssh/codecommit_rsa.tmp
- base64 -di ~/.ssh/codecommit_rsa.tmp > ~/.ssh/codecommit_rsa
- chmod 400 ~/.ssh/codecommit_rsa
- echo $CodeCommitConfig > ~/.ssh/config.tmp
- base64 -di ~/.ssh/config.tmp > ~/.ssh/config
- chmod 600 ~/.ssh/config
- cat ~/.ssh/config
- set +e
- ssh -o StrictHostKeyChecking=no $CodeCommitHost
- set -e
- git remote add codecommit [AQUI SSH URL REPOSITORIO EN CODECOMMIT]
- git push codecommit $BITBUCKET_BRANCH