Errors running aws-alias.sh

Just wanted to point out a couple issues/solutions when working through setup with the aws-alias.sh script. I am using an ubuntu shell w windows 10.

  1. I’m using a free-tier t2 server (micro) and paid tier p2 server, with the plan to test small code on the free tier and pay the 90c/hour when I need to. The aws-alias.sh code references ‘t2.large’ large servers so this needed to be changed to ‘t2.micro’ in the code snippet.

  2. The ‘aws-start’ command was generating an error:

'…
CURRENTSTATE 16 running
PREVIOUSSTATE 16 running
usage: aws [options] [parameters]
aws: error: argument operation: Invalid choice, valid choices are:

activate-license | allocate-address
assign-private-ip-addresses | associate-address
…’
… a bunch of other options, none of which was ‘wait’.

I edited the ‘wait’ lines out of the ‘aws-start’ code to get:

‘aws ec2 start-instances --instance-ids $instanceId && export instanceIp=aws ec2 describe-instances --filters "Name=instance-id,Values=$instanceId" --query "Reservations[0].Instances[0].PublicIpAddress" && echo $instanceIp’

which works fine independently but once I re-edited the ‘aws-alias.sh’ to exclude the wait, it gave the same error and didn’t provide the ip…

Any thought on what was going on here and if this will come back to bite me in the future?

Let me know if I could provide any more details

for part 2) I had issues with the script, it turns out it wasnt the script but either windows invisible characters at the end or in the middle of file messing things up. i had copied and pasted from the Raw github file from windows into the cygwin editor.

i used cygwin to install dos2unix and then ran that command on the .sh file and after cleaning the file up no issues.

1 Like

Hmm, thanks for the tip but using dos2unix didn’t seem to work for me. I had downloaded the raw github file directly using wget.

I was running into similar issue with all the variables assigned by Echo output and was not seeing the same issue in Win 10 with Linux. After spending more than 3 hours (definitely not deep learning :slight_smile: I was able to identify the special character (^M obtained by doing Ctrl-V followed by Ctrl-M) and remove it using dos2unix and storing the output in the same variable. I had to modify the script before using $instanceId and $instanceIp . Also learnt that Linux is very sensitive to space after the assignment operator also and had to remove the space.

akrish5@AKRISH5-MOBL1 ~
$ echo $instanceIp
35.166.8.45

akrish5@AKRISH5-MOBL1 ~
$ echo $instanceIp | cat -A
35.166.8.45^M$

akrish5@AKRISH5-MOBL1 ~
$ ssh -i ~/.ssh/aws-key2.pem ubuntu@$instanceIp
: Name or service not knownname 35.166.8.45

akrish5@AKRISH5-MOBL1 ~
$ instanceIp=$(echo $instanceIp | dos2unix)

akrish5@AKRISH5-MOBL1 ~
$ echo $instanceIp
35.166.8.45

akrish5@AKRISH5-MOBL1 ~
$ echo $instanceIp | cat -A
35.166.8.45$

akrish5@AKRISH5-MOBL1 ~
$ ssh -i ~/.ssh/aws-key2.pem ubuntu@$instanceIp
The authenticity of host ‘35.166.8.45 (35.166.8.45)’ can’t be established.
ECDSA key fingerprint is SHA256:8CePDM/9EMM+g55CLSv6cZ8m/98wbk2ZF1sfW8LFeCw.
Are you sure you want to continue connecting (yes/no)?

1 Like

Thanks for the explanation
… funny how sensitive that syntax can be…