go-lambda-cleanup

command module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 1 Imported by: 0

README

go-lambda-cleanup

Test Go version semantic-release

drawing

A Golang based CLI for removing unused versions of AWS Lambdas. One binary, no additional dependencies required.

drawing

Installation

go-lambda-cleanup is distributed as a single binary. Download the binary and install go-lambda-cleanup by the binary to a directory in your system's PATH. /usr/local/bin is the recommended path for UNIX/LINUX environments.

VERSION=1.0.4
wget https://github.com/karl-cardenas-coding/go-lambda-cleanup/releases/download/v$VERSION/go-lambda-cleanup-v$VERSION-linux-amd64.zip
unzip go-lambda-cleanup-v$VERSION-linux-amd64.zip 
sudo mv glc /usr/local/bin/

Usage

Usage:
  glc clean [flags]

Flags:
  -c, --count int8   The number of versions to retain from $LATEST-(n) (default 1)
  -h, --help         help for clean

Global Flags:
  -s, --enableSharedCredentials   Leverages the default ~/.aws/credentials file (bool)
  -p, --profile string            Specify the AWS profile to leverage for authentication
  -r, --region string             Specify the desired AWS region to target
  -v, --verbose                   Set to true to enable debugging (bool)

Use "gcl [command] --help" for more information about a command.

To retain 2 version excluding $LATEST

glc clean -r us-east-2 -c 2 -s true -p myProfile
Authentication

go-lambda-clean utilizes the default AWS Go SDK credentials provider to find AWS credentials. The default provider chain looks for credentials in the following order:

  1. Environment variables.

  2. Shared credentials file.

  3. If your application uses an ECS task definition or RunTask API operation, IAM role for tasks.

  4. If your application is running on an Amazon EC2 instance, IAM role for Amazon EC2.

Shared File Example

If ~/.aws/config and ~/.aws/config is setup for the AWS CLI then you may leverage the existing profile configuration for authentication.

$ export AWS_PROFILE=sb-test
$ glc clean -r us-west-2 -s true
INFO[03/05/21] Scanning AWS environment in us-west-2
INFO[03/05/21] ............

Alternatively, the --profile flag may be used.

$ glc clean -r us-west-2 -s true -p myProfile
INFO[03/05/21] Scanning AWS environment in us-west-2
INFO[03/05/21] ............
Environment Variables

Static credentials may be also be used to authenticate into AWS.

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_SESSION_TOKEN (optional)

$ export AWS_ACCESS_KEY_ID=YOUR_AKID
$ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
$ export AWS_SESSION_TOKEN=TOKEN
$ glc clean -r us-west-2
2021/03/04 20:42:46 Scanning AWS environment in us-west-2.....
2021/03/04 20:42:46 ............

Compile

If you want to complile the binary, clone the project to your local system. Ensure you have Go 1.16 installed.

git clone git@github.com:karl-cardenas-coding/go-lambda-cleanup.git
go build -o glc

Proxy

The tool supports network proxy configurations and will honor the following proxy environment variables.

  • HTTP_PROXY,
  • HTTPS_PROXY
  • NO_PROXY

The environment values may be either a complete URL or a "host[:port]", in which case the "http" scheme is assumed. An error is returned if the value is a different form.

$ export HTTPS_PROXY=http://proxy.example.org:9000

$ glc clean -r us-west-2
2021/03/04 20:42:46 Scanning AWS environment in us-west-2.....
2021/03/04 20:42:46 ............

Contributing to go-lambda-cleanup

For a complete guide to contributing to go-lambda-clean, see the Contribution Guide.

Contributions to go-lambda-cleanup of any kind including documentation, organization, tutorials, blog posts, bug reports, issues, feature requests, feature implementations, pull requests, answering questions on the forum, helping to manage issues, etc.

FAQ

Q: On MacOS I am unable to open the binary due to Apple not trusting the binary. What are my options?

A: You have two options.

Option A is to clone this project and compile the binary. Issue go build -o glc, and the end result is a binary compatible for your system. If you still encounter issues after this, invoke the code signing command on the binary codesign -s -

Option B is not recommended but I'll offer it up. You can remove the binary from quarantine mode.

xattr -d com.apple.quarantine /path/to/file

AWS Credentials Configuration

Golang Cobra CLI Framework

AWS Go SDK Credentials

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL