I want to get the ELB name from inside the EC2 instance.
I can do a aws elb describe-load-balancers but this needs the ELB name as input.
I want do it reverse - I know the EC2 instance details from EC2 metadata and want to find the ELB name so that I can append to a file.
The command aws elb describe-load-balancers doesn't need the elb name. It will list all the elbs you have. Then you can parse the output JSON and get which instances are attached to every ELB. I don't know if this is your case, but you can find which elb your instance is attached, and then grab the elb name.
Regards
Related
I am trying to create a VPC where provisioning of EC2 instances is going to be automated, but each instance is going to be assigned a public dns of "ec2-{public-ip}.{region}.compute.amazonaws.com" and a private dns of "ip-{private-ip}.me-south-1.compute.internal". What I want here is to be able to use my own domain (using Route53) to make instances get a public dns of something like
"instance-id.customdomain.com"
And to keep updating the dns entries on Route53 after each reboot of the EC2 instance.
Is there anyway to accomplish this from within the VPC settings or Route53's? If not, how could such a thing be accomplished?
There is no AWS offered solution to it. You have to create your own scripts to achieve this.
instance-id.customdomain.com -> instance public ip
You can attach an instance profile and add user data to EC2 at launch. It's easily achievable by using some AWS CLI commands. For example, use describe-instances to get the public ip of a particular instance identified by the instance id. Then use change-resource-record-sets to add an A record in route53.
keep updating the dns entries on Route53 after each reboot of the EC2 instance
You can either treat this as part of the EC2 reboot job or check and sync ip with route53 on every OS reboot.
Alternative: Use EIP so you don't need to monitor the public IP change.
I am trying to put my RDS instance behind an elastic loadbalancer. Unfortunately, I am not able to find the RDS in listed instance while creating a target group. I am wondering how to do that, is this possible?
There is a work-around I have done. While creating the target group I have selected IP address instead of the instance id. The IP address is not directly provided by AWS. I ran nslookup command with the domain name of RDS as input to get the IP address. I was successfully able to configure ELB with this approach.
Note: This is not the recommended way, as the IP address of RDS may change, according to the AWS document.
I have created a classic load balancer and auto scaling policy which launch 2 instance successfully; now when I logged in through ssh to one of the load balancer.
ssh -i "mykeypair.pem" ec2-user#my-load-balancer-1222.us-east-1.elb.amazonaws.com
we looged in with the teminla
[ec2-user#ip-10-0-1-86 ~ ] << here this Ip is one of the instance which was created by auto scaling
now I want to check the security-group of the elb from curl http://169.254.169.254/latest/meta-data/security-groups command but it display the instnace security group name not the elb security group.
My question is how can we check the elb security group?
It seems you have SSH'ed into one of the 2 instances behind the load balancer (I doubt you can SSH into the ELB itself), so that's why you're seeing the security group of that instance.
I believe the way to check the ELB's security group is by using the AWS CLI (or one of their SDKs), using the
aws elb describe-load-balancers --load-balancer-name my-load-balancer
You can find more details in the docs
Note: of course, if you wanted to run this command from within the EC2 instance you SSH'ed into, you would need to make sure you have access to make that invocation. See here for more info, on getting set up.
You should not SSH into an instance via a Load Balancer.
An SSH session is persistent -- you wish to continue talking to the same server. This clashes with the concept of a Load Balancer, which distributes traffic across multiple servers.
I am running my application in VPN having a public ELB over 4 nodes, I want to know the ipAddress of all nodes behind that ELB.
You Can Create a CLI Script.
Using the AWS CLI -
Pass the ELB name to describe the LoadBalancer.
aws elb describe-load-balancers --load-balancer-name sarat-load-balancer
It returns a set of instance id running behind the load balancer in Json Format.
Extract the Instance ids and Put them in a Loop.
Pass the Instance ids to describe the Instance.
aws ec2 describe-instances --instance-ids i-xxxxxxxxxx
It returns a set of data with public ips of the instances in Json Format.
You can do the same with SDK.
Hope It Helps.. :)
I have deployed a webservice application in Amazon EC2 and has associated an Elastic IP address with the same. Our mobile interact with this webservice using elastic IP. Now I want to implemented auto scaling on the EC2.
But what I am not sure is how does my single elastic ip be associated with multiple EC2 instances as it scales up? Is this possible. Please guide.
An elastic IP address is only ever associated with a single EC2 instance.
If you want to start auto-scaling your application, then you need to put a load balancer in front of your EC2 instances. That can be AWS Elastic Load Balancer, or some other.
Users would connect to the Load Balancer, and the Load Balancer would forward requests to the underlying EC2 instances.
Assuming you use an Elastic Load Balancer, you'll need to drop the Elastic IP address since ELB cannot use them. Instead, you'll create a CNAME (or Alias if your DNS is using Route 53) to the ELB.
No that's not possible. You probably need to be using an Elastic Load Balancer.
With EC2 & Auto scaling, You need using user data in EC2 to Auto Attach Elastic IP to EC2 Instance For Auto scaling
#!/bin/bash
aws configure set aws_access_key_id "XYZ..."
aws configure set aws_secret_access_key "ABC..."
aws configure set region "ap-..."
aws ec2 associate-address --instance-id "$(curl -X GET "http://169.254.169.254/latest/meta-data/instance-id")" --public-ip your_elastic_IP
Note: you should create new user & IAM have only permission associate-address to create/get aws key
Hope it be help you :)