amazon-web-servicesamazon-ec2aws-clilaunch-configuration

Is there a way to list launch configurations sorted by CreatedTime via aws-cli?


I am finding a way on how to list launch configurations sorted by CreatedTime. When I ran this command below, it does not return the oldest LC:

aws autoscaling describe-launch-configurations --max-items 1

Is there a way for this? Thank you!


Solution

  • You can control the the command's output using a JMESPath expression like this:

    aws autoscaling describe-launch-configurations --query 'reverse(sort_by(LaunchConfigurations, &CreatedTime))'
    

    The previous command will list all launch configurations ordered by descending CreatedTime. If you only want to get the latest launch config based on CreatedTime, add the [0] expression at the end of the command:

    aws autoscaling describe-launch-configurations --query 'reverse(sort_by(LaunchConfigurations, &CreatedTime))[0]'