Example #1
0
// NewRoute53Client initializes a new DNSClient interface instance based on AWS Route53
func NewRoute53Client(opts *Options) (*Route53, error) {
	optsCopy := *opts

	awsOpts := &amazon.ClientOptions{
		Credentials: opts.Creds,
		Region:      "us-east-1", // our route53 is based on this region, so we use it
		Log:         optsCopy.log(),
		Debug:       opts.Debug,
	}
	dns := route53.New(amazon.NewSession(awsOpts))

	// TODO(rjeczalik): filter by hosted zone instead of requesting 100 records
	params := &route53.ListHostedZonesInput{
		MaxItems: aws.String("100"),
	}
	hostedZones, err := dns.ListHostedZones(params)
	if err != nil {
		return nil, err
	}

	var zoneId string
	var dnsName = opts.HostedZone + "." // DNS name ends with a ".", e.g. "dev.koding.io."
	for _, h := range hostedZones.HostedZones {
		if aws.StringValue(h.Name) == dnsName {
			zoneId = aws.StringValue(h.Id)
		}
	}

	if zoneId == "" {
		return nil, fmt.Errorf("Hosted zone with the name %q doesn't exist", opts.HostedZone)
	}

	return &Route53{
		Route53: dns,
		ZoneId:  zoneId,
		opts:    &optsCopy,
	}, nil
}
Example #2
0
File: aws.go Project: koding/koding
func (c *Cred) session() *session.Session {
	return amazon.NewSession(c.Options())
}