title: aws ec2 - aws command not found when running user data
body: <p>My aim is to launch an instance such that a start-up script is triggered on boot-up to download some configuration files stored in AWS S3. Therefore, in the start-up script, I am setting the S3 bucket details and then, triggering a <code>config.sh</code> where <code>aws s3 sync</code> does the actual download. However, the <code>aws</code> command does not work - it is not found for execution.</p>
  
  <h3>User data</h3>
  
  <p>I have the following user data when launching an EC2 instance:</p>
  
  <pre><code>#!/bin/bash
  # Set command from https://stackoverflow.com/a/34206311/919480
  set -e -x
  export S3_PREFIX='bucket-name/folder-name'
  /home/ubuntu/app/sh/config.sh
  </code></pre>
  
  <p>The AWS CLI was installed with <code>pip</code> as described in the <a href="https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-linux.html" rel="nofollow noreferrer">documentation</a>.</p>
  
  <h3>Observation</h3>
  
  <p>I think, the user data script is run with <code>root</code> user ID. That is why, in the user data I have <code>/home/ubuntu/</code> because <code>$HOME</code> did not resolve into <code>/home/ubuntu/</code>. In fact, the first command in <code>config.sh</code> is <code>mkdir /home/ubuntu/csv</code> which creates a directory with owner as <code>root</code>!</p>
  
  <p>So, would it be right to conclude that, the user data runs under <code>root</code> user ID?</p>
  
  <h3>Resolution</h3>
  
  <p>Should I use <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html" rel="nofollow noreferrer">REST API</a> to download?</p>