Create IAM user and generate Git credential
Create access access-user-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:GitPull",
"codecommit:GitPush"
],
"Resource": [
"arn:aws:codecommit:ap-northeast-1:{ACCOUNT ID}:{REPOSITORY NAME}"
]
}
]
}
At AWS CLI, run those commands
POLICY={POLICY NAME}
USER={USER NAME}
ACCOUNT={ACCOUNT ID}
aws iam create-policy \
--policy-name $POLICY \
--policy-document file://access-user-policy.json
aws iam create-user --user-name $USER
aws iam attach-user-policy \
--user-name $USER \
--policy-arn arn:aws:iam::$ACCOUNT:policy/$POLICY
aws iam create-service-specific-credential \
--user-name $USER \
--service-name codecommit.amazonaws.com
Memorize Git credential
Memorize the outputs from previous executions
{
"ServiceSpecificCredential": {
"CreateDate": "2023-01-11T07:08:45+00:00",
"ServiceName": "codecommit.amazonaws.com",
"ServiceUserName": "{USER NAME}-at-{ACCOUNT ID}",
"ServicePassword": "xxxxxxxxxxxx",
"ServiceSpecificCredentialId": "XXXXXXXXXXXXX",
"UserName": "{USER NAME}",
"Status": "Active"
}
}
Create CodeCommit repository
- At AWS CLI, run those commands
aws codecommit create-repository --repository-name {CODECOMMIT REPOSITORY NAME}
- At CodeCommit repository, go to Clone URL > Clone HTTPS
- Memorize the URL for later use
https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/{REPOSITORY NAME}
- Memorize the URL for later use
https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/{REPOSITORY NAME}
Set up GitLab push mirroring
- At your GitLab project, go to Settings > Repository
- Expand Mirroring repositories
- Modify the URL with ServiceUserName from previous sections and put it on Git repository URL
https://{ServiceUserName}@git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/{REPOSITORY NAME}
- Mirror direction: Push
- Authentication method: Password
- Password: ServicePassword from the previous section
- Mirror repository
- After successful mirroring, run Update now
Check CodeCommit repository
- Wait a while, and you will see the CodeCommit repository has the mirrored code from the GitLab
No comments:
Post a Comment