CLI (3)


Stop un-tagged instances

After setting up a bastion and getting GitLab runner to autoscale on EC2 spot instances, I noticed that some instances are being started but left un-tagged and probably unused. Those seem to slip through the cracks somehow .. I’m still investigating why that’s happening.
Meanwhile, to avoid paying for those instances, I set up a cron to check for non tagged instances on EC2 and terminate them.

Here’s my bash code using aws-cli

#!/bin/bash
INSTANCES=$(aws ec2 describe-instances \
  --filters "Name=key-name,Values=runner-*" \
            "Name=instance-state-name,Values=running" \
  --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Name`].Value)] | [].[InstanceId]' \
  --output text)
if [ -n "$INSTANCES" ]; then 
  aws ec2 terminate-instances --instance-ids $INSTANCES 
fi

This looks for running instances, with the Key Name runner-* and where the tag Name is not not_null (so null!)

It’s working so far. Will keep on looking for a more permanent solution.

Similar Posts:




Start Firefox Private Browsing Next to Running Session

It’s easy in Chrome, just open a new “incognito” window and you’re set. Firefox however has to switch the whole application into Private Browsing mode. And since it is designed to allow only one copy of the application to access a profile at the same time it is not a trivial matter to just open another window.

So here’s how you do it:

  • First create a new profile using something like the following:
    firefox -no-remote -ProfileManager
  • Then use that profile to start a Private session next to the regular one:
    firefox -no-remote -P newProfileName -private

You could check the firefox command line reference for more information.

Similar Posts:




CLI blogging with Postie (via postie)

Bookmark this category
Another blogging test using the postie plugin

Similar Posts: