Skip to content

Instantly share code, notes, and snippets.

@simeji
Last active September 16, 2015 17:50
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 simeji/6117a508e902cb9e755d to your computer and use it in GitHub Desktop.
Save simeji/6117a508e902cb9e755d to your computer and use it in GitHub Desktop.
AWS CLI で現在停止中で30日以上前に起動されたインスタンスを取得するワンライナー ref: http://qiita.com/simeji/items/3d680c3a59897700f43c
$ 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}"
[
{
"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"
}
]
$ echo $DATE
>> 2015-08-18
[
{
"InstanceId": "i-dxxxxx2e",
"LaunchTime": "2015-06-20T09:32:45.000Z",
"PrivateIpAddress": "172.30.0.79"
}
]
$ echo $DATE
2015-07-19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment