This small solution can help you to leverge your existing CI/CD pipeline in your AWS account and the same time use Gitlab as your main source code repository. You can choose to mirror your repository to an existing empty AWS CodeCommit repository or you can create a new one automatically.
- Since all the resources are created using CloudFormation, it's easy to remove it. (Note: by default it will also delete the AWS CodeCommit repository upon deletion if it was created by the stack)
- The user has minimal privilige. It's only allowed to push and pull from the target repository. Nothing more.
- The user will not have any AWS Access keys.
- Login to AWS console in the account where you want to mirror your Gitlab repository.
- Go to CloudFormation. Make sure you are in the same region as the AWS CodeCommit repository
- Download ./template.yaml
Then create a new CloudFormation stack using the downloaded file.
- Choose an IAM user name that will be created for you with minimal priviliges
- Select if you want to create a new AWS CodeCommit repository.
- Type in the name of the existing or new (based on previous step) repository that will be used for mirroring. If you use an existing repository, the repository itself must be empty
- Once the stack is created, navigate to the CloudFormation stack
Outputs
- Open the link in a new window next to
IAMUserDetails
(this will open up the IAM user's details, security credentials tab) Right tab:Right section:
Generate Credentials:
- Click on
HTTPS Git credentials for AWS CodeCommit -> Generate credentials
for the IAM user and leave the modal open. You will need the password later - In a new window, open up your Gitlab repository and navigate to
Settings -> Repository
- In Gitlab, expand the
Mirroring repositories
section and fill it out the following way:- Git repository URL should be the
GitRepositoryURL
from the outputs of your CloudFormation file - Mirror direction:
Push
- orPull
if that option is available/desired - Authentication method:
Password
- Password: Insert the password in from step 6. (If you need to regenerate the password, you will need to remove the old one first OR change the username, aka the text before the @ characheter, in the Git repository URL according the new username)
- Git repository URL should be the
- Once added, click on the Refresh/Update now button next to the name of the repository.
If you like this solution, please, click on the star.
If you have any issues or you found a bug, you can create a new Issue in Gitlab.
If you want to submit improvements, feel free to send in a Merge Request.