From 8e88d70a52b0ebc270127124b6fc0fd845e5ac74 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:14:36 -0400 Subject: [PATCH] add ec2 list and ssm session fzf script also fix lint issues on home packages --- modules/common/shell/bash/scripts/aws-ec2.sh | 21 +++++++++ modules/darwin/utilities.nix | 49 ++++++++++++-------- 2 files changed, 50 insertions(+), 20 deletions(-) create mode 100755 modules/common/shell/bash/scripts/aws-ec2.sh diff --git a/modules/common/shell/bash/scripts/aws-ec2.sh b/modules/common/shell/bash/scripts/aws-ec2.sh new file mode 100755 index 0000000..5410ed0 --- /dev/null +++ b/modules/common/shell/bash/scripts/aws-ec2.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Retrieve list of AWS instances +# Use enter to jump into their sessions with SSM + +# Specify AWS_PROFILE and AWS_REGION before running this script + +aws ec2 describe-instances | + jq -r \ + '.Reservations[] + | .Instances[] + | .InstanceId + " - " + + (.PrivateIpAddress // "n/a") + " - " + + (.PublicIpAddress // "n/a") + " - " + + (.Tags | from_entries | .Name // "n/a")' | + fzf \ + --height 100% \ + --layout reverse \ + --header $'Press Enter to start SSM session\nInstance ID - Private IP - Public IP - Name' \ + --preview "aws ec2 describe-instances --instance-ids \"\$(echo {} | cut -d' ' -f1)\" | jq -r '.Reservations[].Instances[0]'" \ + --bind "enter:become(aws ssm start-session --target \$(echo {} | cut -d' ' -f1))" diff --git a/modules/darwin/utilities.nix b/modules/darwin/utilities.nix index 08971a5..628864c 100644 --- a/modules/darwin/utilities.nix +++ b/modules/darwin/utilities.nix @@ -15,29 +15,38 @@ home-manager.users.${config.user} = lib.mkIf pkgs.stdenv.isDarwin { - home.packages = with pkgs; [ - visidata # CSV inspector - dos2unix # Convert Windows text files - inetutils # Includes telnet - youtube-dl # Convert web videos - pandoc # Convert text documents - mpd # TUI slideshows - mpv # Video player - gnupg # Encryption - awscli2 - ssm-session-manager-plugin - awslogs - google-cloud-sdk - vault-bin - consul - noti # Create notifications programmatically - ipcalc # Make IP network calculations - teams - (writeShellApplication { + home.packages = [ + pkgs.visidata # CSV inspector + pkgs.dos2unix # Convert Windows text files + pkgs.inetutils # Includes telnet + pkgs.youtube-dl # Convert web videos + pkgs.pandoc # Convert text documents + pkgs.mpd # TUI slideshows + pkgs.mpv # Video player + pkgs.gnupg # Encryption + pkgs.awscli2 + pkgs.ssm-session-manager-plugin + pkgs.awslogs + pkgs.google-cloud-sdk + pkgs.vault-bin + pkgs.consul + pkgs.noti # Create notifications programmatically + pkgs.ipcalc # Make IP network calculations + pkgs.teams + (pkgs.writeShellApplication { name = "ocr"; - runtimeInputs = [ tesseract ]; + runtimeInputs = [ pkgs.tesseract ]; text = builtins.readFile ../../modules/common/shell/bash/scripts/ocr.sh; }) + (pkgs.writeShellApplication { + name = "ec2"; + runtimeInputs = [ + pkgs.awscli2 + pkgs.jq + pkgs.fzf + ]; + text = builtins.readFile ../../modules/common/shell/bash/scripts/aws-ec2.sh; + }) ]; programs.fish.shellAbbrs = {