Welcome back to Stage1
of this AdvancedDemo series.
And in this stage,
you're going to implement this architecture.
So you're going to be creating and configuring
a CodeCommit repository,
giving yourself access to that repository,
cloning the repository down to your local machine,
adding some files,
and pushing those files back up to the repository.
Now as always, there are a full set
of text-based instructions attached to this lesson.
The first thing that you'll need to do though
is to move across to your terminal.
Now this part is important
because the steps that you need to perform
vary massively depending on whether you're using
either Linux or macOS or Windows.
Now Linux and macOS use roughly the same steps
whereas Windows is completely different.
And in addition to the full text instructions,
I've included links to each of these instructions
attached to this lesson.
So because I'm using macOS,
I'm going to follow those instructions.
And the first thing that I'm going to do
is to move into the .ssh folder.
This is the folder where all of the SSH keys
and configuration is stored on my local machine.
Next, I'm gonna go ahead and generate an SSH key pair.
It's going to be an RSA key type
and it's going to be 4,096 bits.
And so to do that, I'm going to run this command.
So go ahead and use that command and press Enter.
You'll need to enter a name for the key pair,
so go ahead and use CodeCommit,
and then press Enter.
We won't be using a passphrase,
so press Enter,
and then confirm that again.
And that will save out the key pair into the current folder.
So that's the .ssh folder, in my case.
I'm gonna clear the screen to make it easier to see.
And the next step is that we need to get
the public part of this key pair,
because that's what we need to upload to AWS.
To get that, I'm gonna run this command.
So cat~/.ssh/codecommit.pub.
Again, it will be slightly different
depending on your operating system,
but what we'll need to do is copy this entire
public part of this key into our clipboard.
So copy that into your clipboard.
And then you can go ahead and move back to the AWS console.
At the AWS console, go ahead and type IAM
into the search box at the top
and then click to move to the IAM console
because we're going to upload this public key
into our IAM identity.
So click on Users.
You should be logged in as the IAMadmin user.
So go ahead and click the IAMadmin user.
Then click on Security credentials and scroll down.
And we're looking for SSH keys for AWS CodeCommit.
So this is how you authenticate with CodeCommit
when interacting with repositories,
you use an SSH key pair.
You can also use HTTPS credentials
but I prefer to use SSH keys.
So go ahead and click on the button
to upload the SSH public key.
And paste the contents of your clipboard into this box.
Then once you've done that, go ahead and click on the button
to upload that SSH public key.
Now it's going to show you the SSH key ID
for the public key that you've just uploaded.
And we're going to need that in the next step.
So just make sure that you leave this screen open
and then move back to your terminal.
Now there's a configuration file
in this folder called config
and we need to edit that configuration file.
So we do that using this command.
So we're editing using the nano text editor,
and we're editing the SSH config file.
Now it should look something like this.
Don't be overly concerned if it looks different.
What we need to do is add something to the top of this file.
So just press Enter
and then move the cursor to the top of the file.
Now inside the text-based instructions for this stage
is a code snippet that you'll need to copy
into your clipboard and paste into this file.
It should look something like this.
So you should have host git-codecommit.star.amazonaws.com.
It should point at the identity file that you just created.
So the key that's called CodeCommit inside this folder.
Again, if you're using Windows or Linux,
this might look slightly different.
The key part that you need to worry about
is that you need to delete this placeholder
all the way to the space after user.
So leave the space.
And then move back to the AWS console
and copy the SSH key ID into your clipboard.
Now make sure that you don't copy the key ID
for your access keys.
We need to make sure that
this is the SSH keys for AWS CodeCommit.
So copy that into your clipboard.
Move back to your terminal and paste in that key ID.
Now that's going to ensure
that whenever we attempt to authenticate to CodeCommit,
this is the SSH key that we use.
So go ahead and save that file
and then exit out of your editor.
Now I'm using macOS, so I just need to make sure
that the permissions on this file are appropriate.
So I'm going to use a chmod 600 space,
and then the path to this config file.
Again, if you're using Windows or Linux,
these steps may vary.
I'll clear the screen again to keep it easy to see.
And then finally, we need to test
that we can authenticate through to CodeCommit
using this SSH key that we've just created.
And to do that, we're going to use this command.
This is a simple connection command
which attempts to connect
to git-codecommit.us-east-1.amazonaws.com.
So go ahead and run that command.
What you should see is you have successfully
authenticated over SSH.
Don't worry about any of the other text
even if it looks like an error.
The only thing that we care about
is that you have successfully authenticated over SSH.
So that's the authentication part
of this process configured.
We can now interact with CodeCommit
from our command line.
So we can use the git command to push or pull any code
into or out of any repositories within CodeCommit.
So let's go ahead and move back to our AWS console.
And the next step is that we need to create
the CodeCommit repository.
So to do that, click in the Search box at the top
and just type CodeCommit,
and then click to move to the CodeCommit console.
Once you're at the CodeCommit console,
just make sure that you're inside CodeCommit.
So click on Repositories.
And at this point, you probably shouldn't have
any repositories created within CodeCommit.
So we're going to create one.
So go ahead and click on Create repository.
Go ahead and enter a repository name.
So I suggest you use catpipeline-codecommit.
And then if this were production usage
you'd probably have many of these,
so you need to make sure that they're unique
and easily distinguishable.
So often, you might want to put a unique ID
or a project code at the end,
and you could just use another hyphen
and then use a particular ID for project code
or anything that you want.
I'm gonna go ahead and use catpipeline-codecommit,
and then I'm gonna add 1337 onto the end,
just so that I know what repository this is.
Go ahead and name your repository and then click on Create.
Now once you've created that repository,
you'll see there's a dialogue which shows you
the connection steps to interact with this repository.
Now as I mentioned before,
you can use HTTPS to interact with the repository,
but I prefer SSH.
So go ahead and click on SSH.
And this is going to give you the connection instructions
for all of the three popular operating systems
supported by this course.
So macOS, Windows, or Linux.
In my case, I'm using macOS,
so I'm going to expand that.
It's going to give you the steps required
to interact with this repository.
And you'll notice those are the same steps
that we've already taken.
So registering a public key,
editing the local SSH configuration,
adjusting the permissions on this config file,
and then the last step, is to clone down the repository
using this command.
So go ahead and copy that into your clipboard
and then move back to your terminal.
I'm gonna clear the screen to keep things easy to see.
And then I'm going to move to my home folder
by typing CD and pressing Enter.
Now, I always recommend with my courses
to have a location where all of your repositories are kept.
In my case, I have a folder called repos
where all of my repositories are.
And then within there,
I have another folder called learn.cantrill.io
where all of my course-based repositories are stored.
So I'm going to move into that folder.
You should get into the habit of creating
a similar folder structure for all of your repositories
but whatever structure you use,
you need to move into the folder
where you want the repository stored
because next we're going to clone the repository down
to our local machine.
So I'm going to clear the screen to keep things easy to see
and then we'll need to paste in the command
that we've just copied into our clipboard and press Enter
to clone this repository down to our local machine.
So it's going to clone the repository down
into a folder with the same name as the repository name.
You'll see a warning saying that
"You appear to have cloned an empty repository,"
and that's okay because the repository is empty.
We've just created it
and it currently contains no source code.
And that's okay.
Now the next step is that we need to add
some code into this repository.
Now attached to the instructions for this lesson
is a link to download a file called container.zip.
And this is the source code
for a simple containerized application
which you may have used from my other courses.
So go ahead and click this link
to download it to your local machine.
Once you've downloaded this container.zip file,
go ahead and extract it.
And this is what this folder should look like.
You might recognize this.
If you've done my other courses,
this is from a lesson where you create a Docker image
and then you use that to run a Docker container
both on EC2 and within ECS Fargate.
What we're going to do in this demo series
is automate the process
of building and deploying this Docker image.
So all of these files,
you need to go ahead and copy those
and you need to copy them
into the repository that you've just cloned
down to your local machine.
So in my case, this is the repository,
catpipeline-codecommit-1337.
I'm gonna go ahead and paste in all of those files.
And there we go, we've got six cat images,
a Docker file,
something called imagebuild.md, which you can ignore,
and then an index.html.
And once we've done that, we can go ahead
and move back to our terminal.
And we're going to add these files
locally into our staging area, commit them,
and then push them into the remote repository.
We're going to move into the repository folder
that we've just cloned down.
And then we're going to run this command.
So, git add -A .
And that's going to add all of these files
in the current directory signified by a period.
So press Enter, and that will add all of those files.
Then we need to commit these files.
So, git commit -M, for message,
and then speech marks
and then we'll just type a brief comment,
"container of cats" and press Enter.
And that commits all of these files.
And lastly, we need to use a, git push,
to push those files up to CodeCommit.
That'll take a few moments.
Once it has finished, you'll see that
it's created a new branch called master.
Once that's done, we can move back to the AWS console.
Once we're back at the console,
if we click on Code, we'll be able to see that
now inside this repository are all of those files
which we just pushed into this repository.
So that's everything that you need to do
in Stage1 of this demo series.
You've successfully configured security
so that you can interact
with any repositories within CodeCommit.
You've created a repository.
You've cloned it down,
you've added some files.
And then you've done your first commit
and pushed that back up to this CodeCommit repository.
So now we have files within this repository
and we have a single branch called master
that's inside this repository.
And that's everything that we need to do at this point.
You can go ahead and finish this video.
In Part two, you're going to get the experience
of working with CodeBuild.
And CodeBuild is going to automate the process
of creating a Docker image
from the files in this repository.
But at this point, that's everything you need to do.
So go ahead, complete this video.
And when you're ready, I'll look forward
to you joining me in Stage2.