Created
April 25, 2018 07:22
-
-
Save genert/1f7ae3bf72ec3313d5881e527f558605 to your computer and use it in GitHub Desktop.
AWS Lambda Consul service with KVs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# enable fail-fast | |
set -e | |
# enable trace | |
set -x | |
CONSUL_IP="xxxxxxx" | |
CONSUL_BASE_URL="http://${CONSUL_IP}:8500/v1" | |
http_put() { | |
curl -sS -X PUT -d "${2:?undefined data}" "${1:?undefined url}" > /dev/null | |
} | |
# Key/value HTTP endpoint | |
# https://www.consul.io/docs/agent/http/kv.html | |
consul_store() { | |
http_put "$CONSUL_BASE_URL/kv/${1:?undefined key}" "${2:?undefined value}" | |
} | |
# Catalog HTTP endpoint | |
# https://www.consul.io/docs/agent/http/catalog.html | |
consul_register() { | |
http_put "$CONSUL_BASE_URL/catalog/register" "${1:?undefined service}" | |
} | |
# =========== | |
# = AWS Lambda file parser | |
# =========== | |
consul_register '{ | |
"Datacenter": "local", | |
"Node": "us-east-1.amazonaws.com", | |
"Address": "us-east-1.amazonaws.com", | |
"Service": {"Service": "lambda-file-parser", "Port": 3306} | |
}' | |
consul_store 'auth/lambda-file-parser/username-for/some-service' 'xxxxx' | |
consul_store 'auth/lambda-file-parser/secret-for/xxxxx' 'xxxxx' | |
printf 'Consul registration done\n!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment