LoginSignup
0
2

More than 3 years have passed since last update.

AWS CodeCommitをCloud9で使用する

Last updated at Posted at 2020-10-20

AWS Cloud9からCodeCommitを使用する手順を紹介します。
CodeCommitはsshではなくhttps接続を使用します。https接続だと、当然ですが公開鍵の生成、登録が必要ありませんので、設定はその分容易です。
前提条件としてIAMユーザーに「AWSCodeCommitFullAccess」が割り当てられているものとします。

1. CodeCommit上でリポジトリの作成

・「リポジトリを作成」からリモートリポジトリを作成
・リポジトリ名を指定して「作成」
rp1.PNG
これでAWS CodeCommit上にリポジトリが作成されました。

2. Git認証情報の作成

・IAM ダッシュボード→ユーザー→該当ユーザーを選択
・認証情報タブの「AWS CodeCommit の HTTPS Git 認証情報」で「認証情報を生成」
 rp2.PNG

Git認証用のユーザー名とパスワードを控えておきます。証明書をダウンロードするとこれらの情報が記載されたCSVファイルがダウンロードされます。

3. Cloud9上での設定

3-1. ローカルリポジトリの作成

$ git init
Initialized empty Git repository in /home/ec2-user/environment/.git/

3-2. ユーザー設定

「USER_NAME」に「ユーザー名」を指定
「USER_EMAIL」に「メールアドレス」を指定

$ git config --global user.name USER_NAME
$ git config --global user.email USER_EMAIL

3-3A. リモートリポジトリの追加

https以下URLはレポジトリの一覧からhttpsのボタンを押すとコピーされます。

$ git remote add origin https://git-codecommit.us-west-2.amazonaws.com/v1/repos/tst

3-3B. クローンを作成を作成する場合

ディレクトリが作成されてクローンが作成されるのでカレントディレクトリに注意

$ git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/tst
Cloning into 'tst'...
warning: You appear to have cloned an empty repository.

3-4A. ステージに追加(ファイル指定)

$ git add run.py

3-4B. ステージに追加(カレントフォルダ以下すべて)

$ git add .

3-5. Commitからpush

$ git commit -m "first commit"
[master (root-commit) 877da2a] first commit
 1 file changed, 6 insertions(+)
 create mode 100644 run.py

$ git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 322 bytes | 322.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://git-codecommit.us-west-2.amazonaws.com/v1/repos/tst
 * [new branch]      master -> master

4. Source Tree の使用

ファイル → 新規 → クローンの作成
URLにレポジトリのURL(3-3A)、保存パスの位置、名前を入力します。
IDとパスワードを聞かれますので、Git認証情報(2)で取得したものを設定します。

以上

0
2
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
0
2