Initial setup on cloud9 for AWS CDK
The steps in this tutorial can be followed to set up locally as well. I advise the use of VS Code, and the Windows Subsystem for Linux as your bash terminal inside the VS Code editor. You will face some issues but I’m sure you will be able to figure them out. Learn to google things and consider being stuck a learning experience. Hint: You will need to install packages using sudo apt install.
Part 1 Python version from 2 to 3
Assuming you’ve started the environment in either cloud9 or are in the bash terminal. We start off by being concerned with the version of python in the environment which is 2 by default. Type in the below command to see the output.
python -- version
To change the default we edited the bashrc file
vim ~/.bashrc
press i to go to edit mode. At the bottom of the file enter
alias python='/user/bin/python3'
Use escape to exit edit mode
Enter “:wq” to write (save the file) and quit.
Type the below to run the file
source ~/.bashrc
And now you should have python 3 as the default python being used. You can check with the version command.
Part 2 AWS command setup
aws -- help
To check if aws exists or whether the version is good enough for us.
Install it with
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/install
If the above command is not suitable for your system, search “Install the AWS CLI version 2 on Linux” or whatever and copy the curl command with its link.
Quick configuration with aws configure
aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS
Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2
Default output format [None]: json
For more detail on ‘aws configure’ and where to get the keys if you don’t already know how; follow the link below.
Part 3 CodeCommit & SSH
I recommend following the above tutorial rather than section 3. Codecommit was used but you could easily use github. Search setting up ssh with github and follow those tutorials.
ssh-keygencat ~/.ssh/id_rsa.pub
Go to IAM on console.
Select user.
Go to security and credentials and upload public ssh key
Copy or save the information in SSH Key ID
On your local machine, use a text editor to create a config file in the ~/.ssh directory i.e vim ~/.ssh/config, 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 APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
Then enter
chmod 600 ~/.ssh/config
I would like you to google what chmod is and the different access permissions you can grant to files.
Follow the link given in this section to complete the rest of the steps.
Assuming you have cloned any repo :
git config -- global user.name=”Mubash Zubash”git config -- global usern.email=”mubashirullah@acm.org”
To check if these values have been saved, type the below
vim ~/.gitconfig
Part 4 AWS CDK installation
nmv will exist on cloud9. If you are following this tutorial for setting stuff up locally then you need to setup nvm
nvm install v16.3.0 && nvm use v16.3.0 && nvm alias default v16.3.0
Once that works, enter the below command and cdk will become a command you can enter if it did not exist previously.
npm install -g aws-cdk
Part 5 AWS CDK in Python
mkdir infra
cd infracdk --helpcdk init app --language python
To manually create a virtualenv on MacOS and Linux:
If the venv is not created by the cdk init by default you can create it with:
$ python3 -m venv .venv
You can use the following step to activate your virtualenv.
$ source .venv/bin/activate
If you are a Windows platform, you would activate the virtualenv like this for cmd or PS:
.venv\Scripts\activate.bat.\.venv\Scripts\Activate.ps1
Once the virtualenv is activated, you can install the required dependencies.
$ pip -V$ pip install -- upgrade pip$ pip install -r requirements.txt
Part 6
cdk synthcdk deploy
Your good to go after this point.
Want to learn Cloud DevOps? Check out