Skip to content

Instantly share code, notes, and snippets.

@ambakshi
Last active Aug 29, 2015
Embed
What would you like to do?
Go compiled binary to query an instance for tags vs aws cli.
$ time aws ec2 describe-instances --instance-ids "$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" --query 'Reservations[*].Instances[*].Tags' --output text
Owner amit.bakshi
Billing_Code ops
Name ops-deploy-003
Hostgroup ops-deploy
Megatron_Deployment deploy
real 0m1.016s
user 0m0.321s
sys 0m0.134s
$ time ./ec2-tags
Billing_Code ops
Name ops-deploy-003
Hostgroup ops-deploy
Megatron_Deployment deploy
Owner amit.bakshi
real 0m0.133s
user 0m0.018s
sys 0m0.014s
# with some dynamic libs
$ CGO_ENABLED=1 go build .
$ ldd ec2-tags
linux-vdso.so.1 => (0x00007fff77efc000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b64600000)
libc.so.6 => /lib64/libc.so.6 (0x0000003b64200000)
/lib64/ld-linux-x86-64.so.2 (0x0000003b63e00000)
# no dynamic libs
$ CGO_ENABLED=0 go build .
$ ldd ec2-tags
not a dynamic executable
$ strip ec2-tags
$ ls -alh ec2-tags
-rwxr-xr-x 1 nobody nobody 5.0M Aug 1 11:00 ec2-tags*
$ file ec2-tags
ec2-tags: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
$ ./ec2-tags -p
ec2_tag_name=ops-deploy-003
ec2_tag_hostgroup=ops-deploy
ec2_tag_megatron_deployment=deploy
ec2_tag_owner=amit.bakshi
ec2_tag_billing_code=ops
$ ./ec2-tags -format sh
OWNER=amit.bakshi
BILLING_CODE=ops
NAME=ops-deploy-003
HOSTGROUP=ops-deploy
MEGATRON_DEPLOYMENT=deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment