Pipeline form Code Commit repository
Pre-requisites
AWS account
Code Commit repository
Local machine setup
In this pipeline we setup source stage and deploy stage
First, log in to the AWS Console, open the code commit repository and create a repository name: MyDemoRepository
Next you need to clone the repository to your local machine make sure git installed in the local machine
Now if you using a Windows machine go to your bash emulator like Git Bash
From the emulator, run the ssh-keygen command and save the file to the .ssh directory
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/drive/Users/user-name/.ssh/id_rsa): Type a file name here, for example /c/Users/user-name/.ssh/codecommit_rsa
Enter passphrase (empty for no passphrase): <Type a passphrase, and then press Enter>
Enter same passphrase again: <Type the passphrase again, and then press Enter>
Your identification has been saved in drive/Users/user-name/.ssh/codecommit_rsa.
Your public key has been saved in drive/Users/user-name/.ssh/codecommit_rsa.pub.
The key fingerprint is:
45:63:d5:99:0e:99:73:50:5e:d4:b3:2d:86:4a:2c:14 user-name@client-name
The key's randomart image is:
+--[ RSA 2048]----+
| E.+.o*.++|
| .o .=.=o.|
| . .. *. +|
| ..o . +..|
| So . . . |
| . |
| |
| |
| |
+-----------------+
The above code generates a file with a private key file and public key file
Now copy the content in the public key that was generated and paste in the SSH public keys for AWS Code Commit from Security Credentials now that we have
SSH key ID
Now in git bash create a config file in the directory
vi ~/.ssh/config
now add the following to the config file
Host git-codecommit.*.amazonaws.com
User APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
the above is SSH configuration for accessing AWS Code Commit repositories using GIT
Run the following command to connect the local machine to AWS Code Commit
git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/MyDemoRepo
if it is successful, you will be connected to the repository
if not you need to troubleshoot the following command
ssh -v git-codecommit.us-east-2.amazonaws.com
Now add your code to the repository, i add it from the local machine
Push the files to the code commit
command to stage all of your files at once
git add -A
command to commit the files with a commit message
git commit -m "Add sample application files"
Run the following command to push the files from your local repo to Code Commit repository
git push
The files you added to your local repo have now been added to the main
branch in your Code Commit MyDemoRepo
repository and are ready to be included in a pipeline
Create an Amazon EC2 Linux instance and install the Code Deploy agent to run your pipeline
Now we need to create roles to deploy applications
From the IAM role create a role with the name EC2Role and attach the following policies
AmazonEC2RoleforAWSCodeDeploy
AmazonSSMManagedInstanceCore
Create an EC2 Linux machine with t2.micro and at the network choose HTTP to add to EC2 security group
Create an application in Code Deploy, an application is a resource that contains the software applications you want to deploy.
Go to Code deploy console create application and enter the name
compute platform is on EC2/On-premises.
Create deployment group : it defines deployment-related settings
Pipeline in Code Pipeline
Name the Pipeline you creating
At the source stage choose Code Commit, Branch name is the main
Deploy stage choose Code Deploy
Add the application you created
Deployment Group choose the group you created
Create pipeline
Validation of Pipeline
go to your EC2 machine and copy Public DNS in details Description tab and paste in the browser you see your application running
Your Pipeline is configured to run whenever code changes are made to your Code Commit repository.