In this article we are creating a local copy of the CodeCommit repository which we are creating in AWS, and making some changes to it. Then we push the changes to the AWS CodeCommit repository.
Step-by-step guide
Setup for HTTPS users using Git credentials.
1. Create an AWS CodeCommit Repository.
On the Create repository page, in Repository name, enter a name for your repository. Other fields are optional.
2. Creating Local repository in our system from AWS CodeCommit repo.
Choose Clone URL, and then choose the protocol you want to use when cloning or connecting to the repository.
There are three protocols:
-Copy the HTTPS URL if you are using either Git credentials with your IAM user or the credential helper included with the AWS CLI.
-Copy the HTTPS (GRC) URL if you are using the git-remote-codecommit command on your local computer.
-Copy the SSH URL if you are using an SSH public/private key pair with your IAM user.Here we are using HTTPS URL,
- Create an IAM user with CodeCommit access and generate HTTPS Git credentials, since git https credentials will be asked when running git clone.
2.1. Sign in to the AWS Management Console and open the IAM console to create CodeCommit user.
2.2. In the IAM console, in the navigation pane, choose Users, and then choose Add user or select existing user.
2.3. In Grant permissions, choose Attach existing policies directly.
2.4. After you have selected the policy you want to attach, choose Next: Review to review the list of policies to attach to the IAM user.
- Generate HTTPS Git credentials for CodeCommit user.
git clone https://git-codecommit.us-east-2.amazonaws.com/v1/repos/test
Now you have the local repo with exact copy of CodeCommit repo.
In Grant permissions, choose Attach existing policies directly.
- Add files to see the changes happen in CodeCommit after next push.
- Run git config to add your username and email address. This makes it easier to identify the commits you make and others.
git config --local user.name "your-user-name" git config --local user.email your-email-address
- Run git status to view the changes made,
git status
- Run git add to stage the change,
git add .
- The git add command adds changes in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.
- Run git commit to commit the change,
git commit -m "Message to commit"
- Run git push to push your initial commit.
git push -u origin master
In this step, you push the commit from your local repo to your CodeCommit repository. you can view the changes in AWS. CodeCommit user authentication is needed here.
- Now you can view the changes/added files in the AWS CodeCommit repo.
Setup steps for SSH connections to AWS CodeCommit repositories
- To set up the public and private keys for Git and CodeCommit from the terminal on your local machine, run the ssh-keygen command, and follow the directions to save the file to the .ssh directory for your profile.
- Run the following command to display the value of the public key file (Codecommit_rsa.pub) :
cat ~/.ssh/codecommit_rsa.pub
Copy this value to the clipboard.
- In AWS IAM console, in the navigation pane, choose Users, and from the list of users, choose your IAM user you created for this CodeCommit. On the user details page, choose the Security Credentials tab, and then choose Upload SSH public key. Paste the contents of your SSH public key into the field, and then choose Upload SSH public key.
- Copy or save the information in SSH Key ID (for example, APKA4RVIFCYLNQJMQFFA).
- On your local machine, use a text editor to create a config file in the ~/.ssh directory, and then add the following lines to the file, where the value for User is the SSH key ID you copied earlier:
Host git-codecommit.*.amazonaws.com User APKA4RVIFCYLNQJMQFFA IdentityFile ~/.ssh/codecommit_rsa
- Change the permissions for the config file:
chmod 600 config
- Setup is completed and you can test your SSH configuration using the following command :
ssh git-codecommit.us-east-2.amazonaws.com
LET US TAKE CARE OF YOUR SERVERS 24/7/365.
Get rid of all the hassles