UNPKG

briareus

Version:

Briareus assists with Feature Branch deploys to ECS

44 lines (37 loc) 1.3 kB
'use strict' const AWS = require('aws-sdk'); let action = module.exports = function (pipeline, payload, cb) { const elbv2 = new AWS.ELBv2(); function createAlbRule(done) { // Generate random priority. No two rules can have the same priority. // Not true random, but this doesn't have to be cryptographically secure random // We'll just try again if we pick a number that is already in use let randomPriority = Math.random() * (999 - 1) + 1; let params = { Actions: [{ TargetGroupArn: payload.assets.targetGroup.arn, Type: 'forward' }], Conditions: [ { Field: 'host-header', Values: [`*${payload.endpoint.host}`] }], ListenerArn: payload.alb.listenerArn, Priority: randomPriority }; elbv2.createRule(params, (err, data) => { if (err) { // If we randomly chose a priority that has already been used. Try again if (err.code === 'PriorityInUse') return createAlbRule(done); return cb(err); } cb(null, [ { op: 'add', path: '/assets/albRule', value: { arn: data.Rules[0].RuleArn } }, ]); }); } createAlbRule(cb); }; action.waiting = 'Creating routing rule on ALB'; action.done = 'Routing rule on ALB has been created';