DEV Community

Revathi Joshi for AWS Community Builders

Posted on

6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch

In this 6-part series on configuring a CI/CD pipeline using Customized Docker image on an Apache Web Server, Application Load Balancer, ECS, ECR, CodeCommit, CodeBuild, CodeDeply services -

In the 4th article, We will create a CodeCommit Repository, and with proper permissions to IAM User, Using SSH public keys we will authenticate access to AWS CodeCommit, then Clone the repository and we will move the Dockerfile and index.html inside the repo and push them to remote repository master branch.

1st article

2nd article

3rd article

Let’s get started!

Please visit my GitHub Repository for Docker/ECS/ECR articles on various topics being updated on constant basis.

Objectives:

1. Create a CodeCommit repository called "my-codecommit-repo"

2. Assign permissions to IAM User to access CodeCommit

3. Use SSH public keys to authenticate access to AWS CodeCommit

4. Clone the repository

5. Move the Dockerfile and index.html inside the repo and push them to remote repository master branch

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • AWS CLI.

Resources Used:

CodeCommit

AWS CodePipeline

Steps for implementation to this project

1. Create a CodeCommit repository called "my-codecommit-repo"

  • On the Codecommit dashboard, Repositories, Create repository, my-codecommit-repo, Description - my-codecommit-repo, Tags, Name, Value - my-codecommit-repo

  • Create

Image description

  • On the connection steps page

  • There are 3 types of connections, HTTPS, SSH and HTTPS (GRC)

  • I am going to be working with SSH connection

Image description

2. Assign permissions to IAM User to access CodeCommit

  • On IAM Dashboard, Users, goti2, Permissions tab, Add permissions, Attach policies directly, Search and select AWSCodeCommitPowerUser, Next, Review and Add permissions

3. Use SSH public keys to authenticate access to AWS CodeCommit

  • SSH into the EC2 Instance thru Putty

  • Go to the docker folder using the command

sudo su
cd /opt/docker
Enter fullscreen mode Exit fullscreen mode
  • Install git
yum install git -y
Enter fullscreen mode Exit fullscreen mode

Image description

  • Generate the public and private keys for Git and CodeCommit
ssh-keygen
Enter fullscreen mode Exit fullscreen mode

Image description

  • Go to the SSH keys location
cd ~/.ssh/
Enter fullscreen mode Exit fullscreen mode
  • command "ll" to check.

Image description

  • In order to access the CodeCommit through SSH, we need to copy and paste the SSH public key in IAM User

  • Use the following command to copy the public key content

cat id_rsa.pub

Enter fullscreen mode Exit fullscreen mode
  • On the IAM console, Users, click on the user - goti2, Go to the Security credentials tab and under SSH Keys for AWS CodeCommit, Click on Upload SSH public key

Make sure to paste it properly to avoid errors in the future

  • Once pasted, click on Upload SSH public key, you can see the SSH Key ID

  • Copy the SSH Key ID for future reference.

APKAT7SS6ZVXC6LRIFXL
Enter fullscreen mode Exit fullscreen mode

Image description

  • Back to the CodeCommit, SSH connection page, Linux, Step 3, Copy the 3 lines of code in step 3
Step 3: Edit Local SSH Configuration

Edit your SSH configuration file named "config" in your local ~/.ssh directory. Add the following lines to the file, where the value for User is the SSH Key ID you copied in Step 2.

Host git-codecommit.*.amazonaws.com
User Your-IAM-SSH-Key-ID-Here
IdentityFile ~/.ssh/Your-Private-Key-File-Name-Here

Once you have saved the file, make sure it has the right permissions by running the following command in the ~/.ssh directory.

chmod 600 config
Enter fullscreen mode Exit fullscreen mode
  • In the .ssh directory, Create a file - name it config
Host git-codecommit.*.amazonaws.com
User APKAT7SS6ZVXC6LRIFXL
IdentityFile ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • To change the permissions for the config file
chmod 600 config
Enter fullscreen mode Exit fullscreen mode

Image description

  • Go to the docker folder
cd /opt/docker

Enter fullscreen mode Exit fullscreen mode

4. Clone the repository

  • Clone command from the SSH page in CodeCommit
Clone your repository to your local computer and start working on code. Run the following command

git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-codecommit-repo
Enter fullscreen mode Exit fullscreen mode

Image description

5. Move the Dockerfile and index.html inside the repo and push them to remote repository master branch

  • Go to the docker folder
sudo su
cd /opt/docker
Enter fullscreen mode Exit fullscreen mode
  • Move the dockerfile and index.html file to my-codecommit-repo
mv dockerfile index.html my-codecommit-repo/

cd my-codecommit-repo

ls -lt
Enter fullscreen mode Exit fullscreen mode

Image description

  • to add all the files to the git
git add .

Enter fullscreen mode Exit fullscreen mode
  • Check the status
git status
Enter fullscreen mode Exit fullscreen mode

Image description

  • Commit the files

Image description

  • Pushing the files into the remote repository’s master branch
git push

Enter fullscreen mode Exit fullscreen mode

Image description

  • to the CodeCommit repository and check the files.

Image description

What we have done so far

  • We have successfully created a CodeCommit Repository, authenticated using SSH public keys, cloned the repository, and moved the Dockerfile and index.html inside the repo and pushed them to remote repository master branch.

Top comments (0)