Wednesday, October 23, 2013

Editing a Putty Session to always point at the correct AWS Instance.

Problem : Putty Sessions are in the registry.

So we want to edit the registry to insert the new public DNS name after we have started it.  ( our intent is to start and stop nightly so we are lazy about picking up the new DNS name )

We can get the dns name from the previous step.

Probably the best way to do this is write and execute a registry .reg file.

Relevant key is

So.... if we do something along the line of exporting the relevant session hive and the substituting in the rest... i.e. like

aws ec2 describe-instances --filters "Name=instance-id,Values=i-xxxx" --quer
y "Reservations[*].Instances[*].{dz:PublicDnsName}" --output text  > pdn1.out
set /p myvar=type > update.reg
echo "HostName"="%myvar%" >> update.reg
type >> update.reg

Sub in the relevant instance-id and then run update. reg .... also don't forget to edit the registry if you want to divert X window tunnels etc for Vnc desktop , you need the internal IP for that though so a slightly different call but should not be excessive.

If you wanted to make that easy you could run it up as a .bat with admin rights to avoid the UAC prompt but .. as I said... exercise for the reader !

Using the AWS CLI to get a public hostname

We use this for the next step,  amending Putty.

  • Assumptions : 
  • We know the instance-id 
  • We have a working CLI. 
So we use ec2-describe-instances 

We use a filter to only get info for our instance. 
We use a query to only output the Public DNSNAME 
aws ec2 describe-instances 

--filters "Name=instance-id,
--output  text

C:\Users\Chris\.aws>aws ec2 describe-instances --filters "Name=instance-id,Value
s=i-xxxxxxxx" --query "Reservations[*].Instances[*].{dz:PublicDnsName}" --output

So now we have our public DNSNAME, and with that we can change our putty settings ! 

Getting the Amazon SDK Running.

Hi folks we will talk about getting Amazon AWS command line tools

We assume you have signed up with Amazon and given them your credit card etc etc.

First thing to do is download the Windows installer from

this is 5.7 mb currently .  So when you run that

So accept the license and click next next next 

So the next thing to do is to follow the rest of

If we look at our PATH setting now by opening a command window we can see that AWSCLI has been added to the end of the variable, usually c:\program files\Amazon\AWSCLI
If we now try 


usage: aws [options] [parameters]
aws: error: too few arguments


it is evident we must do a lot of things to get it all configured to start talking to our instances. 

First thing to do is to look at getting the config file set up. 

This will need to be in a directory .aws, so usually %USERPROFILE%\.aws\config

C:\Users\Chris>mkdir .aws

C:\Users\Chris>cd .aws

 Volume in drive C is OS
 Volume Serial Number is F619-A748

 Directory of C:\Users\Chris\.aws

23/10/2013  12:43    

23/10/2013  12:43    

               0 File(s)              0 bytes
               2 Dir(s)  13,599,453,184 bytes free

So what will this config file contain ?  Well this is the important credential and region information. 

We see an example in the getting started 

aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
region = us-west-2

OK so where do we get our values.

Region should be easy as it is where you will be doing most of your work for me that will be eu-west-1

yours will probably be different. 

OK that was easy.  For our access key and secret we got these when we signed up first for AW.  You can get them from

So edit the liitle config file with the relevant information in it 

 Directory of C:\Users\Chris\.aws

23/10/2013  12:56    
23/10/2013  12:56    
23/10/2013  12:57               137 config
               1 File(s)            137 bytes
               2 Dir(s)  13,595,860,992 bytes free


One point to note is that if you are using notepad to edit the config file it saves it as .txt which is wrong it needs to be just called config. 

OK so let's give it a try 

C:\Users\Chris\.aws>aws ec2 describe-regions|more

    "Regions": [
            "Endpoint": "",
            "RegionName": "eu-west-1"
            "Endpoint": "",
            "RegionName": "sa-east-1"
            "Endpoint": "",
            "RegionName": "us-east-1"
            "Endpoint": "",
            "RegionName": "ap-northeast-1"
            "Endpoint": "",
            "RegionName": "us-west-2"
            "Endpoint": "",
-- More  --

OK... all working

In the next post we will show how to grab some value out of this.