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
HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions.


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 firstpart.in > update.reg
echo "HostName"="%myvar%" >> update.reg
type lastpart.in >> update.reg
C:\Users\Chris\.aws>

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 !


No comments: