LoginSignup
1
1

More than 5 years have passed since last update.

[JAWS-UG CLI] CodeCommit #1 リポジトリの作成

Last updated at Posted at 2016-10-10

AWS CLIを利用して、CodeCommit上にリポジトリを作成してみます。

前提条件

CodeCommitへの権限

CodeCommitに対してフル権限があること。

AWS CLIのバージョン

以下のバージョンで動作確認済

  • AWS CLI 1.11.2
コマンド
aws --version
結果(例)
      aws-cli/1.11.2 Python/2.7.11 Darwin/15.6.0 botocore/1.4.60

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

Gitコマンド

Gitコマンドが利用できること。

0. 準備

0.1. リージョンの決定

構築するリージョンを決めます。 (カレントユーザが利用するカレントリージョンも切り変わります。)

コマンド(バージニアリージョンの場合)
export AWS_DEFAULT_REGION='us-east-1'

注釈: 2016-10-10時点でCodeCommitはus-east-1のみ提供されています。

0.2. 変数の確認

プロファイルが想定のものになっていることを確認します。

コマンド
aws configure list
結果(例)
            Name                    Value             Type    Location
            ----                    -----             ----    --------
         profile         administrator-prjz-mbp13        env    AWS_DEFAULT_PROFILE
      access_key     ****************XXXX shared-credentials-file
      secret_key     ****************XXXX shared-credentials-file
          region                         us-east-1  env    AWS_DEFAULT_REGION

AssumeRoleを利用している場合はprofileが ''と表示されます。 それ以外のときにprofileが '' と表示される場合は、以下を実行してください。

bash変数の設定
         export AWS_DEFAULT_PROFILE=<IAMユーザ名>

0.3. 環境設定 (Git)

コミットログに記録されるユーザ名とメールアドレスを決定します。

変数の設定
GIT_EMAIL="taro@example.com"

ユーザ名とメールアドレスをgitに設定します。

変数の確認
cat << ETX

        USER:      ${USER}
        GIT_EMAIL: ${GIT_EMAIL}

ETX
コマンド
git config --global user.name "${USER}"
      git config --global user.email "${GIT_EMAIL}"

設定を確認します。

コマンド
git config --get user.name
結果(例)
      taro
コマンド
git config --get user.email
結果(例)
      taro@example.com

1. 事前作業

1.1. リポジトリ名の決定

変数の設定
CODEC_REPOSITORY_NAME="handson-$(date +%Y%m%d)" \
        && echo ${CODEC_REPOSITORY_NAME}

同名のリポジトリが存在しないことを確認します。

コマンド
aws codecommit get-repository \
        --repository-name ${CODEC_REPOSITORY_NAME}
結果(例)
      An error occurred (RepositoryDoesNotExistException) when calling the GetRepository operation: handson-20161010does not exist

1.2. リポジトリの詳細

変数の設定
CODEC_REPOSITORY_DESC="hands on repository on 20161010"   && echo ${CODEC_REPOSITORY_DESC}

2. リポジトリの作成

変数の確認
cat << ETX

        CODEC_REPOSITORY_NAME:  ${CODEC_REPOSITORY_NAME}
        CODEC_REPOSITORY_DESC: "${CODEC_REPOSITORY_DESC}"

ETX
コマンド
aws codecommit create-repository \
        --repository-name ${CODEC_REPOSITORY_NAME} \
        --repository-description "${CODEC_REPOSITORY_DESC}"
結果(例)
      {
        "repositoryMetadata": {
          "repositoryName": "handson-20161010",
          "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/handson-20161010",
          "lastModifiedDate": 1234567890.123,
          "repositoryDescription": "hands on repository on 20161010",
          "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/handson-20161010",
          "creationDate": 1234567890.123,
          "repositoryId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "Arn": "arn:aws:codecommit:us-east-1:XXXXXXXXXXXX:handson-20161010",
          "accountId": "XXXXXXXXXXXX"
        }
      }

3. 事後作業

3.1. リポジトリの確認

コマンド
aws codecommit get-repository \
        --repository-name ${CODEC_REPOSITORY_NAME}
結果(例)
      {
        "repositoryMetadata": {
          "repositoryName": "handson-20161010",
          "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/handson-20161010",
          "lastModifiedDate": 1234567890.123,
          "repositoryDescription": "hands on repository on 20161010",
          "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/handson-20161010",
          "creationDate": 1234567890.123,
          "repositoryId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "Arn": "arn:aws:codecommit:us-east-1:XXXXXXXXXXXX:handson-20161010",
          "accountId": "XXXXXXXXXXXX"
        }
      }

3.2. エンドポイントの取得

コマンド
CCODE_CLONE_URL=$( \
        aws codecommit get-repository \
        --repository-name ${CODEC_REPOSITORY_NAME} \
        --query 'repositoryMetadata.cloneUrlSsh' \
        --output text \
      ) \
        && echo ${CCODE_CLONE_URL}
結果(例)
      ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/handson-20161010

3.3. ローカルへのクローン

コマンド
mkdir -p ~/tmp/
cd ~/tmp/
コマンド
git clone ${CCODE_CLONE_URL}
結果(例)
      Cloning into 'handson-20161010'...
      warning: You appear to have cloned an empty repository.
      Checking connectivity... done.
コマンド
ls -a handson-20161008/
結果(例)
      .   ..      .git

完了

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1