1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

changeResourceRecordSets()はRoute53のホステッドゾーンIDで参照しないといけない。
なのでドメイン名からやりたいときは、listHostedZonesByName()で情報引き出してからやると良さげ。
Lambdaもpromise使えるようになったので、処理の流れはpromise使っていく。

var AWS = require('aws-sdk');
var route53 = new AWS.Route53({
	apiVersion: '2014-05-15',
	accessKeyId: "ACCESS_KEY_ID",
	secretAccessKey: "SECRET_ACCESS_KEY",
	region: "REGION"
});

var params = {
  DNSName: 'YOUR.DOMAIN',
  MaxItems: '1'
};
var eip = "XX.XX.XXX.XXX";
var ttl = "TTL";

route53.listHostedZonesByName(params).promise().then(
	(data) =>  {
	  console.log(data);
	  console.log(data.HostedZones[0].Id);
	  return data;
  }).then( (data) => {
	var HostedZoneId = data.HostedZones[0].Id;
	HostedZoneId = HostedZoneId.split('/')[2];

	var params = {
	  ChangeBatch: {
	    Changes: [
	      {
	        Action: 'UPSERT',
	        ResourceRecordSet: {
	          Name: data.DNSName + '.',
	          Type: 'A',
			  TTL: ttl,
			  ResourceRecords: [
				{
				  Value: eip
				}
			  ]
	        }
	      }
	    ],
	  },
	  HostedZoneId: HostedZoneId
	};
	return route53.changeResourceRecordSets(params).promise();
  }).then( (data) => {
	console.log(data);
  }).catch( (err) => {
	  console.log('Fail to add domain');
	  console.log(err);
  });

ちなみに成功するとこんな感じの表示が出る

{ ChangeInfo: 
   {
   Id: '/change/XXXXXXXXX',
   Status: 'PENDING',
   SubmittedAt: Tue Jun 07 2016 17:33:55 GMT+0900 (JST) 
   }
}

横着してCloudFrontもこれでやろうとしたところ、見事に怒られたのでそっちはまた後々。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?