discovery.seed_hosts in elasticsearch AWS EC2 with ELB - elasticsearch

I have EC2 instances under an ELB. Whenever a new instance is started an ip address is assigned dynamically.
I have added the ELB DNS name, but it is referring the ip addresses from Network Interfaces tagged to the ELB. But I need to add the ec2 instance ip address.
So how do I add the new ip address in discovery.seed_hosts in elasticsearch without manual intervention?
Note:- I am looking for a way other than ec2 discovery plugin

I have used aws cli command to fetch the IP's from AWS ELB. Added the following script to my .sh file
export ELASTIC_INSTANCE_IPS=$(aws ec2 describe-instances --filters file://filters.json --query "Reservations[*].Instances[*].PrivateIpAddress" --region ${aws_region} --output text | paste -sd,)
tee -a elasticsearch.yml << END
discovery.seed_hosts: [$ELASTIC_INSTANCE_IPS]

Related

AWS: Start EC2 Instance with Cloudformation and encrypt BlockDevices with specific KMS Key

When starting EC2 instances via aws cli I can specify a KmsKeyId for BlockDevices.
When starting an EC2 instance via Cloudformation (either directly or via ASG/LaunchConfiguration) this option does not exist.
How can I encrypt the block devices of my EC2 instances started via Cloudformation with a specific KMS Key?
It looks like the chain is:
Instance > [ BlockDeviceMapping ] > Ebs > KmsKeyId

How to get public ip of an EC2 instance from aws CLI by instance id?

I have an instance that I start through aws cli:
aws ec2 start-instances --instance-ids i-00112223333444445
Instance does not have a static public IP. How can I get instance public ip through CLI knowing the ID i-00112223333444445?
Try the following command:
aws ec2 describe-instances --instance-ids $instance_id \
--query 'Reservations[*].Instances[*].PublicIpAddress' \
--output text
If the EC2 instance has a public IP address, this command will return it.
Links:
Details about the query parameter can be found here.
Details about the describe-instances command can be found here.

Cloud9 AWS CLI - how to determine CIDR for security group?

I'm using Cloud9 IDE and AWS CLI to manage EC2 instances. I'm going through the AWS guidance on configuring security groups and trying to determine what CIDR I should use when creating a new security group (http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html)
Here is the sample command from the guidance:
$ aws ec2 authorize-security-group-ingress --group-name devenv-sg --protocol tcp --port 22 --cidr 0.0.0.0/0
Thanks.

Script to attach and detach server from the load balancer in amazon aws

I am using the below Script to attach and detach the server from load balancer
#!/bin/bash
aws elb register-instances-with-load-balancer --load-balancer-name Load-BalancerLoadBalancer --instances i-a3f1446e
aws elb deregister-instances-from-load-balancer --load-balancer-name Load-BalancerLoadBalancer --instances i-a3f1446e
When I am running the script I am getting the error as below
Service elasticloadbalancing not available in region ap-southeast-1b
Service elasticloadbalancing not available in region ap-southeast-1b
Is there any changes I want to make the script working or Is there any alternate script to do the work.
The error says region ap-southeast-1b, but ap-southeast-1b is an Availability Zone, not a Region.
The Region should be ap-southeast-1.
Run aws configure and confirm that your Region is set correctly.
Seems your ELB is set in other regions, add --region in your command, for example, if the ELB is created at us-east-1:
aws elb register-instances-with-load-balancer --load-balancer-name Load-BalancerLoadBalancer --instances i-a3f1446e --region us-east-1
aws elb deregister-instances-from-load-balancer --load-balancer-name Load-BalancerLoadBalancer --instances i-a3f1446e --region us-east-1

Adding another Host to a Cluster in Deis

Is there a procedure for adding another host into an existing cluster? I'm using EC2.
I'm thinking it could be done by using CloudFormation again:
aws cloudformation create-stack \
--template-body "$(<deis.template)" \
--stack-name deis-2 \
--parameters "$(<cloudformation.json)"
Which would need a new stack name. That adds the new host.
Or just launch a new instance with the cli?
aws ec2 run-instances --image-id ami-cfe125b8 --count 1 --instance-type m3.medium --key-name deis --security-groups sg-b7edc3c0,sg-c9edc3be
I'm guessing the host should be in both the coreos and deis security groups? And how does fleet know about the new host?
Then, we need to alter the hosts field?
deis clusters:info <cluster>
deis clusters:update <cluster> hosts=x,y,z
Anything else necessary? Is there another, easier way of doing it?
Since all we're dealing with here is CoreOS, it's completely possible to add new nodes to the cluster. The only requirement that you must do is to apply the cloud-config template that you applied to every other node in the cluster to the new instance. See https://coreos.com/docs/running-coreos/cloud-providers/ec2/ for more info.

Resources