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
- As a reference, please read my 1st article - 6-part series - (1) Deploy a Custom Docker Image with Centos on an Apache web server and Save it to AWS ECR Repository
2nd article
- As a reference, please read my 2nd article - 6-part series - (2) Create Task Definition in ECS and Application Load balancer for the Task to be run on Fargate Cluster
3rd article
- As a reference, please read my 3rd article - 6-part series - (3) Create Fargate Cluster, and a Service which can access customized Docker image
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:
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
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
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
- Install git
yum install git -y
- Generate the public and private keys for Git and CodeCommit
ssh-keygen
- Go to the SSH keys location
cd ~/.ssh/
- command "ll" to check.
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
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
-
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
- In the .ssh directory, Create a file - name it config
Host git-codecommit.*.amazonaws.com
User APKAT7SS6ZVXC6LRIFXL
IdentityFile ~/.ssh/id_rsa
- To change the permissions for the config file
chmod 600 config
- Go to the docker folder
cd /opt/docker
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
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
- Move the dockerfile and index.html file to my-codecommit-repo
mv dockerfile index.html my-codecommit-repo/
cd my-codecommit-repo
ls -lt
- to add all the files to the git
git add .
- Check the status
git status
- Commit the files
- Pushing the files into the remote repository’s master branch
git push
- to the CodeCommit repository and check the files.
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)