I am launching an EC2 instance and when the instance is launched for the first time, I am trying to run a few commands and set a few environment variables using UserData. The commands that I have added to the UserData:
#!/bin/bash
sudo apt-get -y update
sudo apt-get install gcc g++ build-essential
sudo apt install -y zip awscli python3-pip python3.7 python3.7-dev
python3.7 -m pip install --upgrade pip
pip3 install virtualenv
mkdir anomaly-detection
export DB_ADAPTER=postgresql+psycopg2
export DB_USER=dummy_user
export DB_PASSWORD=dummy_pwd
export DB_HOST=ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com
export DB_NAME=dummy_db
After the instance is launched, I launch the instance and when I check for the environment variables, they aren't set, also the mkdir command wasn't run. (So I am assuming that all the commands haven't been executed).
What is the mistake I am doing?
. ./script/location/script.sh. Notice the leading dot.. ./script/location/script.shcommand in the userdata?/var/log/cloud-init-output.logand see which errors are there, if any. Which Linux distribution are you using?