@goldstack/utils-aws-lambda 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Goldstack AWS CLI Tools
|
|
2
|
+
|
|
3
|
+
This library provides a simple wrapper around the AWS CLI. Allowing to either invoke it directly or run it in a Docker container.
|
|
4
|
+
|
|
5
|
+
See [Source Code](https://github.com/goldstack/goldstack/blob/master/workspaces/templates-lib/packages/utils-aws-cli/src/utilsAwsCli.ts)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
export interface DeployFunctionParams {
|
|
3
|
+
lambdaPackageDir: string;
|
|
4
|
+
targetArchiveName?: string;
|
|
5
|
+
awsCredentials: AWS.Credentials;
|
|
6
|
+
region: string;
|
|
7
|
+
functionName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const deployFunction: (params: DeployFunctionParams) => Promise<any>;
|
|
10
|
+
//# sourceMappingURL=utilsAwsLambda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilsAwsLambda.d.ts","sourceRoot":"","sources":["../../src/utilsAwsLambda.ts"],"names":[],"mappings":"AAGA,OAAO,GAAG,MAAM,SAAS,CAAC;AAE1B,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,GAAG,CAAC,WAAW,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,cAAc,WACjB,oBAAoB,KAC3B,QAAQ,GAAG,CAqCb,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deployFunction = void 0;
|
|
4
|
+
const utils_aws_cli_1 = require("@goldstack/utils-aws-cli");
|
|
5
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
6
|
+
const deployFunction = async (params) => {
|
|
7
|
+
const targetArchive = params.targetArchiveName || `lambda-${new Date().getTime()}.zip`;
|
|
8
|
+
await (0, utils_sh_1.rmSafe)(targetArchive);
|
|
9
|
+
await (0, utils_sh_1.zip)({
|
|
10
|
+
directory: params.lambdaPackageDir,
|
|
11
|
+
target: targetArchive,
|
|
12
|
+
mode: 511,
|
|
13
|
+
});
|
|
14
|
+
const deployResult = (0, utils_aws_cli_1.awsCli)({
|
|
15
|
+
credentials: params.awsCredentials,
|
|
16
|
+
region: params.region,
|
|
17
|
+
command: `lambda update-function-code --function-name ${params.functionName} --zip-file fileb://${targetArchive}`,
|
|
18
|
+
});
|
|
19
|
+
if (!params.targetArchiveName) {
|
|
20
|
+
await (0, utils_sh_1.rmSafe)(targetArchive);
|
|
21
|
+
}
|
|
22
|
+
// wait until lambda becomes active
|
|
23
|
+
let counter = 0;
|
|
24
|
+
let state = '';
|
|
25
|
+
while (counter < 20 && state !== 'Active') {
|
|
26
|
+
const res = (0, utils_aws_cli_1.awsCli)({
|
|
27
|
+
credentials: params.awsCredentials,
|
|
28
|
+
region: params.region,
|
|
29
|
+
command: `lambda get-function --function-name ${params.functionName}`,
|
|
30
|
+
});
|
|
31
|
+
const data = JSON.parse(res);
|
|
32
|
+
state = data.Configuration.State;
|
|
33
|
+
counter++;
|
|
34
|
+
}
|
|
35
|
+
if (counter >= 20) {
|
|
36
|
+
throw new Error(`Function was still in state '${state}' after deployment`);
|
|
37
|
+
}
|
|
38
|
+
return JSON.parse(deployResult);
|
|
39
|
+
};
|
|
40
|
+
exports.deployFunction = deployFunction;
|
|
41
|
+
//# sourceMappingURL=utilsAwsLambda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilsAwsLambda.js","sourceRoot":"","sources":["../../src/utilsAwsLambda.ts"],"names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CAAgC,KAAK,oBAAoB,CAAC,CAAC;KAC5E;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAvCW,QAAA,cAAc,kBAuCzB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goldstack/utils-aws-lambda",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Utilities for deploying AWS Lambda functions",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"goldstack",
|
|
7
|
+
"utility",
|
|
8
|
+
"infrastructure",
|
|
9
|
+
"cli",
|
|
10
|
+
"docker",
|
|
11
|
+
"aws",
|
|
12
|
+
"lambda",
|
|
13
|
+
"aws sdk",
|
|
14
|
+
"IaC",
|
|
15
|
+
"configuration"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://goldstack.party",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/goldstack/goldstack/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/goldstack/goldstack.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "Max Rohde",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "dist/src/utilsAwsLambda.js",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "yarn clean && yarn compile",
|
|
31
|
+
"build:watch": "yarn clean && yarn compile-watch",
|
|
32
|
+
"clean": "rm -rf ./dist",
|
|
33
|
+
"compile": "tsc -p tsconfig.json",
|
|
34
|
+
"compile-watch": "tsc -p tsconfig.json --watch",
|
|
35
|
+
"compile-watch:light": "nodemon --watch ./src/ -e '*' --exec 'yarn compile'",
|
|
36
|
+
"coverage": "jest --collect-coverage --passWithNoTests --config=./jest.config.js",
|
|
37
|
+
"prepublishOnly": "yarn run build",
|
|
38
|
+
"publish": "utils-git changed --exec \"yarn npm publish $@\"",
|
|
39
|
+
"test-ci": "jest --passWithNoTests --config=./jest.config.js",
|
|
40
|
+
"version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\"",
|
|
41
|
+
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@goldstack/utils-aws-cli": "0.3.34",
|
|
45
|
+
"@goldstack/utils-log": "0.2.9",
|
|
46
|
+
"@goldstack/utils-sh": "0.4.21",
|
|
47
|
+
"aws-sdk": "2.1001.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@goldstack/utils-git": "0.1.29",
|
|
51
|
+
"@types/jest": "^27.0.2",
|
|
52
|
+
"@types/node": "^16.11.0",
|
|
53
|
+
"jest": "^26.6.3",
|
|
54
|
+
"ts-jest": "^26.5.4",
|
|
55
|
+
"typescript": "^4.4.3"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"main": "dist/src/utilsAwsLambda.js"
|
|
59
|
+
}
|
|
60
|
+
}
|