Skip to content

Latest commit

 

History

History
 
 

01

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

A Serverless Project

Brought to you by Dozen Software

Blog Post #1 - CDK and Code Commit

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.

  1. Sign up for AWS
  2. Create an IAM user to use for this project
  3. Install the aws-cli
  4. Set up that user in your CLI
  5. Install the aws-cdk
  6. Create a CodeCommit repository
  7. Create Git Credentials
  8. Set up the structure for our project (or just copy the files)
  9. Conclusion

Step 1: Sign up for AWS

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.

Step 2: Create an IAM user to use for this project

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.)

  1. Visit the IAM console and click on Add User IAM Users
  2. Then enter a name for the user (I chose cdkuser), and select both Programmatic access and AWS Management Console access. Uncheck the User must create a new password checkbox. Add User
  3. Click on Attach existing policies directly and select Administrator Access and then click Next: Tags. Add User WARNING - This is not AWS 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...
  4. Click Next: Review (we don't need to add Tags).
  5. Click Create User
  6. Download the CSV Download the CSV Your CSV should have a password, an Access key ID and a Secret access key and look something like this... Credentials.csv
  7. Your user has been created!

Step 3: Install the aws-cli

Follow these instructions to install the AWS CLI

Step 4: Set up that user in your 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

Step 5: Install the aws-cdk

  1. If you don't have it already, install npm.
  2. Then just npm install -g aws-cdk.
  3. That's it!

Here's more info if you need it.

Step 6: Create a CodeCommit repository

AWS has a service called CodeCommit. It's a lot like GitHub or GitLab. To create a new repository...

  1. Logout of the AWS Console (the AWS website).
  2. Visit the Console login link from your credentials.csv file and login as the user you created in Step 2. In my example the username will be cdkuser, and I'll copy the password from my credentials.csv file.
  3. Visit CodeCommit in the AWS Console
  4. Click Create repository Create repository
  5. Give your repository a name (I chose my-cdk-project). Name your repository
  6. You should see something like this Repo Confirmation

Step 7: Create Git Credentials

  1. Go to Users in the IAM Service of the AWS Console.
  2. Click on the user you created (mine was cdkuser)
  3. Click on Security credentials User
  4. Scroll to the bottom and click on Generate under HTTPS Git credentials for AWS CodeCommit Security Credentials
  5. Click on Download Credentials Generate Credentials
  6. Your csv should look something like this Downloaded Credentials

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

Step 8: Set up the structure for our project

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.

Copy and paste

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...

  1. Clone this repo
  2. Copy the 01 folder into your empty project
  3. Commit the new code to your repo that you created earlier

How I set up this project...

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
  1. The cdk folder will contain the code to generate our infrastructure
  2. The public folder will hold our index.html file - the entry point for our front end
  3. 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
  1. Establish a .gitignore file so that you don't commit your dependencies to your repo.
  2. Initialize npm for the project
  3. Install react dependencies
touch public/index.html src/App.js src/index.js src/registerServiceWorker.js
  1. public/index.html is the container into which we'll inject our React project
  2. src/App.js is the parent Component of our React project
  3. src/index.js is the entry point of our React project
  4. 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.

Conclusion

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