俺のアウトプット

調べたこと、試したことを書きます

AWS Cloud9とCodeCommitを統合する

AWS Cloud9 内から AWS CodeCommit リポジトリでコード管理を行うことができます。

AWS Cloud9 EC2環境を起動します。
AWS CodeCommitリポジトリは事前に用意しておいてください。

AWS Cloud9 EC2環境の構築は、下記エントリを参照してください。

AWS CodeCommitの前準備は、下記エントリを参照してください。

Gitの設定

AWS Cloud9内のターミナルウィンドウから、gitがインストールされていることを確認します。

$ git --version
git version 2.14.4

git configコマンドで、Gitコミットと関連付けるユーザー名メールアドレスを設定します。

$ git config --global user.name "Hoge Fuga"
$ git config --global user.email hoge-fuga@example.com

AWS CLIの認証情報ヘルパー設定

ターミナルウィンドウから、下記のコマンドを入力し、HTTPS接続用のAWS CLIの認証情報ヘルパーを設定します。
認証ヘルパーを設定すると、毎回ユーザーとパスワードを入力する手間がなくなります。

$ git config --global credential.helper '!aws codecommit credential-helper $@'
$ git config --global credential.UseHttpPath true

設定した値は、git config -l で確認できます。

$ git config -l
core.editor=/usr/bin/nano
user.name=Hoge Fuga
user.email=hoge-fuga@example.com
credential.helper=!aws codecommit credential-helper $@
credential.usehttppath=true

CodeCommitリポジトリの作成

リポジトリを作成します。

$ aws codecommit create-repository --repository-name SampleRepo
{
    "repositoryMetadata": {
        "repositoryName": "SampleRepo", 
        "cloneUrlSsh": "ssh://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/SampleRepo", 
        "lastModifiedDate": 1536974158.19, 
        "repositoryId": "905607e6-13f3-4a0e-698b-b1d0c6bd6146", 
        "cloneUrlHttp": "https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/SampleRepo", 
        "creationDate": 1536974158.19, 
        "Arn": "arn:aws:codecommit:ap-southeast-1:123456789012:SampleRepo", 
        "accountId": "123456789012"
    }
}

Cloud9を起動したリージョン上にリポジトリが作成されます。

別のリージョンに作成する場合は、--regionオプションを指定します。

$ aws codecommit create-repository --repository-name SampleRepo --region ap-northeast-1

CodeCommitリポジトリのクローンを作成

ターミナルウィンドウから、git cloneコマンドを実行します。

$ git clone https://git-codecommit.<リージョン>.amazonaws.com/v1/repos/<リポジトリ名>

URLは、 CodeCommitのダッシュボードのURL列のアイコンから HTTPS を選択することでコピーできます。

f:id:kitsugi:20180915095453p:plain

参考