Skip to content

Instantly share code, notes, and snippets.

@akshendra
Last active December 24, 2019 11:24
Show Gist options
  • Save akshendra/a3f92e578caf6e4e2f0102e448778ab3 to your computer and use it in GitHub Desktop.
Save akshendra/a3f92e578caf6e4e2f0102e448778ab3 to your computer and use it in GitHub Desktop.
Setup ec2 for sending info to cloudwatch
#!/usr/bin/env bash
# Setup for gathering metrices, debian based
required_env='AWS_REGION, MONITOR_DISKS, MACHINE_NAME';
function checkEnv() {
echo "Checking $1"
local val=$(env | grep "$1")
echo $val
if [ -z "$val" ]; then
echo "These env variables are required: $required_env"
exit 1
fi
}
# check if all environment variables are present
checkEnv AWS_REGION
checkEnv MONITOR_DISKS
checkEnv MACHINE_NAME
# Install pip3
sudo apt-get update
sudo apt-get install python3-pip
# Configure aws
echo "Creating aws directory"
mkdir ~/.aws
echo "Adding aws config file"
echo "[default]
region = ${AWS_REGION}" > ~/.aws/config
# Install pip3 stuff
pip3 install --user redis boto3
# Add machine names and other exportable variable
cp ~/.zshrc ~/.zshrc.bkp
echo "export MACHINE_NAME=$MACHINE_NAME" >> ~/.zshrc
echo "export AWS_REGION=$AWS_REGION" >> ~/.zshrc
# sourcing it all
source ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment