1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS Cloud9とCodeCommitを連携させてみた

Last updated at Posted at 2020-12-10

AWS Cloud9が立ち上がったので(前回)、次は、Cloud9とCodeCommitを連携させましょう。
なお、今回、Cloud9はEC2のAmazonLinux2で動かしてます。

CodeCommitとは、AWSマネージドのコード管理サービスです。gitのコマンドが使えます。

CodeCommitリポジトリを作ろう

codecommit-initpage.png.jpg

リポジトリを作成をクリックします

create-repo.png

今回、LambdaとCodePipelineでつないでCI/CD環境を作っていくのを目指しているので、lambda-testという名前のリポジトリを作ります。

codecommit-repo.png

これにて、リポジトリの作成は完了です。

AWS Cloud9での設定

もう、ここに書いてある通りなのですが、Cloud9のターミナルで以下のコマンドを実行します。
ユーザネームとメールは、各自のものを設定します。

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
git config --global user.name "Mary Major"
git config --global user.email mary.major@example.com

で、Cloud9ターミナルからgit cloneしてみましょう。
git-clone-after.png.jpg
クローンできました。CodeCommitとCloud9をあっさりと連携することができました!
(空のリポジトリなので警告が出ています)

ではCodeCommitにcommitしましょう

早速ですが、以下のような簡単なコードをPythonで準備して、test.pyでlambda-testディレクトリ以下に保存しました。
test-src.png.jpg

あとは、ターミナルにて

git add -A
git commit -m "init"
git push origin master

を実行します。
codecommit-push.png.jpg

で、AWSマネコンに戻り、CodeCommitを確認すると
pushed.png.jpg
空だったリポジトリにファイルが追加され、
pushed2.png.jpg
中身もきちんと反映されていました。

まとめ

今回は、Cloud9からCodeCommitの連携を行い、実際にコードをPUSHしました。
さすがどちらもAWSサービスだけあって、シームレスに統合することができました。
CodePipelineなんか使って、S3にデプロイすれば、すでに静的Webサイトのホスティングが、開発も、CI/CDも、コード管理も、ぜーんぶクラウドベースでできちゃうことになります。
AWSさまさまですね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?