From 9c675dde744c14cdfed341b96c6d72c2fd584a5d Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Fri, 2 Sep 2022 09:07:21 +0200 Subject: [PATCH] aws sessionmanager ssm for TRAMP Signed-off-by: Andreas Gerler --- bba.org | 79 ++++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/bba.org b/bba.org index 9354347f..0484102e 100644 --- a/bba.org +++ b/bba.org @@ -3631,6 +3631,39 @@ Right from [[https://gist.github.com/etherald/dcdcf579751c75a2c796][gisthub]]: (require 'ipcalc) #+END_SRC +* AWS sessionmanager ssm +[2022-08-11 Thu 10:02] + +Somebody decided to replace ssh with [[https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html][AWS Session Manager]] +As a heavy user of Emacs TRAMP i was not very happy with that. + +In the beginning I was using [[https://github.com/xen0l/aws-gate][aws-gate]]. +With more changes in our environment this stopped working for me. +After I wrote my own wrapper for the aws cli command - [[https://github.com/baron42bba/ec2-connect][ec2-connect]] - +everything was good again. + +#+begin_src elisp + (require 'tramp) + (eval-after-load "tramp" + '(progn + (add-to-list 'tramp-methods + '("ssm" + (tramp-login-program "ec2-connect") + (tramp-login-args (("--name")("%h") ("2>/dev/null"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (tramp-set-completion-function "ssm" tramp-completion-function-alist-ssh))) + +#+end_src + +Now we can again do strange, dark org-babel magic like: + +#+begin_src org :eval never + ,#+begin_src sh :dir /ssm:host01|sudo:host01: + date + ,#+end_src +#+end_src * [[http://www.emacswiki.org/emacs/RecentFiles][RecentFiles]] @@ -5356,52 +5389,6 @@ Check a AWS Cloudformation template with [[https://github.com/awslabs/cfn-python (define-key yaml-mode-map (kbd "C-c C-l") 'bba-aws-cfn-lint) #+END_SRC -* aws sessionmanager -[2020-02-20 Thu 15:22] - -Somebody decided to replace ssh with [[https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html][AWS Session Manager]] -As a heavy user of Emacs TRAMP i was not very happy with that. -In the end it turned out to be easy. - -ssm doesn't support hostnames. just strange instance ids. -who can remmber those? -Luckily i am not the only one with a bad memory. -[[https://github.com/xen0l/aws-gate][aws-gate]] to the rescue! - -Now we can run commands like - -#+begin_src sh :eval never - aws-gate session hostname -#+end_src - -if those are configured in your aws-gate config file you don't have to -define aws account or region either. -Based on the telnet configuration (they both have similar -capabilities) I wrote this one: - -#+begin_src elisp :eval never :tangle no - (require 'tramp) - (eval-after-load "tramp" - '(progn - (add-to-list 'tramp-methods - '("ssm" - (tramp-login-program "ec2-connect") - (tramp-login-args (("--name")("%h") ("2>/dev/null"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) - (tramp-set-completion-function "ssm" tramp-completion-function-alist-ssh))) - -#+end_src - -Now we can again do strange, dark org-babel magic like: - -#+begin_src org :eval never - ,#+begin_src sh :dir /ssm:host01|sudo:host01: - date - ,#+end_src -#+end_src - * terraform [2016-09-02 Fri 14:57] -- 2.47.3