-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandler.js
34 lines (31 loc) · 926 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var AWS = require("aws-sdk");
var route53 = new AWS.Route53();
module.exports.update = (event, context, cb) => {
if (!event.query.hosted_zone_id) { cb('Missing hosted_zone_id param'); return false; }
if (!event.query.name) { cb('Missing name param'); return false; }
route53.changeResourceRecordSets({
HostedZoneId: event.query.hosted_zone_id,
ChangeBatch: {
Changes: [
{
Action: 'UPSERT',
ResourceRecordSet: {
Name: event.query.name,
Type: 'A',
ResourceRecords: [ { Value: event.identity.sourceIp } ],
TTL: 300
}
}
],
Comment: 'ddns update'
}
}, function (err, data) {
if (err) {
console.log(err, err.stack);
cb('Failed to update record set: ' + JSON.stringify({ message: 'FAIL', err: err.stack }))
} else {
cb(null, { message: 'OK' })
}
});
}