This projects aims to ease the configuration of AWS EC2 instances hostname. In particular when they are launched as part of ASGs or fleets.
# Using instance-id method
~$ ahs instance-id
INFO[2018-07-23T11:56:00Z] Found AZ: 'eu-west-1a'
INFO[2018-07-23T11:56:00Z] Computed region : 'eu-west-1'
INFO[2018-07-23T11:56:00Z] Found instance-id : 'i-096bed3161783f000'
INFO[2018-07-23T11:56:00Z] Querying input-tag 'Name' from EC2 API
INFO[2018-07-23T11:56:00Z] Computing hostname with truncated instance-id
INFO[2018-07-23T11:56:00Z] Computed unique hostname : 'myhostname-096be'
INFO[2018-07-23T11:56:00Z] Setting instance hostname locally
INFO[2018-07-23T11:56:00Z] Setting hostname on configured instance output tag 'Name'
# Using sequential method
~$ ahs sequential
INFO[2018-07-23T11:56:00Z] Found AZ: 'eu-west-1a'
INFO[2018-07-23T11:56:00Z] Computed region : 'eu-west-1'
INFO[2018-07-23T11:56:00Z] Found instance-id : 'i-096bed3161783f000'
INFO[2018-07-23T11:56:00Z] Querying input-tag 'Name' from EC2 API
INFO[2018-07-23T11:56:00Z] Computing a hostname with sequential naming
INFO[2018-07-23T11:56:00Z] Computed unique hostname : 'myhostname-1' - Sequential ID : '1'
INFO[2018-07-23T11:56:00Z] Setting instance hostname locally
INFO[2018-07-23T11:56:00Z] Setting hostname on configured instance output tag 'Name'
INFO[2018-07-23T11:56:00Z] Setting instance sequential id (1) on configured tag 'ahs:instance-id'
You can also use a Dockerized version if you prefer :
~$ docker run -it --rm --privileged mvisonneau/ahs <instance-id|sequential>
Have a look onto the latest release page and pick your flavor.
~$ go get -u github.com/mvisonneau/ahs
~$ docker run -it --rm --privileged mvisonneau/ahs
For the following ones, you need to know which version you want to install, to fetch the latest available :
~$ export AHS_VERSION=$(curl -s "https://api.github.com/repos/mvisonneau/ahs/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# Binary (eg: linux/amd64)
~$ wget https://github.com/mvisonneau/ahs/releases/download/${AHS_VERSION}/ahs_${AHS_VERSION}_linux_amd64.tar.gz
~$ tar zxvf ahs_${AHS_VERSION}_linux_amd64.tar.gz -C /usr/local/bin
# DEB package (eg: linux/386)
~$ wget https://github.com/mvisonneau/ahs/releases/download/${AHS_VERSION}/ahs_${AHS_VERSION}_linux_386.deb
~$ dpkg -i ahs_${AHS_VERSION}_linux_386.deb
# RPM package (eg: linux/arm64)
~$ wget https://github.com/mvisonneau/ahs/releases/download/${AHS_VERSION}/ahs_${AHS_VERSION}_linux_arm64.rpm
~$ rpm -ivh ahs_${AHS_VERSION}_linux_arm64.rpm
~$ ahs
NAME:
ahs - Set the hostname of an EC2 instance based on a tag value and the instance-id
USAGE:
ahs [global options] command [command options] [arguments...]
COMMANDS:
instance-id compute a hostname by appending the instance-id to a prefixed/base string
sequential compute a sequential hostname based on the number of instances belonging to the same group
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--dry-run only display what would have been done [$AHS_DRY_RUN]
--input-tag tag tag to use as input to determine the hostname (default: "Name") [$AHS_INPUT_TAG]
--log-level level log level (debug,info,warn,fatal,panic) (default: "info") [$AHS_LOG_LEVEL]
--log-format format log format (json,text) (default: "text") [$AHS_LOG_FORMAT]
--output-tag tag tag to update with the computed hostname (default: "Name") [$AHS_OUTPUT_TAG]
--separator separator separator to use between tag and id (default: "-") [$AHS_SEPARATOR]
--help, -h show help
--version, -v print the version
This method basically takes the output of a tag considered as the base of the hostname, it appends a separator to it (default to -) and finally a truncated value of the instance-id (default to 5 characters).
~$ ahs instance-id -h
NAME:
ahs instance-id - compute a hostname by appending the instance-id to a prefixed/base string
USAGE:
ahs instance-id [command options]
OPTIONS:
--length value length of the id to keep in the hostname (default: 5) [$AHS_INSTANCE_ID_LENGTH]
This method allows you to have sequential hostnames on instances on which you couldn't or haven't configured at the time of provisioning.
~$ ahs sequential -h
NAME:
ahs sequential - compute a sequential hostname based on the number of instances belonging to the same group
USAGE:
ahs sequential [command options]
OPTIONS:
--instance-sequential-id-tag value tag to which output the computed instance-sequential-id (default: "ahs:instance-id") [$AHS_INSTANCE_SEQUENTIAL_ID_TAG]
--instance-group-tag value tag to use in order to determine which group the instance belongs to (default: "ahs:instance-group") [$AHS_INSTANCE_GROUP_TAG]
--respect-azs if instances are provisioned through an ASG, setting this flag it will get the sequential-ids associated to respective azs [$AHS_RESPECT_AZS]
You can have a look at the Makefile in order to see all available options:
~$ make
all Test, builds and ship package for all supported platforms
build-local Build the binaries using local GOOS
build Build the binaries
clean Remove binary if it exists
coverage-html Generates coverage report and displays it in the browser
coverage Generates coverage report
dev-env Build a local development environment using Docker
fmt Format source code
goimports Test code syntax with goimports
gosec Test code for security vulnerabilities
help Displays this help
ineffassign Test code syntax for ineffassign
install Build and install locally the binary (dev purpose)
is-git-dirty Tests if git is in a dirty state
lint Run all lint related tests against the codebase
misspell Test code with misspell
publish-coveralls Publish coverage results on coveralls
release Build & release the binaries
revive Test code syntax with revive
setup Install required libraries/tools for build tasks
sign-drone Sign Drone CI configuration
test Run the tests against the codebase
vet Test code syntax with go vet
Contributions are more than welcome! Feel free to submit a PR.
Content type
Image
Digest
Size
6.2 MB
Last updated
about 4 years ago
docker pull mvisonneau/ahs