-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.js
41 lines (41 loc) · 927 Bytes
/
helper.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
'use strict';
const AWS = require('aws-sdk');
let dynamo = new AWS.DynamoDB.DocumentClient();
const ec2 = new AWS.EC2({ apiVersion: '2016-11-15' });
module.exports.getSecurityGroupId = () => {
var params = {
DryRun: false,
};
// Call EC2 to retrieve policy for selected bucket
return ec2
.describeInstances(params)
.promise()
.then((result) => {
return result.Reservations[0].Instances[0].SecurityGroups[0].GroupId;
});
};
module.exports.revokePermissions = async (ip) => {
console.log(ip)
const id = await this.getSecurityGroupId();
const sgParams = {
GroupId: id,
IpPermissions: [
{
FromPort: 22,
IpProtocol: 'tcp',
IpRanges: [
{
CidrIp: ip
},
],
ToPort: 22,
},
],
};
ec2
.revokeSecurityGroupIngress(sgParams)
.promise()
.then((result) => {
return result;
});
};