AWS에도 Github이나 Bitbucket과 같이 GIT Repository가 존재한다.
AWS에 Code가 존재한다면 CI 구성할때에 속도나 보안문제에 매우 유리할 수가 있다.
Github에서 CodeCommit으로 마이그레이션을 하기 위해서는 다음의 절차로 진행한다.
이 문서에서 CodeCommit으로 옮길 샘플 Repository
https://github.com/harryoh/lambda_weather
CodeCommit Service로 이동
[Create Repository] 선택
옮길 Repository와 동일하게 Repository name에 lambda_weather 입력
생성된 Repository의 URL을 복사
https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather
생성된 Repository의 [Settings]에서 ARN을 복사
arn:aws:codecommit:ap-northeast-2:000000000000:lambda_weather
[Security credentials] 탭으로 이동HTTPS Git credentials for AWS CodeCommit 항목에서 [Generate] 선택CodeCommit에 생성한 Repository를 생성한다. 다운받은 Credentials의 ID와 Password를 입력한다.
$ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather
username:
password:
warning: You appear to have cloned an empty repository.
Repository에 github를 remote branch로 등록하여 fetch하고 소스를 CodeCommit로 push한다.
$ cd lambda_weather
$ git remote add github https://github.com/harryoh/lambda_weather
$ git remote -v
github https://github.com/harryoh/lambda_weather (fetch)
github https://github.com/harryoh/lambda_weather (push)
origin https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather (fetch)
origin https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather (push)
$ git fetch github
$ git merge github/master --ff-only
$ git push origin master
Counting objects: 10, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 5.63 KiB | 2.82 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0)
To https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather
* [new branch] master -> master
IAM - Policies으로 이동후 [Create Policy] 선택
[Create Your Own Policy] 선택
Policy Name에 CUSTOM_Developer 입력
Policy Document에 다음을 입력후 [Create Policy] 선택
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:List*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"codecommit:BatchGetRepositories",
"codecommit:CreateBranch",
"codecommit:DeleteBranch",
"codecommit:Get*",
"codecommit:GitPull",
"codecommit:GitPush",
"codecommit:Put*",
"codecommit:Test*",
"codecommit:Update*"
],
"Resource": [
"arn:aws:codecommit:ap-northeast-2:880169174736:lambda_weather"
]
}
]
}
CUSTOM_Viewer Policy를 하나 더 추가
다음을 입력후 [Create Policy] 선택
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:List*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"codecommit:BatchGetRepositories",
"codecommit:Get*",
"codecommit:GitPull"
],
"Resource": [
"arn:aws:codecommit:ap-northeast-2:880169174736:lambda_weather"
]
}
]
}
확인
IAM - Groups 에서 [Create New Groups] 선택
Group Name에 MyTeam 입력 후 [Next Step] 선택
Attach Policy에서 다음의 Policy를 추가후 [Next Step] 선택
Review에서 확인 후에 [Create Group] 선택
MyTeam Group과 다음의 Policy를 선택하여 YourTeam Group을 생성
IAM - Users 에서 [Add user] 선택
User name을 입력하고 AWS Management Console access에 체크하여 `[Next: Permissions]' 선택 (다른 항목은 적절하게 선택)
Set permissions 에서 Add user to group 탭에서 MyTeam 체크후 [Next: Review] 선택
Review에서 확인 후에 [Create user] 선택
위와 동일한 방법으로 YourTeam을 Group에 추가하여 새로운 사용자를 추가로 만든다.
Security credentials 탭에서 HTTPS Git credentials for AWS CodeCommit 항목의 [Generate] 선택MacOS 사용자의 경우에는 Keychain Access 에서 Git 관련 정보를 삭제
Git 인증 캐쉬 삭제
git config --global --unset credential.helper
YourTeam Group은 Repository를 Clone 할 수는 있어도 Push는 불가
$ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather lambda_weather_sally
Cloning into 'lambda_weather_sally'...
Username:
Password:
remote: Counting objects: 10, done.
Unpacking objects: 100% (10/10), done.
$ cd lambda_weather_sally
$ echo "test" | cat > test
$ git add test
$ git commit -m "test commit"
$ git push origin master
fatal: unable to access 'https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather/': The requested URL returned error: 403
MyTeam Group은 Push가 가능. (테스트시 Git Credential 초기화 필요)
$ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather lambda_weather_harry
Cloning into 'lambda_weather_harry'...
Username:
Password:
remote: Counting objects: 10, done.
Unpacking objects: 100% (10/10), done.
$ cd lambda_weather_harry
$ echo "test" | cat > test
$ git add test
$ git commit -m "test commit"
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 258 bytes | 258.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/lambda_weather
6c7bfc1..00f986f master -> master
CodeCommit에서는 Pull Request를 지원하지 않아서 EC2에 Review 시스템을 설치해서 사용하거나 외부 서비스를 사용해야함.
참고