Following definition of Amazon Elastic Load Balancing is taken from AWS documentation for ELB. Refer here for more information – “Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones. Elastic Load Balancing offers three types of load balancers that all feature the high availability, automatic scaling, and robust security necessary to make your applications fault tolerant.”
Below script will help you to generate an inventory of ELB instances in your Account. I included properties you might need as part of ELB inventory. However, feel free to add your stuff as require. Following script assumes you have already setup your AWS credentials and AWS Powershell SDK to run this script on your working system. If you face any issue setting those, please refer following documents to set those:
- https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html
- https://aws.amazon.com/powershell/
Let me know if this is helpful!
$date = Get-Date -UFormat "%m-%d-%Y"
$currentDir = $(Get-Location).Path
$oFile = "$($currentDir)\ELB_Details_$($date).csv"
if(Test-Path $oFile){Remove-Item $oFile -Force}
"ELB Name,CanonicalHostedZone Name,CanonicalHostedZoneName ID,Creation Time,HealthCheck, Instances,Scheme,Security Groups,Subnets,VPCId" | Out-File $oFile -Append -Encoding ascii
Get-ELBLoadBalancer | ForEach-Object{
$elbName = $hostedZoneName = $hostedZoneNameId = $createDate = $healthCheck = $instances = $scheme = $securityGroups = $subnets = $vpcId = ""
$elbName = $_.LoadBalancerName
$hostedZoneName = $_.CanonicalHostedZoneName
$hostedZoneNameId = $_.CanonicalHostedZoneNameID
$createDate = $_.CreatedTime
$healthCheck = $_.HealthCheck
if(![string]::IsNullOrEmpty($_.Instances)){
$instances = $_.Instances.instanceId -join ";"
}
$scheme = $_.Scheme
$securityGroups = $_.SecurityGroups -join ";"
$subnets = $_.Subnets -join ";"
$vpcId = $_.VPCId
#Here we have associated Tags with the ELB. You may use it to further parse Tags.
$tags = Get-ELBResourceTag -LoadBalancerName $elbName
"$elbName,$hostedZoneName,$hostedZoneNameId,$createDate,$healthCheck, $instances,$scheme,$securityGroups,$subnets,$vpcId" | Out-File $oFile -Append -Encoding ascii
}
Exit
Before running aws scripts, set up your aws credentials following provided documentation above.
Download above script and save it with a .ps1 file extension.After that, open aws powershell sdk tool console. Once, it is open run the script saved previously.
Once the script execution completes, it will generate a CSV file output like below screenshot: