SCP Reminder

It's been some time since the last time i used scp to download files so i'm going to take advantage to write down what i need to do. I've got my ssh key setup to be able to connect to the server without password (won't describe how to do that here) and my config is setup knows how to associate my ssh key with the example-server.com server so:

scp example-server.com:/tmp/file-a.txt ~/

And that's it! next time i forget, i'll know where to look for when it comes to downloading files with scp.

Setup Virtualenv for a django project

This will build on the PyEnv / Bash / OSX installation on Mac blog post i wrote some time ago in order to be able to have a set of packages in a virtual environment set only for my Django project. So, lets get started!

Environment Setup

The first thing is change into a directory that will hold my project files by running the following

mkdir myapp && cd $_

Just for the sake of versioning my application, i'm going to create a README.md and initialize my repo:

echo '# My App' >> README.md
touch .gitignore
git init
git add .
git commit -m 'Initialize repo'

Now, set a local python version within that directory:

pyenv local 3.6.2

and install virtual environment which is the last step to be able to get started setting up the project:

pip install virtualenv

Project Setup

Now it's time to get my Django app started by creating a project specific virtual environment. Bare in mind we don't want to version this directory so:

virtualenv .env
echo '.env' >> .gitignore
echo 'db.sqlite3' >> .gitignore
echo '*.pyc' >> .gitignore
source .env/bin/activate
pip install django
pip freeze > requirements.txt
django-admin.py startproject myapp .
chmod +x ./manage.py
git commit -m 'Install empty Django project'

And that should do the job! now simply run the initial migration and server:

./manage.py migrate
./manage.py runserver

and go to http://127.0.0.1:8000/ and mission accomplished!

AWS Code Commit Setup

This tutorial aims to get an IAM account setup to be able to use Code Commit. In summary I'm going to be:

  • Create IAM developer group with full permissions to access code commit.
  • Create IAM User and developer group.
  • Setting up SSH keys and configure SSH to use said keys.
  • Try a new repository

That said, lets get started.

Create IAM developer group with full permissions to access code commit.

  • Log into your account
  • Go to IAM > Groups > Create New Group
  • Create a group called Developers
  • Attach AWSCodeCommitFullAccess policy
  • Make sure you download the CSV file with all the given credentials or at least store it somewhere safe

Create IAM User and developer group.

  • Go to IAM > Users > Create New User
  • Create a user, I follow the pattern of first initial and last name (eg. jdoe)
  • Allow Programmatic access and AWS Management Console access
  • Let AWS to Autogenerated password
  • Make sure you require password reset
  • You should be able to see the Developer group you created previously make sure you assign it to the user.

Setting up SSH keys and configure SSH to use said keys.

  • Create your SSH keys by running ssh-keygen -t rsa -b 4096 -C "opposite.bracket@gmail.com"
  • name your ssh keys (eg. aws-id_rsa)
  • Go to AWS > IAM > Users
  • Select the user you created (eg jdoe)
  • Copy your public ssh key by running the following in your terminal pbcopy < ~/.ssh/aws-id_rsa in the terminal
  • Update user in AWS
  • Update your ~/.ssh/config with the following content:

Host git-codecommit.*.amazonaws.com
  AddKeysToAgent yes
  UseKeychain yes
  User {SSH key ID}
  IdentityFile ~/.ssh/aws-id_rsa

Try a new repository

  • Create a repository with your AWS CLI: aws codecommit create-repository --repository-name my-first-repo
  • Clone the repo git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-first-repo
  • Change into repo cd my-first-repo
  • Create a README.md echo '#Provisioning' > README.md
  • commit git commit -am "make first commit"
  • push git push origin master

PROFIT!!!

GitHub – opposite-bracket

Jesus Rodriguez

Vancouver, BC