You should be using the aws-sdk to do all of this.  Not doing it is why you end up with all these really long lines.  You're stringing together commands based on conditions and appending switches/values all of the place.  The aws-sdk handles all of this:

http://docs.aws.amazon.com/AWSRubySDK/latest/frames.html

Relying on commands is inherently unsafe and doubly so when making the assumption that the command is in the user's PATH (as opposed to being explicit about location or requiring to user to provide that info).