Created
December 9, 2015 11:00
-
-
Save rriifftt/101944bc0c5c76435382 to your computer and use it in GitHub Desktop.
AWS DataPipeline の ShellCommandActivity を使って特定のタグを持つインスタンスを日次停止する ref: http://qiita.com/satoshi_iwashita/items/992f9a5166703322e478
This file contains 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
#!/bin/bash | |
sudo yum update aws-cli -y | |
AWS="/usr/bin/aws --region ap-northeast-1" | |
ids=$(${AWS} ec2 describe-instances --filters \\ | |
"Name=tag:dont_stop,Values=False" \\ | |
"Name=instance-state-code,Values=16" \\ | |
--query 'Reservations[].Instances[].InstanceId' \\ | |
--output text) | |
if [ -z "${ids}" ]; then | |
echo "nothing running instance." | |
else | |
echo "stop instances ids -> ${ids}" | |
${AWS} ec2 stop-instances --instance-id ${ids} \\ | |
&& echo "complete ec2-auto-stop." | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment