-
Notifications
You must be signed in to change notification settings - Fork 99
/
create_elb_https_listner_rules_for_redirect_url.js
58 lines (47 loc) · 1.55 KB
/
create_elb_https_listner_rules_for_redirect_url.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const awsConfigHelper = require('./util/awsConfigHelper');
const AWS = require("aws-sdk");
const cli = require('cli');
const cliArgs = cli.parse({
region: ['r', 'AWS region', 'string'],
listenerArn: ['l', 'Rule Arn', 'string'],
query: ['q', 'Query', 'string', undefined],
host: ['h', 'Host Name', 'string'],
redirectHost: ['d', 'Redirect Host Name', 'string'],
path: ['p', 'Destination ARN', 'string', '/#{path}'],
priority: ['o', 'priority', 'number']
});
if (!cliArgs.region || !cliArgs.listenerArn) {
cli.getUsage();
}
async function createElbListenerRuleForRedirectUrl() {
try {
await awsConfigHelper.updateConfig(cliArgs.region);
const elbV2 = new AWS.ELBv2();
return await elbV2.createRule({
Actions: [
{
Type: "redirect",
RedirectConfig: {
StatusCode: "HTTP_301",
Host: cliArgs.redirectHost,
Path: cliArgs.path,
Port: '443',
Protocol: 'HTTPS',
Query: cliArgs.query
}
}
],
Conditions: [
{
"Field": "host-header",
"Values": [cliArgs.host]
}
],
ListenerArn: cliArgs.listenerArn,
Priority: cliArgs.priority
}).promise();
} catch (error) {
console.error(error);
};
}
createElbListenerRuleForRedirectUrl();