title: Boto3 Cli: How to pass the variable content in USERDATA to php script?
body: <p>I need to substitute the server name in the user data with the RDS ENDPOINT.</p>
  
  <p>I can get the RDS endpoint but not sure how to substitute that in the php file properly.</p>
  
  <p>Here is how I get the RDS endpoint:</p>
  
  <pre><code>            instances = source.describe_db_instances(DBInstanceIdentifier=db_instance)
              rds_host = instances.get('DBInstances')[0].get('Endpoint').get('Address')
  </code></pre>
  
  <p>Another way is also:</p>
  
  <pre><code>RDS=aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address"
  </code></pre>
  
  <p>Next I need to pass the RDS variable content to the php script shown below:</p>
  
  <pre><code>            echo "define('DB_SERVER', $RDS);" &gt;&gt; /var/www/html/dbinfo.php
  </code></pre>
  
  <p>Here is what I have.</p>
  
  <pre><code>    UserData="""#!/bin/bash
  
              RDS=aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address"
              echo $RDS &gt; /var/www/html/test.php
  
              echo "&lt;?php phpinfo(); ?&gt;" &gt; /var/www/html/phpinfo.php
              cd /var/www/html
              echo "&lt;?php phpinfo(); ?&gt;" &gt; /var/www/html/hello.php
              echo "&lt;?php " &gt;/var/www/html/dbinfo.php          
  
              echo "define('DB_SERVER', $RDS);" &gt;&gt; /var/www/html/dbinfo.php
  
              echo "define('DB_USERNAME', 'username');" &gt;&gt; /var/www/html/dbinfo.php
              echo "define('DB_PASSWORD', 'pass');" &gt;&gt; /var/www/html/dbinfo.php
              echo "define('DB_DATABASE', 'dbname');" &gt;&gt; /var/www/html/dbinfo.php
              echo "\$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);"&gt;&gt; /var/www/html/dbinfo.php
              echo "if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();"&gt;&gt; /var/www/html/dbinfo.php
              echo "Successfully connected to the RDS instance; $rds_host" &gt;&gt; /var/www/html/dbinfo.php
              echo "?&gt;" &gt;&gt; dbinfo.php
              """
  </code></pre>
  
  <p>Basically, I need to get the content of rds_host and echo it to the line in the php script where $rds_host is shown.</p>
  
  <p>Also tried the following:</p>
  
  <pre><code>    UserData="""#!/bin/bash
              yum update –y
              yum install httpd php mysql php-mysql git -y
              service httpd start
              chkconfig httpd on
              groupadd www
              usermod -a -G www ec2-user
              chown -R root:www /var/www
              chmod 2775 /var/www
              find /var/www -type d -exec chmod 2775 {} +
              find /var/www -type f -exec chmod 0664 {} +
  
              echo "&lt;?php phpinfo(); ?&gt;" &gt; /var/www/html/phpinfo.php
              cd /var/www/html
              echo "&lt;?php phpinfo(); ?&gt;" &gt; /var/www/html/hello.php
  
              $rds_host='aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address"'
              echo "&lt;?php " &gt;/var/www/html/dbinfo.php          
  
              echo "define('DB_SERVER', $rds_host);" &gt;&gt; /var/www/html/dbinfo.php
  
              echo "define('DB_USERNAME', 'username');" &gt;&gt; /var/www/html/dbinfo.php
              echo "define('DB_PASSWORD', 'dbpass');" &gt;&gt; /var/www/html/dbinfo.php
              echo "define('DB_DATABASE', 'dbname');" &gt;&gt; /var/www/html/dbinfo.php
              echo "\$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);"&gt;&gt; /var/www/html/dbinfo.php
              echo "if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();"&gt;&gt; /var/www/html/dbinfo.php
              echo "Successfully connected to the RDS instance; $rds_host" &gt;&gt; /var/www/html/dbinfo.php
              echo "?&gt;" &gt;&gt; dbinfo.php
              """
  </code></pre>
  
  <p>)</p>
  
  <p>and checking the cloud-init-output.log shows:</p>
  
  <pre><code>/var/lib/cloud/instance/scripts/part-001: line 17: =aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address": command not found
  </code></pre>
  
  <p>Cloud-init v. 0.7.6 finished at Mon, 07 May 2018 23:36:15 +0000. Datasource DataSourceEc2.  Up 15.83 seconds</p>