Giter Club home page Giter Club logo

golang-howto-route53's Introduction

Overview

The goal of this how-to is to demonstrate adding a CNAME to a domain in Amazon's Route53 service.

Prerequisites

Create Hosted Zone

Setup a new hosted zone by going to the Route53 home in your AWS account

Assuming you're registering a new domain, you'll get an email confirming your email address. Follow the steps, Amazon will notify you once it's ready.

Once you have your domain registered, you'll get a Hosted Zone Id. Keep it ready, you'll need it in a bit.

Setup your AWS Credentials

The AWS go-sdk requires you to setup the credentials in ~/.aws/credentials.

~/.aws/credentials

[default]
aws_access_key_id = [your access key id]
aws_secret_access_key = [your secret access key] 

Create your CNAME

This is actually a pretty straightforward common task, but I haven't found good documentation on it, so here goes.

I've stripped down the AWS sdk examples to just the bare minimum for setting up a CNAME record.

I'm using the UPSERT Action, which will automatically insert or update. Name is the domain name you're adding the CNAME for. Target is the destination of the CNAME record. You can also add a TTL.

func createCNAME(svc *route53.Route53) {
...
	params := &route53.ChangeResourceRecordSetsInput{
	    ChangeBatch: &route53.ChangeBatch{ // Required
	        Changes: []*route53.Change{ // Required
	            { // Required
	                Action: aws.String("UPSERT"), // Required
	                ResourceRecordSet: &route53.ResourceRecordSet{ // Required
	                    Name: aws.String(name), // Required
	                    Type: aws.String("CNAME"),  // Required
	                    ResourceRecords: []*route53.ResourceRecord{
	                        { // Required
	                            Value: aws.String(target), // Required
	                        },
	                    },
	                    TTL:            aws.Int64(TTL),
	                    Weight:         aws.Int64(weight),
					    SetIdentifier:  aws.String("Arbitrary Id describing this change set"),
	                },
	            },
	        },
	        Comment: aws.String("Sample update."),
	    },
	    HostedZoneId: aws.String(zoneId), // Required
	}
	resp, err := svc.ChangeResourceRecordSets(params)
...

List all domains

I can't figure out how to get this query to constrain results. If you've got a suggestion, let me know.

func listCNAMES(svc *route53.Route53) {
...
	listParams := &route53.ListResourceRecordSetsInput{
		HostedZoneId: aws.String(zoneId), // Required
		...
	}
	respList, err := svc.ListResourceRecordSets(listParams)
...
}

Run the example

go run cname-example.go -d www.your-domain.com -t your-domain.com -z [Your Zone Id]

golang-howto-route53's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

golang-howto-route53's Issues

Restricting the result of ListResourceRecordSets

The ListResourceRecordSetsInput provides three fields to constrain the results.
StartRecordName
StartRecordType
MaxItems

The tricky part is these are not filters, but rather move a pointer to a list of records. For example; if you have dev.example.com, stage.example.com, and prod.example.com. Lets say you want to get dev.example.com. You can get only that record by setting;
StartRecordName: aws.String("dev.example.com")
MaxItems: aws.String("1").

If you set only StartRecordName, then MaxItems will default to 100. So, in this case it will start at "dev.example.com", but then will provide next 100 entries after that irrespective of if they match the StartRecordName or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.