Last active
December 24, 2019 11:24
-
-
Save akshendra/a3f92e578caf6e4e2f0102e448778ab3 to your computer and use it in GitHub Desktop.
Setup ec2 for sending info to cloudwatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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