Simple AWS utilities packaged as a standalone binary

AWS Utils

This repository contains a simple CLI utility with a number of useful sub-commands implemented for working with AWS

Installation

If you the golang development tools installed upon your host, and you're running a recent version, you should be able to download and install via:

go install github.com/skx/aws-utils@latest

Or, after having cloned this repository to your system, you can build from source with a simple:

go build .
go install .

If you don't wish to build from source you should be able to find precompiled binaries for several operating systems upon our releases page

The binary contains embedded support for bash-completion, to enable this add the following to your bash startup-file:

source <(aws-utils bash-completion)

Common Features

All of the commands accept the use of AWS credentials in the way you'd expect, be it from ~/.aws/credentials or via the use of environmental-variables:

  • AWS_SECRET_ACCESS_KEY
  • AWS_ACCESS_KEY_ID
  • AWS_SESSION_TOKEN
    • For the cases when you're using assume-role.
  • AWS_REGION
    • The region to use.

This is documented in the Golang SDK page:

Many of the utilities also allow you to operate the same functionality upon an arbitrary number of AWS roles. In that case you'd specify the path to a file containing roles to assume, via the -roles argument.

For example:

$ aws-utils csv-instances -roles=/path/to/roles

The format of the file is one-role per line, such as:

arn:aws:iam::123457000001:role/foo-AdministratorAccessFromInt-1ABCDEFGHIJKL
arn:aws:iam::123457000002:role/foo-AdministratorAccessFromInt-2ABCDEFGHIJKL
arn:aws:iam::123457000003:role/tst-AdministratorAccessFromInt-3ABCDEFGHIJKL
arn:aws:iam::123457000004:role/tst-AdministratorAccessFromInt-4ABCDEFGHIJKL

# Lines prefixed with "#" are comments, and are ignored (as are empty-lines).

SubCommands

The following sub-commands are available:

csv-instances

Export a simple CSV-based list of running instances:

  • Account ID
  • Instance ID
  • Instance Name
  • AMI ID
  • Age of AMI in days

instances

Show a human-friendly list of all the EC2 instances you have running.

Sample output:

i-01066633e12345567 - prod-fooapp-uk
------------------------------------
	AMI: ami-01234567890abcdef
	Instance type: t3.medium
	Key name: sysadmin1
	Private IPv4: 10.30.44.105
	State: running
	Volumes:
		/dev/sda1	vol-01234567890abcdef	100Gb	gp2	Encrypted:true	IOPs:300

sg-grep

Show security-groups which match a particular regular expression.

