Brought to you by Dozen Software
For the first blog post, we're just going to get everything set up so we can have a vessel for our project.
There is some great documentation about how to get set up here. But I'll try to boil it down. Obviously, skip over any parts that you've already done or don't care about.
- Sign up for AWS
- Create an IAM user to use for this project
- Install the aws-cli
- Set up that user in your CLI
- Install the aws-cdk
- Create a CodeCommit repository
- Create Git Credentials
- Set up the structure for our project (or just copy the files)
- Conclusion
Follow this article.
You'll have to put in your credit card information. But if you follow this project, you shouldn't incur any charges. If you make a mistake here or there, you could end up spending as much at $1.00.
Once you've signed up and logged in with your root account (that's the username/password that you used to create the account), follow these steps.
(I've added some black rectangles to hide some personal info about my account.)
- Visit the IAM console and click on
Add User
- Then enter a name for the user (I chose
cdkuser
), and select bothProgrammatic access
andAWS Management Console access
. Uncheck theUser must create a new password
checkbox. - Click on
Attach existing policies directly
and selectAdministrator Access
and then clickNext: Tags
. WARNING - This is notAWS Best Practices
because your user should only have access to what they need. Giving them Administrator Access means they can use any AWS service on your behalf. Technically, we should spell out each service that the user should have access to. Perhaps I'll update this later... - Click
Next: Review
(we don't need to add Tags). - Click
Create User
- Download the CSV
Your CSV should have a
password
, anAccess key ID
and aSecret access key
and look something like this... - Your user has been created!
Follow these instructions to install the AWS CLI
Create a new file on your machine called ~/.aws/credentials
that has the following text...
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
But paste in your Access key Id
and Secret access key
from the csv that you downloaded instead of the example keys
For more information click here
- If you don't have it already, install npm.
- Then just
npm install -g aws-cdk
. - That's it!
Here's more info if you need it.
AWS has a service called CodeCommit. It's a lot like GitHub or GitLab. To create a new repository...
- Logout of the AWS Console (the AWS website).
- Visit the
Console login link
from yourcredentials.csv
file and login as the user you created in Step 2. In my example the username will becdkuser
, and I'll copy the password from mycredentials.csv
file. - Visit CodeCommit in the AWS Console
- Click
Create repository
- Give your repository a name (I chose
my-cdk-project
). - You should see something like this
- Go to Users in the IAM Service of the AWS Console.
- Click on the user you created (mine was
cdkuser
) - Click on
Security credentials
- Scroll to the bottom and click on
Generate
underHTTPS Git credentials for AWS CodeCommit
- Click on
Download Credentials
- Your csv should look something like this
You'll need this username and password in the next step, and also Step 12
Here is the official AWS documentation for creating git credentials
I recommend copy-and-pasting the following blocks of code to get started. If you keep reading, you'll see why I created each of these folders and files.
Let's say you have a folder called projects
where you will store some... projects.
cd projects
mkdir my-cdk-project
git clone https://github.com/corydozen/serverless-cdk-cicd
cp -R serverless-cdk-cicd/01/. my-cdk-project/
cd my-cdk-project
git init
git remote add origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-cdk-project
git add .
git commit -m "Step 1"
git push origin master
You'll likely be prompted for a username and password. Use the credentials from the csv that you downloaded in Step 7
This is what you just did with the copy-and-paste...
- Clone this repo
- Copy the
01
folder into your empty project - Commit the new code to your repo that you created earlier
You don't need to do anything here. It's just an explanation of the stuff you just copied over.
These are the steps I took when building out this 01
folder.
If you don't care about this, skip it
cd 01
mkdir cdk public src
- The
cdk
folder will contain the code to generate our infrastructure - The
public
folder will hold ourindex.html
file - the entry point for our front end - And the
src
folder will hold the source code for our front end application
echo "node_modules/" > .gitignore
npm init
npm i react react-dom react-redux react-router react-router-dom redux redux-devtools-extension redux-thunk
- Establish a
.gitignore
file so that you don't commit your dependencies to your repo. - Initialize npm for the project
- Install react dependencies
touch public/index.html src/App.js src/index.js src/registerServiceWorker.js
public/index.html
is the container into which we'll inject our React projectsrc/App.js
is the parent Component of our React projectsrc/index.js
is the entry point of our React project- To learn more about what
src/registerServiceWorker.js
does, read this
cd cdk
cdk init app --language=typescript
This installs some boilerplate code for developing within the CDK. We'll be using typescript in this tutorial.
Yeah, there was a lot here. I hope it made sense. If not, hit me up on twitter, or file an issue/pr on this repo.
If you made it all the way through, you're ready for Step 2