Last active
September 16, 2015 17:50
-
-
Save simeji/6117a508e902cb9e755d to your computer and use it in GitHub Desktop.
AWS CLI で現在停止中で30日以上前に起動されたインスタンスを取得するワンライナー ref: http://qiita.com/simeji/items/3d680c3a59897700f43c
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
$ ago=30;date -v-${ago}d > /dev/null 2>&1 && DATE=`date -v-${ago}d +%Y-%m-%d` || DATE=`date --date="-${ago} days" +%Y-%m-%d`; aws ec2 describe-instances --filter Name=instance-state-name,Values=stopped --query "Reservations[].Instances[?LaunchTime<='$DATE'][].{InstanceId: InstanceId,PrivateIpAddress: PrivateIpAddress,LaunchTime: LaunchTime}" |
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
[ | |
{ | |
"InstanceId": "i-4xxxxxb5", | |
"LaunchTime": "2015-08-02T16:31:32.000Z", | |
"PrivateIpAddress": "172.31.0.200" | |
}, | |
{ | |
"InstanceId": "i-dxxxxx2e", | |
"LaunchTime": "2015-06-20T09:32:45.000Z", | |
"PrivateIpAddress": "172.31.0.79" | |
} | |
] |
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
$ echo $DATE | |
>> 2015-08-18 |
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
[ | |
{ | |
"InstanceId": "i-dxxxxx2e", | |
"LaunchTime": "2015-06-20T09:32:45.000Z", | |
"PrivateIpAddress": "172.30.0.79" | |
} | |
] |
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
$ echo $DATE | |
2015-07-19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment