Imported patch from http://www.greenhills.co.uk/2012/12/25/s3cmd-with-iam-roles.html