Skip to content

Instantly share code, notes, and snippets.

@rriifftt
Created December 9, 2015 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rriifftt/101944bc0c5c76435382 to your computer and use it in GitHub Desktop.
Save rriifftt/101944bc0c5c76435382 to your computer and use it in GitHub Desktop.
AWS DataPipeline の ShellCommandActivity を使って特定のタグを持つインスタンスを日次停止する ref: http://qiita.com/satoshi_iwashita/items/992f9a5166703322e478
#!/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