-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (42 loc) · 1.38 KB
/
index.ts
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
import * as child from 'child_process';
import * as core from '@actions/core';
import SSMConnection from './services/SSMConnection';
const main = async () => {
const ssm = new SSMConnection();
const targetInstanceId = core.getInput('target-instance-id', { required: true });
const remoteHost = core.getInput('remote-host', { required: true });
const remotePort = core.getInput('remote-port', { required: true });
const localPort = core.getInput('local-port', { required: true });
const awsRegion = core.getInput('aws-region', { required: true });
const awsProfile = core.getInput('aws-profile', { required: false });
const { response, input } = await ssm.connect(
targetInstanceId,
remoteHost,
remotePort,
localPort
);
const jsonResponse = JSON.stringify(response);
const commandType = 'StartSession';
const jsonInput = JSON.stringify(input);
const ssmEndpoint = `https://ssm.${awsRegion}.amazonaws.com`;
const ssmPluginArgs = [
jsonResponse,
awsRegion,
commandType,
awsProfile,
jsonInput,
ssmEndpoint,
];
child
.spawn('session-manager-plugin', ssmPluginArgs, {
stdio: 'ignore',
detached: true,
})
.unref();
const { SessionId: sessionId } = response;
core.info(
`[database-ssm-connection] SessionId "${sessionId}" connected successfully.`
);
core.saveState('ssmSessionId', sessionId);
};
main();