title: AWS EC2 User Data Not Decoding Correctly
body: <p>I am experimenting with creating an EC2 instance to host a Perforce server.  My instance is configured with the following user data:</p>
  
  <pre><code>#!/bin/bash
  
  # Add a newline to the ec2-user prompt string
  echo PS1=\"\\n\$PS1\" &gt;&gt; /home/ec2-user/.bashrc
  
  # Update all packages
  yum update –y
  
  # Install Perforce packages
  # The RHEL/7 part of the baseurl should be replaced with
  # the latest RHEL version that both Amazon and Perforce support
  rpm –import https://package.perforce.com/perforce.pubkey
  cd /etc/yum.repos.d/
  echo [perforce] &gt; perforce.repo
  echo name=Perforce &gt;&gt; perforce.repo
  echo baseurl=http://package.perforce.com/yum/rhel/7/x86_64 &gt;&gt; perforce.repo
  echo enabled=1 &gt;&gt; perforce.repo
  echo gpgcheck=1 &gt;&gt; perforce.repo
  yum install –y helix-p4d
  
  # Make directories for the server, owned by new “perforce” user
  cd /opt/perforce/servers/
  mkdir danware
  cd danware
  mkdir danware-db danware-chkpts journal
  chown –R perforce:perforce danware
  </code></pre>
  
  <p>I have tested each of the above commands, and know that they work when executed manually in this order.  However, some aspect of Amazon's base64 encode/decode system seems to be getting in the way.  When I go to "Actions > Instance Settings > View/Change User Data" from the EC2 Console after launching (and passing all system checks), I see the following user data.  Note how almost every hyphen "-" has been replaced with some strange "a" character.</p>
  
  <p><a href="https://i.stack.imgur.com/5Z0N6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Z0N6.png" alt="enter image description here"></a></p>
  
  <p>However, I'm not sure that this is the issue, because the log file at /var/log/cloud-init-output.log gives me the following output (I replaced some repetitive text with [...] to save space).  Note the line that says <code>Failed running /var/lib/cloud/instance/scripts/part-001</code> I have verified that this part-001 file actually <em>does</em> have the correctly displayed hyphen characters.</p>
  
  <pre><code>[...]
  Cloud-init v. 0.7.6 running 'modules:final' at Fri, 09 Sep 2016 06:23:39 +0000. Up 86.66 seconds.
  Loaded plugins: priorities, update-motd, upgrade-helper
  No Match for argument: –y
  No packages marked for update
  RPM version 4.11.2
  Copyright (C) 1998-2002 - Red Hat, Inc.
  This program may be freely redistributed under the terms of the GNU GPL
  
  Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group] [...]
  Loaded plugins: priorities, update-motd, upgrade-helper
  Resolving Dependencies
  --&gt; Running transaction check
  ---&gt; [...]
  
  Dependencies Resolved
  
  ================================================================================
   Package                  Arch        Version               Repository     Size
  ================================================================================
  Installing:
   helix-p4d                x86_64      2016.1-1429894        perforce       24 k
  Installing for dependencies:
   helix-cli                x86_64      2016.1-1429894        perforce      8.8 k
   helix-cli-base           x86_64      2016.1-1429894        perforce      1.4 M
   helix-p4d-base           x86_64      2016.1-1429894        perforce      3.1 k
   helix-p4d-base-16.1      x86_64      2016.1-1429894        perforce      2.4 M
   helix-p4dctl             x86_64      2016.1-1429894        perforce      1.2 M
  
  Transaction Summary
  ================================================================================
  Install  1 Package (+5 Dependent packages)
  
  Total download size: 5.0 M
  Installed size: 13 M
  Is this ok [y/d/N]: Exiting on user command
  Your transaction was saved, rerun it with:
   yum load-transaction /tmp/yum_save_tx.2016-09-09.06-23.dRP_r2.yumtx
  /var/lib/cloud/instance/scripts/part-001: line 22: cd: /opt/perforce/servers/: No such file or directory
  chown: invalid user: ‘–R’
  Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
  Sep 09 06:23:41 cloud-init[2517]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
  Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Running module scripts-user (&lt;module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'&gt;) failed
  Cloud-init v. 0.7.6 finished at Fri, 09 Sep 2016 06:23:41 +0000. Datasource DataSourceEc2.  Up 88.53 seconds
  </code></pre>
  
  <p>Even more annoying, I assumed that the early <code>No Match for argument: –y</code> line from the log file was referring to the <code>yum update -y</code> line from my user data.  Sure enough, just running the example user data script from the EC2 <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" rel="nofollow noreferrer">documentation</a> page, which also uses <code>yum update -y</code>, gives me this same error/warning!  Amazon's own example script doesn't work!?  So can anyone answer why A) AWS is not displaying the user data code correctly, and B) why my user data is yielding the errors shown above?  The help is much appreciated!</p>