/ Meteor

Working with REST APIs on Meteor

I have an IP address that changes everyday. One of my electron app has the IP hardcoded, and I need to manually update the IP everyday to get this working.

Doing this over multiple systems is both time consuming and irritating!

I want to hack a way to query the IP via a REST call and then use it in my app!

To do this, I simply decided to open up a collection on my meteor app: https://xeon.santoshsrinivas.com/

To work with the REST API using a terminal client, I will use: HTTPie – command line HTTP client

I created a collection called KVs and opened it up for REST calls using kahmali/meteor-restivus: REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus

Now, easy to query using:

# GET
http "http://xeon.santoshsrinivas.locd/api/kvs"

http "https://xeon.santoshsrinivas.com/api/kvs"

# INSERT
echo '{"key": "ip", "value": "127.0.0.2"}' | http POST https://xeon.santoshsrinivas.com/api/kvs

# UPDATE
# Create a json through bash
# https://stackoverflow.com/questions/51736614/piping-echo-output-into-xargs
printf 'Hello Hola Bonjour' | xargs -d' ' -I _ echo '{"value": "_"}'

# Credit: [(No Title)](https://github.com/kahmali/meteor-restivus#patch)
curl -X PATCH http://xeon.santoshsrinivas.locd/api/kvs/avofQWJ7mZAe9Gh5f -d "value=127.0.0.2"

# UPDATE
echo '{"value": "127.0.0.2"}' | http PATCH http://xeon.santoshsrinivas.locd/api/kvs/avofQWJ7mZAe9Gh5f

######################End of Trials######################

# WORKS on Xeon
aws ec2 describe-instances --instance-ids $instance_id --filter Name=instance-state-name,Values=running --query "Reservations[*].Instances[*].PublicIpAddress" --output=text | xargs -d' ' -I _ echo '{"value": "_"}'

# Had to remove new line as mentioned at https://unix.stackexchange.com/a/57129
aws ec2 describe-instances --instance-ids $instance_id --filter Name=instance-state-name,Values=running --query "Reservations[*].Instances[*].PublicIpAddress" --output=text | xargs -I{} echo {} | tr -d '\n' | xargs -d' ' -I _ echo '{"value": "_"}' | http PATCH https://xeon.santoshsrinivas.com/api/kvs/PJ4JS2xitWZ9DnsMo

Direct ssh to a AWS Spot instance!

# Credit: https://unix.stackexchange.com/questions/325940/how-to-ip-throught-piping
aws ec2 describe-instances --instance-ids $instance_id --filter Name=instance-state-name,Values=running --query "Reservations[*].Instances[*].PublicIpAddress" --output=text | xargs -I{} -n1 ssh -tt ghost@{}