title: How to pass files from EC2 to S3 and S3 to EC2 using user data
body: <p>Below code is shell script file which is created for creating New AWS EC2 instance with user data.</p>
  
  <p>In this code, it creates new instance and executes cd /home and creates dirctory named with pravin.</p>
  
  <p>But after that it neither downloads file from s3 nor uploads to S3.</p>
  
  <p>What is wrong with that code(s3cmd get and put code).</p>
  
  <p>And AMI used for this is pre-configured with AWS EC2 command line API and s3cmd.</p>
  
  <pre><code>str=$"#! /bin/bash"
  str+=$"\ncd /home"
  str+=$"\nmkdir pravin"
  str+=$"\ns3cmd get inputFile.txt s3://bucketName/inputFile.txt"
  str+=$\ns3cmd put resultFile.txt s3://bucketName/outputFile.txt"
  
  echo "$str"|base64
  ud=`echo -e "$str" |base64`
  echo "$ud"
  
  export JAVA_HOME=/usr
  export EC2_HOME=/home/ec2-api-tools-1.6.7.1
  export PATH=$PATH:$EC2_HOME/bin
  export AWS_ACCESS_KEY=accesskey
  export AWS_SECRET_KEY=secretkey
  if [ "$3" = "us-east-1" ]
  then
   ec2-run-instances ami-fa791231 -t t1.micro -g groupName -n 1 -k Key1 -d "$ud" --region $3 --instance-initiated-shutdown-behavior terminate
  else
      echo "Not Valid region"
  fi
  </code></pre>