serverless-vpc-discovery 4.0.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.json +1 -1
- package/README.md +63 -32
- package/dist/src/aws/ec2-wrapper.js +20 -15
- package/dist/src/common/lambda-function.js +52 -10
- package/dist/src/globals.js +8 -36
- package/dist/src/index.js +7 -11
- package/dist/src/logging.js +45 -0
- package/dist/src/utils.js +10 -45
- package/package.json +27 -23
- package/CHANGELOG.md +0 -72
- package/package-lock.json +0 -6826
package/dist/src/utils.js
CHANGED
@@ -9,65 +9,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.getValueFromTags = exports.wildcardMatches = exports.isObjectEmpty = exports.
|
13
|
-
const RETRYABLE_ERRORS = ["Throttling", "RequestLimitExceeded", "TooManyRequestsException"];
|
12
|
+
exports.getValueFromTags = exports.wildcardMatches = exports.isObjectEmpty = exports.getAWSPagedResults = exports.sleep = void 0;
|
14
13
|
/**
|
15
14
|
* Iterate through the pages of a AWS SDK response and collect them into a single array
|
16
15
|
*
|
17
|
-
* @param
|
18
|
-
* @param funcName - The function name in the service to call
|
16
|
+
* @param client - The AWS service instance to use to make the calls
|
19
17
|
* @param resultsKey - The key name in the response that contains the items to return
|
20
18
|
* @param nextTokenKey - The request key name to append to the request that has the paging token value
|
21
19
|
* @param nextRequestTokenKey - The response key name that has the next paging token value
|
22
20
|
* @param params - Parameters to send in the request
|
23
21
|
*/
|
24
|
-
function getAWSPagedResults(
|
22
|
+
function getAWSPagedResults(client, resultsKey, nextTokenKey, nextRequestTokenKey, params) {
|
25
23
|
return __awaiter(this, void 0, void 0, function* () {
|
26
24
|
let results = [];
|
27
|
-
let response = yield
|
28
|
-
results = results.concat(response[resultsKey]);
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
response = yield service[funcName](params).promise();
|
25
|
+
let response = yield client.send(params);
|
26
|
+
results = results.concat(response[resultsKey] || results);
|
27
|
+
while (nextRequestTokenKey in response && response[nextRequestTokenKey]) {
|
28
|
+
params.input[nextTokenKey] = response[nextRequestTokenKey];
|
29
|
+
response = yield client.send(params);
|
33
30
|
results = results.concat(response[resultsKey]);
|
34
31
|
}
|
35
32
|
return results;
|
36
33
|
});
|
37
34
|
}
|
38
35
|
exports.getAWSPagedResults = getAWSPagedResults;
|
39
|
-
function throttledCall(service, funcName, params) {
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
41
|
-
const maxTimePassed = 5 * 60;
|
42
|
-
let timePassed = 0;
|
43
|
-
let previousInterval = 0;
|
44
|
-
const minWait = 3;
|
45
|
-
const maxWait = 60;
|
46
|
-
while (true) {
|
47
|
-
try {
|
48
|
-
return yield service[funcName](params).promise();
|
49
|
-
}
|
50
|
-
catch (ex) {
|
51
|
-
// rethrow the exception if it is not a type of retryable exception
|
52
|
-
if (RETRYABLE_ERRORS.indexOf(ex.code) === -1) {
|
53
|
-
throw ex;
|
54
|
-
}
|
55
|
-
// rethrow the exception if we have waited too long
|
56
|
-
if (timePassed >= maxTimePassed) {
|
57
|
-
throw ex;
|
58
|
-
}
|
59
|
-
// Sleep using the Decorrelated Jitter algorithm recommended by AWS
|
60
|
-
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
61
|
-
let newInterval = Math.random() * Math.min(maxWait, previousInterval * 3);
|
62
|
-
newInterval = Math.max(minWait, newInterval);
|
63
|
-
yield sleep(newInterval);
|
64
|
-
previousInterval = newInterval;
|
65
|
-
timePassed += previousInterval;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
});
|
69
|
-
}
|
70
|
-
exports.throttledCall = throttledCall;
|
71
36
|
/**
|
72
37
|
* Stops event thread execution for given number of seconds.
|
73
38
|
* @param seconds
|
@@ -79,8 +44,8 @@ function sleep(seconds) {
|
|
79
44
|
});
|
80
45
|
}
|
81
46
|
exports.sleep = sleep;
|
82
|
-
function isObjectEmpty(
|
83
|
-
return Object.keys(
|
47
|
+
function isObjectEmpty(value) {
|
48
|
+
return Object.keys(value).length === 0;
|
84
49
|
}
|
85
50
|
exports.isObjectEmpty = isObjectEmpty;
|
86
51
|
function replaceAll(input, search, replace) {
|
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "serverless-vpc-discovery",
|
3
|
-
"version": "
|
3
|
+
"version": "5.0.0",
|
4
4
|
"engines": {
|
5
|
-
"node": ">=
|
5
|
+
"node": ">=14"
|
6
6
|
},
|
7
7
|
"description": "Serverless Plugin to modify VPC values",
|
8
8
|
"author": "Amplify Education Inc",
|
@@ -34,7 +34,8 @@
|
|
34
34
|
"integration-test": "nyc mocha -r ts-node/register --project tsconfig.json test/integration-tests/*.test.ts && nyc report --reporter=text-summary",
|
35
35
|
"lint": "eslint src --ext .ts",
|
36
36
|
"lint:fix": "npm run lint -- --fix",
|
37
|
-
"build": "tsc --project ."
|
37
|
+
"build": "tsc --project .",
|
38
|
+
"prepare": "npm run build"
|
38
39
|
},
|
39
40
|
"files": [
|
40
41
|
"*.js",
|
@@ -48,33 +49,36 @@
|
|
48
49
|
]
|
49
50
|
},
|
50
51
|
"devDependencies": {
|
51
|
-
"@
|
52
|
-
"@types/
|
53
|
-
"@
|
54
|
-
"@
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
52
|
+
"@aws-sdk/client-lambda": "^3.465.0",
|
53
|
+
"@types/js-yaml": "^4.0.9",
|
54
|
+
"@types/mocha": "^10.0.6",
|
55
|
+
"@types/node": "^20.10.3",
|
56
|
+
"@types/randomstring": "^1.1.11",
|
57
|
+
"@types/shelljs": "^0.8.15",
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
59
|
+
"@typescript-eslint/parser": "^5.62.0",
|
60
|
+
"aws-sdk-client-mock": "^3.0.0",
|
61
|
+
"chai": "^4.3.10",
|
62
|
+
"chai-spies": "^1.1.0",
|
58
63
|
"eslint": "^7.32.0",
|
59
|
-
"eslint-config-airbnb": "^18.2.1",
|
60
64
|
"eslint-config-standard": "^16.0.3",
|
61
|
-
"eslint-plugin-import": "^2.
|
62
|
-
"eslint-plugin-jsx-a11y": "6.4.1",
|
65
|
+
"eslint-plugin-import": "^2.29.0",
|
63
66
|
"eslint-plugin-node": "^11.1.0",
|
64
|
-
"eslint-plugin-promise": "^5.
|
65
|
-
"eslint-plugin-react": "^7.25.1",
|
66
|
-
"eslint-plugin-react-hooks": "^4.2.0",
|
67
|
+
"eslint-plugin-promise": "^5.2.0",
|
67
68
|
"js-yaml": "^4.1.0",
|
68
|
-
"mocha": "^
|
69
|
+
"mocha": "^10.2.0",
|
69
70
|
"mocha-param": "^2.0.1",
|
70
71
|
"nyc": "^15.1.0",
|
71
|
-
"randomstring": "^1.
|
72
|
-
"serverless": "^3.
|
73
|
-
"shelljs": "^0.8.
|
74
|
-
"ts-node": "^10.
|
75
|
-
"typescript": "
|
72
|
+
"randomstring": "^1.3.0",
|
73
|
+
"serverless": "^3.38.0",
|
74
|
+
"shelljs": "^0.8.5",
|
75
|
+
"ts-node": "^10.9.1",
|
76
|
+
"typescript": "5.1.6"
|
76
77
|
},
|
77
78
|
"dependencies": {
|
78
|
-
"aws-sdk": "^
|
79
|
+
"@aws-sdk/client-ec2": "^3.467.0",
|
80
|
+
"@smithy/smithy-client": "^2.1.18",
|
81
|
+
"@smithy/util-retry": "^2.0.8",
|
82
|
+
"ts-md5": "^1.3.1"
|
79
83
|
}
|
80
84
|
}
|
package/CHANGELOG.md
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
All notable changes to this project will be documented in this file.
|
3
|
-
|
4
|
-
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
-
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
-
|
7
|
-
## [4.0.2] - 2022-04-11
|
8
|
-
### Changed
|
9
|
-
- Add integration with serverless 3 logging
|
10
|
-
- Change Github workflows to run tests both with sls 2 and 3
|
11
|
-
|
12
|
-
## [4.0.1] - 2022-04-08
|
13
|
-
### Changed
|
14
|
-
- Fixed audit issues. Added dependabot config
|
15
|
-
|
16
|
-
## [4.0.0] - 2022-04-08
|
17
|
-
### Changed
|
18
|
-
- Added compability with serverless 3
|
19
|
-
|
20
|
-
## [3.1.2] - 2021-09-01
|
21
|
-
### Changed
|
22
|
-
- Fixed y18n vulnerability
|
23
|
-
|
24
|
-
## [3.1.1] - 2021-09-01
|
25
|
-
### Changed
|
26
|
-
- Added serverless schema validation. Thank you @ROSeaboyer ([53](https://github.com/amplify-education/serverless-vpc-discovery/pull/53))
|
27
|
-
|
28
|
-
## [3.1.0] - 2021-09-01
|
29
|
-
### Changed
|
30
|
-
- Dropped support of node versions < 12
|
31
|
-
- Replaced Travis pipeline items with GitHub workflow
|
32
|
-
|
33
|
-
## [3.0.0] - 2020-12-24
|
34
|
-
### Added
|
35
|
-
- Support for getting subnets and security groups by any tag key/value
|
36
|
-
### Changed
|
37
|
-
- ***Important!*** The `subnetNames` and `securityGroupNames` options have been deprecated and will be removed in the next major release. The new options are `subnets` and `securityGroups`.
|
38
|
-
- ***Important!*** Drop `vpc` option support. The new option is `vpcDiscovery`.
|
39
|
-
|
40
|
-
## [2.3.0] - 2020-12-11
|
41
|
-
### Changed
|
42
|
-
- Allow usage of wildcards in subnet and security group names. Thank you @RLRabinowitz ([#41](https://github.com/amplify-education/serverless-vpc-discovery/pull/41))
|
43
|
-
|
44
|
-
## [2.2.1] - 2020-12-02
|
45
|
-
### Changed
|
46
|
-
- Fixed travis build
|
47
|
-
|
48
|
-
## [2.2.0] - 2020-12-02
|
49
|
-
### Changed
|
50
|
-
- Set `custom.vpcDiscovery` optional.
|
51
|
-
- Update travis config for github release tagging
|
52
|
-
|
53
|
-
## [2.1.0] - 2020-11-17
|
54
|
-
### Changed
|
55
|
-
- ***Important!*** The `vpc` option has been deprecated but it still will work for a while. The new option is `vpcDiscovery`.
|
56
|
-
- The VPC config applies to each function instead of the provider option.
|
57
|
-
- Fixed logic for checking missing subnets and security groups.
|
58
|
-
### Added
|
59
|
-
- A possibility to specify custom config for each function by specifying `function.vpcDiscovery` config
|
60
|
-
- Added `warning` and `info` messages
|
61
|
-
|
62
|
-
## [2.0.0] - 2020-11-13
|
63
|
-
### Changed
|
64
|
-
- The code rewritten to TypeScript. Added improvements. Updated travis config, lint and test scripts.
|
65
|
-
|
66
|
-
## [1.0.13] - 2018-10-10
|
67
|
-
### Added
|
68
|
-
- Added our own configuration for AWS SDK's built in retry mechanism, increasing it from 3 retries to 20 so that this plugin is more easily used in an automated environment.
|
69
|
-
|
70
|
-
## [1.0.12] - 2018-08-01
|
71
|
-
### Added
|
72
|
-
- This CHANGELOG file to make it easier for future updates to be documented. Sadly, will not be going back to document changes made for previous versions.
|