-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# AWS tools | ||
|
||
Some specialised tools to avoid pulling boto3 | ||
|
||
* `elb`: ELB classic only (no ALB). Given a name returns the zone53 record associated with the ELB, including scheme (https returned if both available) and port. | ||
* `elb-name`: Both ELB classic and ALB. Given a name, returns route53 record associated with the ELB. Does not include scheme or port as it doesn't check listeners. | ||
* `s3-download`: Download a single file from s3 | ||
* `ec2-ip-from-name`: Given an EC2 name, list up to `-max-results` IPs associated with instances with that name (default is 1). | ||
* `ecs`: Run a task definition |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/elbv2" | ||
"github.com/aws/aws-sdk-go/service/route53" | ||
) | ||
|
||
func main() { | ||
|
||
loadBalancerName := flag.String("name", "", "Name of the load balancer") | ||
region := flag.String("region", "eu-west-1", "AWS region") | ||
flag.Parse() | ||
|
||
if len(*loadBalancerName) < 1 { | ||
fmt.Println("Missing load balancer name") | ||
os.Exit(1) | ||
} | ||
|
||
config := aws.Config{Region: aws.String(*region)} | ||
session := session.New(&config) | ||
|
||
elb_svc := elbv2.New(session) | ||
params := &elbv2.DescribeLoadBalancersInput{ | ||
Names: []*string{aws.String(*loadBalancerName)}, | ||
} | ||
resp, err := elb_svc.DescribeLoadBalancers(params) | ||
|
||
if err != nil { | ||
fmt.Println(err.Error()) | ||
os.Exit(3) | ||
} | ||
|
||
l := len(resp.LoadBalancers) | ||
if l < 0 { | ||
fmt.Println("No load balancer found") | ||
os.Exit(2) | ||
} | ||
|
||
dnsName := *resp.LoadBalancers[0].DNSName | ||
dnsNameDot := fmt.Sprintf("%s.", dnsName) | ||
route53_svc := route53.New(session) | ||
|
||
zones, err := route53_svc.ListHostedZones(&route53.ListHostedZonesInput{}) | ||
|
||
if err != nil { | ||
fmt.Println(err.Error()) | ||
os.Exit(3) | ||
} | ||
for _, hostedZone := range zones.HostedZones { | ||
zoneId := hostedZone.Id | ||
|
||
records, err := route53_svc.ListResourceRecordSets(&route53.ListResourceRecordSetsInput{HostedZoneId: zoneId}) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
break | ||
} | ||
for _, record := range records.ResourceRecordSets { | ||
if record.AliasTarget == nil || record.AliasTarget.DNSName == nil { | ||
continue | ||
} | ||
if *record.AliasTarget.DNSName == dnsNameDot { | ||
dnsName = strings.TrimRight(*record.Name, ".") | ||
break | ||
} | ||
|
||
} | ||
} | ||
fmt.Println(dnsName) | ||
} |