briareus
Version:
Briareus assists with Feature Branch deploys to ECS
51 lines (43 loc) • 1.45 kB
JavaScript
const AWS = require('aws-sdk');
const _ = require('lodash');
let action = module.exports = function (pipeline, payload, cb) {
const route53 = new AWS.Route53();
let dnsChanges = _.map(payload.assets.acmCertificate.validationOptions, (validationOption) => {
return {
Action: "UPSERT",
ResourceRecordSet: {
Name: validationOption.ResourceRecord.Name,
ResourceRecords: [
{
Value: validationOption.ResourceRecord.Value
}
],
TTL: 60,
Type: validationOption.ResourceRecord.Type
}
}
});
// De-dup record creation. Since certifcate has two domains (regular and wildcard subdomain)
dnsChanges = _.uniqWith(dnsChanges, (change) => change.ResourceRecordSet.Name)
const params = {
ChangeBatch: {
Changes: dnsChanges,
Comment: `Certificate verification for Briareus certificate "${payload.assets.acmCertificate.arn}"`
},
HostedZoneId: payload.hostedZoneId
};
route53.changeResourceRecordSets(params, (err, data) => {
if (err) return cb(err);
const patches = _.map(dnsChanges, (change) => {
return {
op: 'add',
path: '/assets/dnsRecords/-',
value: change.ResourceRecordSet
}
});
cb(null, patches);
});
};
action.waiting = 'Creating DNS records for certificate verification';
action.done = 'DNS records for certificate verification have been created';