I am writing a script in YAML to run an Ubuntu web server on Amazon Web Services. I want to acquire metadata, (specifically the public DNS name and the current AWS region) and append that information onto an html file that is already present.
I'm not sure how to implement a way to both grab the metadata and append it to the html file. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval shows the command and URL that I am supposed to use to get the metadata I need, but I am unsure of how to write it into my code so that those details get written to my index.html file.
UserData:
'Fn::Base64': |
#!/bin/bash -x
# set timezone
timedatectl set-timezone America/New_York
# install and setup apache
apt-get update
apt-get install -y nginx
cd /var/www/html
echo "<title>User #1</title> <h1>You are User #1</h1> <h2></h2>" > index.html
service nginx start
Right now, when the html file is displayed, "User #1" is in the title and "You are User #1" on the page. I want to know how to make the Public DNS and AWS region appear below that.