ruby-on-railsherokuamazon-web-servicesamazon-s3zsh

zsh: parse error near `\n' when Adding AWS keys as environment variables


I have a Rails app that I am hosting on Heroku, and hosting images on a Amazon S3. I am trying to add my Amazon credentials to my app using:

heroku config:add aws_access_key:<your access key> aws_secret_key:<your secret key>

I keep getting the error:

zsh: parse error near `\n'

I have no idea what the problem is.


Solution

  • Most likely your keys contain some characters that have special meaning to zsh.

    Use single quotes (') around your keys:

    heroku config:add aws_access_key='<your access key>' aws_secret_key='<your secret key>'
    

    If there are any single quotes in your keys write '\'' instead. For example, instead of

    aws_access_key=stevie's key
    

    write

    aws_access_key='stevie'\''s key'
    

    Explanation: anything between a pair of single qoutes is taken exactly as it is written, there will be no parameter or command substitution or escape codes. As the second ' ends the quote any ' you want to write has to be quoted in anoter way outside of a pair of single quotes, either \' or "'".