= gossm
A simple tool to list AWS instances by profile, and then execute the aws session-manager connect command.
I needed a tool to utilise the `~/.aws/config` file to launch a session via https://docs.aws.amazon.com/systems-manager/index.html[AWS Systems Manager]
to an instance in the cloud.
Written in Go, this tool allows you to launch the aws cli ssm components.
if you do not set an environment variable for the `AWS_PROFILE` it will interrogate the ones found in `~/.aws/config` and provide you a list to pick from before .
Once the profile is set, it will get a list of the EC2 instances.
usage:
`AWS_PROFILE=<profile_name> gossm`
[source,shell]
----
[1] i-AAAAAAAAAAAAAAAAA svr1.example.com <1>
[2] i-BBBBBBBBBBBBBBBBBB svr2.example.com
[3] i-CCCCCCCCCCCCCCCCCC svr3.example.com
Launch number:> 2 <2>
----
<1> The list of instances to pick from.
<2> The command prompt to enter the number representing the list above.
Once you select the instance, it will launch the session via the command line application, in the following way : `aws --profile <AWS_PROFILE> ssm start-session --target <i-BBBBBBBBBBBBBBBBBB>`
You can further filter the list by specifying tag values, that will eb checked.
eg `gossm prd web` will look for machines tagged with both `prd` and `web` and present you a list of instances.
NOTE: It does not check that the SSM agent is running on these instances.
== AWS Profiles
Not really in scope for this tool, but I have a list of AWS profiles in `~/.aws/config` and the connection credentials are stored in `~/.aws/credentials`
see AWS Documentation for more information on the `~/.aws/*` files.
.Example: ~/.aws/config
[source,shell]
----
[profile SAMPLE-PROFILE] <1>
region = ap-southeast-2 <2>
role_arn = arn:aws:iam::1234567890:role/FullAWSAccess <3>
source_profile = sample-admin-account <4>
----
<1> Name of the profile, used by `gossm`.
<2> The region to use for the profile.
<3> The role to use for the profile. This is the role in the account you want to utilise.
<4> The account from the `~/.aws/credentials` you want to use.
.Example: ~/.aws/credentials
[source,shell]
----
[sample-admin-account] <1>
aws_access_key_id = ABCD... <2>
aws_secret_access_key = ABCD... <3>
----
<1> the name you specify for the config, also used for the connection, eg `gossm sample-admin-acount`
<2> access key from AWS
<3> the secre from AWS
== Simple Install
To grab the latest build from github, run the following command.
`go install github.com/bovinemagnet/gossm@latest`
This will install the latest built version.
IMPORTANT: Pressing ctrl-Z will suspend the gossm process not the process on the remote
== AWS CLI and SSM
Remember to install https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html[AWS CLI] and https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html[AWS SSM] before using this tool.
On arch linux, I ran the following:
=== ArchLinux
.Install AWS CLI
[source, bash]
----
sudo pacman -S aws-cli-v2
----
.Install AWS SSM Plugin
----
git clone https://aur.archlinux.org/aws-session-manager-plugin.git
cd aws-session-manager-plugin
makepkg -sri
----
NOTE: Check the steps, to ensure they match your environemnt.