$ aws-utils sg-grep 0.0.0.0/0
sg-01234567890abcdef [eu-central-1] - launch-wizard-1 created 2021-11-19T09:39:15.473+02:00
	{
	  Description: "launch-wizard-1 created 2021-11-19T09:39:15.473+02:00",
	  GroupId: "sg-sg-01234567890abcdef",
	  GroupName: "launch-wizard-1",
	  IpPermissions: [{
	      FromPort: 22,
	      IpProtocol: "tcp",
	      IpRanges: [{
	          CidrIp: "0.0.0.0/0",
	          Description: ""
	        }],
	      ToPort: 22
	    }],

whoami

Show the current user, or assumed role.

$ aws-utils whoami
aws-company-devops-prd

Or having assumed a role:

$ aws-utils whoami
aws-company-role-prod-ro
Comments
  • Allow deactivation/deletion of AWS access-keys

    Allow deactivation/deletion of AWS access-keys

    Hello,

    thanks for this neat utility, I mostly use it to rotate AWS access-keys. To that effect, would it be possible to add flags to the rotate-keys command to allow for deactivation/deletion of the previous, now rotated keys?

    Thanks.

  • 21 instances

    21 instances

    Correctly show instances.

    This pull-request closes #21 by correctly iterating over instances, quite how this ever worked (without the -json flag) is a mystery to me.

    Having an unset hostname was a red-herring.

  • Instance names are not always set

    Instance names are not always set

    Receiving an error with empty instances here:

    % AWS_SDK_LOAD_CONFIG=1 aws-utils  instances   
    
    errors running instance dump
    error invoking callback: error rendering template template: output:2:2: executing "output" at <.InstanceName>: can't evaluate field InstanceName in type []instances.InstanceOutput
    Steve.Kemp@Steves-MacBook-Pro .aws % 
    
  • Allow user to remove orphaned keys

    Allow user to remove orphaned keys

    This closes #19, by making it possible to remove the orphaned keys that might remain after generating a new one.

    If there are two keys present before things start then one will be removed as part of the generation of the new one - in that case we'll see an errors when we try to remove that a second time, but that is harmless.

  • Allow more flexible output options

    Allow more flexible output options

    This pull-request will close #17, by allowing more flexible output generation:

    • The default text/template which is used by the instances subcommand can be replaced by the user.
    • The csv-instances sub-command will accept a format-string showing which fields to output.

    In both cases the default(s) remain largely as-is, but this will allow increased flexibility for the user.

  • Allow the user to specify the columns to show for csv-instances

    Allow the user to specify the columns to show for csv-instances

    Today I was asked to provide a mapping of "name + IPv4" address for a bunch of accounts. This would have been easier if I could run:

      $ aws-utils csv-instances --fields="name,ipv4"
    

    Of course once I realize this I can also say that the instances and csv-instances are very very similar (which they definitely are). Merging the two commands into one almost makes sense, but I use them for different purposes and it would be nice to keep the simple nature alone.

    To close this issue:

    • Remove the duplication between the two commands, with regard to getting the data at least.
    • Allow the user to specify different fields for the CSV instnace, at least.
      • Ideally a template for the instances subcommand too.

    No changes to the default behaviour from the end-user perspective though, even if they gain the ability to change the formatting/templates.

  • 13 stacks

    13 stacks

    Update the stacks command such that we report stacks correctly.

    It was possible if a stack had been deleted, then a new stack created with the same name, that we'd fail to show it as being present (unless -all was added).

    This is because the ordering of the AWS output was random an we only maintained a map of name => state, rather than name => []state.

    This closes #13.

  • The `stacks` sub-command sometimes misses stacks

    The `stacks` sub-command sometimes misses stacks

    When a stack is present in multiple states it might get excluded.

    • Imagine you create a stack, then delete it.
    • Later you create a stack with the same name.

    This results in two stacks in the list-stack output :

    • One in DELETE_COMPLETE state
    • One in CREATE_COMPLETE state

    Depending on the random ordering this might get excluded. We need to build/maintain a list of the stack-stats not a simple key=>value hash, which will overwrite the stack-details.

  • rotate-keys trashes other profiles

    rotate-keys trashes other profiles

    This configuration file is fine:

    wc41 ~ $ cat ~/.aws/credentials 
    [default]
    aws_access_key_id=1234...
    aws_secret_access_key=abc...
    

    But the moment you have other profiles present as well things break:

     $ cat ~/.aws/credentials 
    [default]
    aws_access_key_id=1234..
    aws_secret_access_key=abc..
    
    [tmp]
    aws_secret_access_key=124.
    aws_access_key_id=blah
    aws_session_token=secret
    

    Specifically the values of all the keys get updated, not just the first one.

    I guess we just replace the first value, not all the values, and that will solve this.

  • 9 callback approach

    9 callback approach

    This pull-request closes #9, by moving towards a callback-based solution.

    We use a helper to define a callback function, and that is either invoked once for the single (default) AWS account, or called once for each role specified in the role-file.

  • Simplify implementation of role-based commands

    Simplify implementation of role-based commands

    Several of our commands now operate either on the main AWS account, or a set of roles assumed from it:

    • csv-instances
    • instances
    • sg-grep

    Rather than duplicating all the code create a helper which does that once, and triggers a callback into the sub-command for the handling.

Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.
Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

tutor-pet API Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure. Macro architecture: Code architecture: Pre-Re

Aug 17, 2022
Integrate AWS EKS Anywhere cluster with AWS Services
 Integrate AWS EKS Anywhere cluster with AWS Services

This article provides step-by-step instruction on integrating AWS EKS Anywhere with AWS Services so the applications running on customer data center can securely connect with these services.

Mar 6, 2022
Apis para la administracion de notifiaciones, utilizando servicios como AWS SNS y AWS SQS

notificacion_api Servicio para envío de notificaciónes por difusión en AWS SNS Especificaciones Técnicas Tecnologías Implementadas y Versiones Golang

Jan 7, 2022
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
A package for access aws service using AWS SDK for Golang

goaws ?? A package for access aws service using AWS SDK for Golang Advantage with goaws package Example for get user list IAM with AWS SDK for Golang

Nov 25, 2021
Aws-parameter-bulk - Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Par

Oct 18, 2022
Feb 7, 2022
Aws-cognito-demo-go - Source code for AWS Cognito in Go

AWS Cognito Demo in Go Source code for YouTube series, AWS Cognito in Go - https

Dec 10, 2022
Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

May 7, 2022
Aws-cdk-go-examples - Example projects using the AWS CDK by Golang

aws-cdk-go-examples Example projects using the AWS CDK by Golang Useful commands

Nov 24, 2022
Utilcanvas is a package which provides some utilities to interface with the Canvas LMS Api.

Utilcanvas Utilcanvas is a package which provides some utilities to interface with the Canvas LMS Api. Example usage c := utilcanvas.NewClient("https:

Dec 21, 2022
GitHub Utilities for managing classroom repositories.

ghutil GitHub Utilities for bulk operations. Requirements A ghutil.toml configuration file is needed in the working directory. It should have entries

Dec 21, 2021
This package includes various utilities and extensions for your Go code.

Go utilities This package includes various utilities and extensions for your Go code. Inspired by lodash Install go get github.com/murat/go-utils@mast

May 11, 2022
Simple tool to search tagged resources between all AWS resouces

Welcome to Cloud Inventory Tags ?? Simple tool to search tagged resources around all AWS Account Installation MacOS / OSX

Jan 26, 2022
Freaking simple AWS Reserved Instance and Usage coverage report
Freaking simple AWS Reserved Instance and Usage coverage report

richeck This tool allows you to simply see the EC2 and ElastiCache nodes you have reserved on amazon. Motivation: How many instances are currently res

Oct 17, 2021
A simple implementation to upload file to AWS S3

A simple implementation to upload file to AWS S3.

Nov 19, 2021
Simples3 : Simple no frills AWS S3 Library using REST with V4 Signing

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 30, 2021
An implementation of a simple RESTful API in Golang on AWS infrastructure.

go-api An implementation of a simple RESTful API in Golang on AWS infrastructure. Tech Stack Serverless framework Go language AWS API Gateway AWS Lamb

Dec 25, 2021
Mrrobot - A simple greetings bot for Slack that uses events api and hosted on AWS Lambda

Mr. Robot a greeter bot for your slack community build_docker

Aug 21, 2022