Esempio n. 1
0
func listZones() {
	req := route53.ListHostedZonesInput{}
	for {
		// paginated
		resp, err := r53.ListHostedZones(&req)
		fatalIfErr(err)
		for _, zone := range resp.HostedZones {
			fmt.Printf("%+v\n", zone)
		}
		if *resp.IsTruncated {
			req.Marker = resp.NextMarker
		} else {
			break
		}
	}
}
Esempio n. 2
0
func lookupZone(nameOrId string) *route53.HostedZone {
	if isZoneId(nameOrId) {
		// lookup by id
		id := nameOrId
		if !strings.HasPrefix(nameOrId, "/hostedzone/") {
			id = "/hostedzone/" + id
		}
		req := route53.GetHostedZoneInput{
			Id: aws.String(id),
		}
		resp, err := r53.GetHostedZone(&req)
		if err, ok := err.(awserr.Error); ok && err.Code() == "NoSuchHostedZone" {
			errorAndExit(fmt.Sprintf("Zone '%s' not found", nameOrId))
		}
		fatalIfErr(err)
		return resp.HostedZone
	} else {
		// lookup by name
		matches := []route53.HostedZone{}
		req := route53.ListHostedZonesInput{}
		for {
			resp, err := r53.ListHostedZones(&req)
			fatalIfErr(err)
			for _, zone := range resp.HostedZones {
				if zoneName(*zone.Name) == zoneName(nameOrId) || *zone.Id == nameOrId {
					matches = append(matches, *zone)
				}
			}
			if *resp.IsTruncated {
				req.Marker = resp.NextMarker
			} else {
				break
			}
		}
		switch len(matches) {
		case 0:
			errorAndExit(fmt.Sprintf("Zone '%s' not found", nameOrId))
		case 1:
			return &matches[0]
		default:
			errorAndExit("Multiple zones match - you will need to use Zone ID to uniquely identify the zone")
		}
	}
	return nil
}
Esempio n. 3
0
func listZones(formatter Formatter) {
	zones := make(chan *route53.HostedZone)
	go func() {
		req := route53.ListHostedZonesInput{}
		for {
			// paginated
			resp, err := r53.ListHostedZones(&req)
			fatalIfErr(err)
			for _, zone := range resp.HostedZones {
				zones <- zone
			}
			if *resp.IsTruncated {
				req.Marker = resp.NextMarker
			} else {
				break
			}
		}
		close(zones)
	}()
	formatter.formatZoneList(zones, os.Stdout)
}