lambda-live-debugger 0.0.112 → 0.0.114
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/.prettierrc +3 -1
- package/README.md +31 -33
- package/dist/awsCredentials.d.ts +2 -2
- package/dist/awsCredentials.mjs +1 -1
- package/dist/cloudFormation.d.ts +1 -1
- package/dist/cloudFormation.mjs +7 -7
- package/dist/configuration/getConfigFromCliArgs.d.ts +1 -1
- package/dist/configuration/getConfigFromCliArgs.mjs +22 -22
- package/dist/configuration/getConfigFromTsConfigFile.d.ts +1 -1
- package/dist/configuration/getConfigFromTsConfigFile.mjs +9 -9
- package/dist/configuration/getConfigFromWizard.d.ts +1 -1
- package/dist/configuration/getConfigFromWizard.mjs +78 -78
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.mjs +15 -15
- package/dist/constants.mjs +2 -2
- package/dist/extension/extension.zip +0 -0
- package/dist/extension/nodejs/node_modules/interceptor.js.map +1 -1
- package/dist/fileWatcher.mjs +11 -11
- package/dist/frameworks/cdkFramework.d.ts +5 -5
- package/dist/frameworks/cdkFramework.mjs +42 -41
- package/dist/frameworks/cdkFrameworkWorker.mjs +17 -13
- package/dist/frameworks/iFrameworks.d.ts +2 -2
- package/dist/frameworks/samFramework.d.ts +3 -3
- package/dist/frameworks/samFramework.mjs +19 -19
- package/dist/frameworks/slsFramework.d.ts +4 -4
- package/dist/frameworks/slsFramework.mjs +22 -22
- package/dist/frameworks/terraformFramework.d.ts +4 -4
- package/dist/frameworks/terraformFramework.mjs +34 -34
- package/dist/getDirname.mjs +3 -3
- package/dist/gitignore.mjs +11 -11
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +4 -4
- package/dist/infraDeploy.mjs +39 -39
- package/dist/ioTService.d.ts +6 -6
- package/dist/ioTService.mjs +19 -19
- package/dist/lambdaConnection.mjs +13 -13
- package/dist/lldebugger.mjs +22 -22
- package/dist/nodeEsBuild.mjs +30 -30
- package/dist/nodeHandler.d.ts +1 -1
- package/dist/nodeHandler.mjs +4 -4
- package/dist/nodeWorker.d.ts +1 -1
- package/dist/nodeWorker.mjs +14 -14
- package/dist/nodeWorkerRunner.mjs +9 -9
- package/dist/resourceDiscovery.d.ts +1 -1
- package/dist/resourceDiscovery.mjs +8 -8
- package/dist/types/lambdaProps.d.ts +1 -1
- package/dist/types/lldConfig.d.ts +4 -4
- package/dist/types/resourcesDiscovery.d.ts +2 -2
- package/dist/utils/findNpmPath.mjs +6 -6
- package/dist/utils/findPackageJson.mjs +6 -6
- package/dist/utils/getRootFolder.mjs +4 -4
- package/dist/utils/removeUndefinedProperties.mjs +1 -1
- package/dist/version.mjs +5 -5
- package/dist/vsCode.mjs +34 -34
- package/eslint.config.js +18 -18
- package/fix-imports.js +13 -13
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { constants } from
|
|
4
|
-
import { findPackageJson } from
|
|
5
|
-
import { exec } from
|
|
6
|
-
import { promisify } from
|
|
7
|
-
import ts from
|
|
8
|
-
import { Logger } from
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { constants } from 'fs';
|
|
4
|
+
import { findPackageJson } from '../utils/findPackageJson.mjs';
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
import ts from 'typescript';
|
|
8
|
+
import { Logger } from '../logger.mjs';
|
|
9
9
|
export const execAsync = promisify(exec);
|
|
10
10
|
/**
|
|
11
11
|
* Support for Terraform framework
|
|
@@ -15,7 +15,7 @@ export class TerraformFramework {
|
|
|
15
15
|
* Framework name
|
|
16
16
|
*/
|
|
17
17
|
get name() {
|
|
18
|
-
return
|
|
18
|
+
return 'terraform';
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Can this class handle the current project
|
|
@@ -24,9 +24,9 @@ export class TerraformFramework {
|
|
|
24
24
|
async canHandle() {
|
|
25
25
|
// is there any filey with *.tf extension
|
|
26
26
|
const files = await fs.readdir(process.cwd());
|
|
27
|
-
const r = files.some((f) => f.endsWith(
|
|
27
|
+
const r = files.some((f) => f.endsWith('.tf'));
|
|
28
28
|
if (!r) {
|
|
29
|
-
Logger.verbose(`[Terraform] This is not a Terraform project. There are no *.tf files in ${path.resolve(
|
|
29
|
+
Logger.verbose(`[Terraform] This is not a Terraform project. There are no *.tf files in ${path.resolve('.')} folder.`);
|
|
30
30
|
}
|
|
31
31
|
return r;
|
|
32
32
|
}
|
|
@@ -39,22 +39,22 @@ export class TerraformFramework {
|
|
|
39
39
|
async getLambdas(config) {
|
|
40
40
|
const state = await this.readTerraformState();
|
|
41
41
|
const lambdas = this.extractLambdaInfo(state);
|
|
42
|
-
Logger.verbose(
|
|
42
|
+
Logger.verbose('[Terraform] Found Lambdas:', JSON.stringify(lambdas, null, 2));
|
|
43
43
|
const lambdasDiscovered = [];
|
|
44
44
|
const tsOutDir = await this.getTsConfigOutDir();
|
|
45
45
|
if (tsOutDir) {
|
|
46
|
-
Logger.verbose(
|
|
46
|
+
Logger.verbose('[Terraform] tsOutDir:', tsOutDir);
|
|
47
47
|
}
|
|
48
48
|
for (const func of lambdas) {
|
|
49
49
|
const functionName = func.functionName;
|
|
50
|
-
const handlerParts = func.handler.split(
|
|
50
|
+
const handlerParts = func.handler.split('.');
|
|
51
51
|
// get last part of the handler
|
|
52
52
|
const handler = handlerParts[handlerParts.length - 1];
|
|
53
53
|
const filename = func.sourceFilename;
|
|
54
54
|
let pathWithourExtension;
|
|
55
55
|
if (filename) {
|
|
56
56
|
// remove extension
|
|
57
|
-
pathWithourExtension = filename.replace(/\.[^/.]+$/,
|
|
57
|
+
pathWithourExtension = filename.replace(/\.[^/.]+$/, '');
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
60
|
pathWithourExtension = path.join(func.sourceDir, handlerParts[0]);
|
|
@@ -68,8 +68,8 @@ export class TerraformFramework {
|
|
|
68
68
|
if (tsOutDir) {
|
|
69
69
|
// remove outDir from path
|
|
70
70
|
const pathWithourExtensionTypeScript = pathWithourExtension
|
|
71
|
-
.replace(tsOutDir,
|
|
72
|
-
.replace(/\/\//g,
|
|
71
|
+
.replace(tsOutDir, '')
|
|
72
|
+
.replace(/\/\//g, '/');
|
|
73
73
|
possibleCodePaths = [
|
|
74
74
|
`${pathWithourExtensionTypeScript}.ts`,
|
|
75
75
|
`${pathWithourExtensionTypeScript}.js`,
|
|
@@ -107,22 +107,22 @@ export class TerraformFramework {
|
|
|
107
107
|
extractLambdaInfo(state) {
|
|
108
108
|
const lambdas = [];
|
|
109
109
|
for (const resource of state.resources) {
|
|
110
|
-
if (resource.type ===
|
|
111
|
-
Logger.verbose(
|
|
110
|
+
if (resource.type === 'aws_lambda_function') {
|
|
111
|
+
Logger.verbose('[Terraform] Found Lambda:', JSON.stringify(resource, null, 2));
|
|
112
112
|
let sourceDir;
|
|
113
113
|
let sourceFilename;
|
|
114
114
|
const functionName = resource.values.function_name;
|
|
115
115
|
const handler = resource.values.handler;
|
|
116
116
|
if (!functionName) {
|
|
117
|
-
Logger.error(
|
|
117
|
+
Logger.error('Failed to find function name for Lambda');
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
120
120
|
// get dependency "data.archive_file"
|
|
121
121
|
const dependencies = resource.depends_on;
|
|
122
|
-
const archiveFileResourceName = dependencies.find((dep) => dep.startsWith(
|
|
122
|
+
const archiveFileResourceName = dependencies.find((dep) => dep.startsWith('data.archive_file.'));
|
|
123
123
|
if (archiveFileResourceName) {
|
|
124
124
|
// get the resource
|
|
125
|
-
const name = archiveFileResourceName.split(
|
|
125
|
+
const name = archiveFileResourceName.split('.')[2];
|
|
126
126
|
const archiveFileResource = state.resources.find((r) => r.name === name);
|
|
127
127
|
// get source_dir or source_filename
|
|
128
128
|
if (archiveFileResource) {
|
|
@@ -138,7 +138,7 @@ export class TerraformFramework {
|
|
|
138
138
|
functionName,
|
|
139
139
|
sourceDir,
|
|
140
140
|
sourceFilename,
|
|
141
|
-
handler: handler ??
|
|
141
|
+
handler: handler ?? 'handler',
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -150,7 +150,7 @@ export class TerraformFramework {
|
|
|
150
150
|
let output;
|
|
151
151
|
// get state by running "terraform show --json" command
|
|
152
152
|
try {
|
|
153
|
-
output = await execAsync(
|
|
153
|
+
output = await execAsync('terraform show --json');
|
|
154
154
|
}
|
|
155
155
|
catch (error) {
|
|
156
156
|
throw new Error(`Failed to get Terraform state from 'terraform show --json' command: ${error.message}`, { cause: error });
|
|
@@ -162,10 +162,10 @@ export class TerraformFramework {
|
|
|
162
162
|
throw new Error("Failed to get Terraform state from 'terraform show --json' command");
|
|
163
163
|
}
|
|
164
164
|
let jsonString = output.stdout;
|
|
165
|
-
Logger.verbose(
|
|
166
|
-
jsonString = jsonString?.split(
|
|
165
|
+
Logger.verbose('Terraform state:', jsonString);
|
|
166
|
+
jsonString = jsonString?.split('\n').find((line) => line.startsWith('{'));
|
|
167
167
|
if (!jsonString) {
|
|
168
|
-
throw new Error(
|
|
168
|
+
throw new Error('Failed to get Terraform state. JSON string not found in the output.');
|
|
169
169
|
}
|
|
170
170
|
try {
|
|
171
171
|
const state = JSON.parse(jsonString);
|
|
@@ -173,8 +173,8 @@ export class TerraformFramework {
|
|
|
173
173
|
}
|
|
174
174
|
catch (error) {
|
|
175
175
|
//save state to file
|
|
176
|
-
await fs.writeFile(
|
|
177
|
-
Logger.error(
|
|
176
|
+
await fs.writeFile('terraform-state.json', jsonString);
|
|
177
|
+
Logger.error('Failed to parse Terraform state JSON:', error);
|
|
178
178
|
throw new Error(`Failed to parse Terraform state JSON: ${error.message}`, { cause: error });
|
|
179
179
|
}
|
|
180
180
|
}
|
|
@@ -184,8 +184,8 @@ export class TerraformFramework {
|
|
|
184
184
|
async getTsConfigOutDir() {
|
|
185
185
|
let currentDir = process.cwd();
|
|
186
186
|
let tsConfigPath;
|
|
187
|
-
while (currentDir !==
|
|
188
|
-
tsConfigPath = path.resolve(path.join(currentDir,
|
|
187
|
+
while (currentDir !== '/') {
|
|
188
|
+
tsConfigPath = path.resolve(path.join(currentDir, 'tsconfig.json'));
|
|
189
189
|
try {
|
|
190
190
|
await fs.access(tsConfigPath, constants.F_OK);
|
|
191
191
|
break;
|
|
@@ -196,12 +196,12 @@ export class TerraformFramework {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
if (!tsConfigPath) {
|
|
199
|
-
Logger.verbose(
|
|
199
|
+
Logger.verbose('[Terraform] tsconfig.json not found');
|
|
200
200
|
return undefined;
|
|
201
201
|
}
|
|
202
|
-
Logger.verbose(
|
|
202
|
+
Logger.verbose('[Terraform] tsconfig.json found:', tsConfigPath);
|
|
203
203
|
const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
|
|
204
|
-
const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys,
|
|
204
|
+
const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, './');
|
|
205
205
|
return compilerOptions.options.outDir
|
|
206
206
|
? path.resolve(compilerOptions.options.outDir)
|
|
207
207
|
: undefined;
|
package/dist/getDirname.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
import { fileURLToPath } from
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
3
|
const __filename = fileURLToPath(import.meta.url);
|
|
4
4
|
const __dirname = path.dirname(__filename);
|
|
5
|
-
const projectDirname = path.resolve(
|
|
5
|
+
const projectDirname = path.resolve('.');
|
|
6
6
|
/**
|
|
7
7
|
* Get the dirname of the Lambda Live Debugger NPM module
|
|
8
8
|
* @returns
|
package/dist/gitignore.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { outputFolder } from
|
|
3
|
-
import { Logger } from
|
|
4
|
-
import { getProjectDirname } from
|
|
5
|
-
import path from
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import { outputFolder } from './constants.mjs';
|
|
3
|
+
import { Logger } from './logger.mjs';
|
|
4
|
+
import { getProjectDirname } from './getDirname.mjs';
|
|
5
|
+
import path from 'path';
|
|
6
6
|
/**
|
|
7
7
|
* Check if ".lldebugger" exists in .gitignore
|
|
8
8
|
*/
|
|
9
9
|
async function doesExistInGitIgnore() {
|
|
10
10
|
try {
|
|
11
|
-
const gitignoreContent = await fs.readFile(getGitIgnoreFileLocation(),
|
|
11
|
+
const gitignoreContent = await fs.readFile(getGitIgnoreFileLocation(), 'utf-8');
|
|
12
12
|
// split by new line
|
|
13
|
-
const lines = gitignoreContent.split(
|
|
13
|
+
const lines = gitignoreContent.split('\n');
|
|
14
14
|
// check if ".lldebugger" exists
|
|
15
15
|
const exists = lines.includes(outputFolder);
|
|
16
16
|
return exists;
|
|
@@ -24,7 +24,7 @@ async function doesExistInGitIgnore() {
|
|
|
24
24
|
* @returns
|
|
25
25
|
*/
|
|
26
26
|
function getGitIgnoreFileLocation() {
|
|
27
|
-
return path.join(getProjectDirname(),
|
|
27
|
+
return path.join(getProjectDirname(), '.gitignore');
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Add ".lldebugger" to .gitignore if it doesn't exist
|
|
@@ -53,11 +53,11 @@ async function addToGitIgnore() {
|
|
|
53
53
|
* Remove ".lldebugger" from .gitignore
|
|
54
54
|
*/
|
|
55
55
|
async function removeFromGitIgnore() {
|
|
56
|
-
Logger.verbose(
|
|
56
|
+
Logger.verbose('Removing .gitignore entry...');
|
|
57
57
|
const exists = await doesExistInGitIgnore();
|
|
58
58
|
if (exists) {
|
|
59
|
-
const gitignoreContent = await fs.readFile(getGitIgnoreFileLocation(),
|
|
60
|
-
const newContent = gitignoreContent.replace(`${outputFolder}\n`,
|
|
59
|
+
const gitignoreContent = await fs.readFile(getGitIgnoreFileLocation(), 'utf-8');
|
|
60
|
+
const newContent = gitignoreContent.replace(`${outputFolder}\n`, '');
|
|
61
61
|
await fs.writeFile(getGitIgnoreFileLocation(), newContent);
|
|
62
62
|
}
|
|
63
63
|
else {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { type LldConfigTs, type LldConfigBase } from
|
|
2
|
-
export type { EsBuildOptions, BundlingType, LambdaResource, } from
|
|
3
|
-
export { CdkFramework } from
|
|
4
|
-
export { SlsFramework } from
|
|
5
|
-
export { SamFramework } from
|
|
6
|
-
export { TerraformFramework } from
|
|
7
|
-
export { type IFramework } from
|
|
8
|
-
export { type AwsConfiguration } from
|
|
1
|
+
export { type LldConfigTs, type LldConfigBase } from './types/lldConfig.js';
|
|
2
|
+
export type { EsBuildOptions, BundlingType, LambdaResource, } from './types/resourcesDiscovery.js';
|
|
3
|
+
export { CdkFramework } from './frameworks/cdkFramework.js';
|
|
4
|
+
export { SlsFramework } from './frameworks/slsFramework.js';
|
|
5
|
+
export { SamFramework } from './frameworks/samFramework.js';
|
|
6
|
+
export { TerraformFramework } from './frameworks/terraformFramework.js';
|
|
7
|
+
export { type IFramework } from './frameworks/iFrameworks.js';
|
|
8
|
+
export { type AwsConfiguration } from './types/awsConfiguration.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CdkFramework } from
|
|
2
|
-
export { SlsFramework } from
|
|
3
|
-
export { SamFramework } from
|
|
4
|
-
export { TerraformFramework } from
|
|
1
|
+
export { CdkFramework } from './frameworks/cdkFramework.js';
|
|
2
|
+
export { SlsFramework } from './frameworks/slsFramework.js';
|
|
3
|
+
export { SamFramework } from './frameworks/samFramework.js';
|
|
4
|
+
export { TerraformFramework } from './frameworks/terraformFramework.js';
|
package/dist/infraDeploy.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { DeleteLayerVersionCommand, LambdaClient, ListLayerVersionsCommand, PublishLayerVersionCommand, UpdateFunctionConfigurationCommand, GetFunctionCommand, ListLayersCommand, } from
|
|
2
|
-
import { IAMClient, GetRolePolicyCommand, PutRolePolicyCommand, DeleteRolePolicyCommand, } from
|
|
3
|
-
import { getVersion } from
|
|
4
|
-
import fs from
|
|
5
|
-
import * as path from
|
|
6
|
-
import { Configuration } from
|
|
7
|
-
import { AwsCredentials } from
|
|
8
|
-
import { getModuleDirname } from
|
|
9
|
-
import { Logger } from
|
|
1
|
+
import { DeleteLayerVersionCommand, LambdaClient, ListLayerVersionsCommand, PublishLayerVersionCommand, UpdateFunctionConfigurationCommand, GetFunctionCommand, ListLayersCommand, } from '@aws-sdk/client-lambda';
|
|
2
|
+
import { IAMClient, GetRolePolicyCommand, PutRolePolicyCommand, DeleteRolePolicyCommand, } from '@aws-sdk/client-iam';
|
|
3
|
+
import { getVersion } from './version.mjs';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { Configuration } from './configuration.mjs';
|
|
7
|
+
import { AwsCredentials } from './awsCredentials.mjs';
|
|
8
|
+
import { getModuleDirname } from './getDirname.mjs';
|
|
9
|
+
import { Logger } from './logger.mjs';
|
|
10
10
|
let lambdaClient;
|
|
11
11
|
let iamClient;
|
|
12
|
-
const inlinePolicyName =
|
|
13
|
-
const layerName =
|
|
12
|
+
const inlinePolicyName = 'LambdaLiveDebuggerPolicy';
|
|
13
|
+
const layerName = 'LambdaLiveDebugger';
|
|
14
14
|
/**
|
|
15
15
|
* Policy document to attach to the Lambda role
|
|
16
16
|
*/
|
|
17
17
|
const policyDocument = {
|
|
18
|
-
Version:
|
|
18
|
+
Version: '2012-10-17',
|
|
19
19
|
Statement: [
|
|
20
20
|
{
|
|
21
|
-
Action:
|
|
22
|
-
Resource:
|
|
23
|
-
Effect:
|
|
21
|
+
Action: 'iot:*',
|
|
22
|
+
Resource: '*',
|
|
23
|
+
Effect: 'Allow',
|
|
24
24
|
},
|
|
25
25
|
],
|
|
26
26
|
};
|
|
@@ -81,7 +81,7 @@ async function findExistingLayerVersion(layerName, description) {
|
|
|
81
81
|
}
|
|
82
82
|
nextMarker = response.NextMarker;
|
|
83
83
|
} while (nextMarker);
|
|
84
|
-
Logger.verbose(
|
|
84
|
+
Logger.verbose('No existing layer found.');
|
|
85
85
|
return undefined;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
@@ -97,8 +97,8 @@ async function deployLayer() {
|
|
|
97
97
|
existingLayer.Description === layerDescription // check if the layer version is already deployed
|
|
98
98
|
) {
|
|
99
99
|
// delete existing layer when developing
|
|
100
|
-
if ((await getVersion()) ===
|
|
101
|
-
Logger.verbose(
|
|
100
|
+
if ((await getVersion()) === '0.0.1') {
|
|
101
|
+
Logger.verbose('Deleting existing layer version, because it is a development mode.');
|
|
102
102
|
const deleteLayerVersionCommand = new DeleteLayerVersionCommand({
|
|
103
103
|
LayerName: layerName,
|
|
104
104
|
VersionNumber: existingLayer.Version,
|
|
@@ -111,14 +111,14 @@ async function deployLayer() {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
// check the ZIP
|
|
114
|
-
let layerZipPathFullPath = path.resolve(path.join(getModuleDirname(),
|
|
114
|
+
let layerZipPathFullPath = path.resolve(path.join(getModuleDirname(), './extension/extension.zip'));
|
|
115
115
|
// get the full path to the ZIP file
|
|
116
116
|
try {
|
|
117
117
|
await fs.access(layerZipPathFullPath);
|
|
118
118
|
}
|
|
119
119
|
catch {
|
|
120
120
|
// if I am debugging
|
|
121
|
-
const layerZipPathFullPath2 = path.join(getModuleDirname(),
|
|
121
|
+
const layerZipPathFullPath2 = path.join(getModuleDirname(), '../dist/extension/extension.zip');
|
|
122
122
|
try {
|
|
123
123
|
await fs.access(layerZipPathFullPath2);
|
|
124
124
|
layerZipPathFullPath = layerZipPathFullPath2;
|
|
@@ -138,12 +138,12 @@ async function deployLayer() {
|
|
|
138
138
|
Content: {
|
|
139
139
|
ZipFile: layerContent,
|
|
140
140
|
},
|
|
141
|
-
CompatibleArchitectures: [
|
|
142
|
-
CompatibleRuntimes: [
|
|
141
|
+
CompatibleArchitectures: ['x86_64', 'arm64'],
|
|
142
|
+
CompatibleRuntimes: ['nodejs18.x', 'nodejs20.x'],
|
|
143
143
|
});
|
|
144
144
|
const response = await getLambdaClient().send(publishLayerVersionCommand);
|
|
145
145
|
if (!response.LayerVersionArn) {
|
|
146
|
-
throw new Error(
|
|
146
|
+
throw new Error('Failed to retrieve the layer version ARN');
|
|
147
147
|
}
|
|
148
148
|
Logger.verbose(`Deployed ${response.Description} ARN: ${response.LayerVersionArn}`);
|
|
149
149
|
return response.LayerVersionArn;
|
|
@@ -217,7 +217,7 @@ async function removeLayerFromLambda(functionName) {
|
|
|
217
217
|
else {
|
|
218
218
|
Logger.verbose(`Skipping detaching layer from the function ${functionName}, no layer attached`);
|
|
219
219
|
}
|
|
220
|
-
const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger(
|
|
220
|
+
const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger('xxx', 0);
|
|
221
221
|
// check if environment variables are set for each property
|
|
222
222
|
for (const [key] of Object.entries(ddlEnvironmentVariables)) {
|
|
223
223
|
if (environmentVariables && environmentVariables[key]) {
|
|
@@ -227,14 +227,14 @@ async function removeLayerFromLambda(functionName) {
|
|
|
227
227
|
}
|
|
228
228
|
if (needToUpdate) {
|
|
229
229
|
Logger.verbose(`Updating function configuration for ${functionName} to remove layer and reset environment variables`);
|
|
230
|
-
Logger.verbose(
|
|
230
|
+
Logger.verbose('Existing environment variables', JSON.stringify(environmentVariables, null, 2));
|
|
231
231
|
//remove environment variables
|
|
232
232
|
for (const [key] of Object.entries(ddlEnvironmentVariables)) {
|
|
233
233
|
if (environmentVariables && environmentVariables[key]) {
|
|
234
234
|
delete environmentVariables[key];
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
Logger.verbose(
|
|
237
|
+
Logger.verbose('New environment variables', JSON.stringify(environmentVariables, null, 2));
|
|
238
238
|
const updateFunctionConfigurationCommand = new UpdateFunctionConfigurationCommand({
|
|
239
239
|
FunctionName: functionName,
|
|
240
240
|
Layers: otherLayerArns,
|
|
@@ -312,7 +312,7 @@ async function attachLayerToLambda(functionName, functionId, layerArn) {
|
|
|
312
312
|
// check if layers with the wrong version are attached
|
|
313
313
|
if (!needToUpdate && ddlLayerArns.find((arn) => arn !== layerArn)) {
|
|
314
314
|
needToUpdate = true;
|
|
315
|
-
Logger.verbose(
|
|
315
|
+
Logger.verbose('Layer with the wrong version attached to the function');
|
|
316
316
|
}
|
|
317
317
|
const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger(functionId, initialTimeout);
|
|
318
318
|
// check if environment variables are already set for each property
|
|
@@ -361,7 +361,7 @@ async function addPolicyToLambdaRole(functionName) {
|
|
|
361
361
|
throw new Error(`Failed to retrieve the role ARN for Lambda ${functionName}`);
|
|
362
362
|
}
|
|
363
363
|
// Extract the role name from the role ARN
|
|
364
|
-
const roleName = roleArn.split(
|
|
364
|
+
const roleName = roleArn.split('/').pop();
|
|
365
365
|
if (!roleName) {
|
|
366
366
|
throw new Error(`Failed to extract role name from role ARN: ${roleArn} for lambda ${functionName}`);
|
|
367
367
|
}
|
|
@@ -393,11 +393,11 @@ async function addPolicyToLambdaRole(functionName) {
|
|
|
393
393
|
function getEnvironmentVarablesForDebugger(functionId, timeout) {
|
|
394
394
|
return {
|
|
395
395
|
LLD_FUNCTION_ID: functionId,
|
|
396
|
-
AWS_LAMBDA_EXEC_WRAPPER:
|
|
397
|
-
NODE_OPTIONS:
|
|
396
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/lld-wrapper',
|
|
397
|
+
NODE_OPTIONS: '--enable-source-maps',
|
|
398
398
|
LLD_DEBUGGER_ID: Configuration.config.debuggerId,
|
|
399
|
-
LLD_INITIAL_TIMEOUT: timeout ? timeout.toString() :
|
|
400
|
-
LLD_OBSERVABLE_MODE: Configuration.config.observable ?
|
|
399
|
+
LLD_INITIAL_TIMEOUT: timeout ? timeout.toString() : '-1', // should never be negative
|
|
400
|
+
LLD_OBSERVABLE_MODE: Configuration.config.observable ? 'true' : 'false',
|
|
401
401
|
LLD_OBSERVABLE_INTERVAL: Configuration.config.interval.toString(),
|
|
402
402
|
};
|
|
403
403
|
}
|
|
@@ -417,7 +417,7 @@ async function removePolicyFromLambdaRole(functionName) {
|
|
|
417
417
|
throw new Error(`Failed to retrieve the role ARN for lambda ${functionName}`);
|
|
418
418
|
}
|
|
419
419
|
// Extract the role name from the role ARN
|
|
420
|
-
const roleName = roleArn.split(
|
|
420
|
+
const roleName = roleArn.split('/').pop();
|
|
421
421
|
if (!roleName) {
|
|
422
422
|
Logger.error(`Failed to extract role name from role ARN: ${roleArn} for Lambda ${functionName}`);
|
|
423
423
|
return;
|
|
@@ -463,7 +463,7 @@ async function getPolicyDocument(roleName) {
|
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
catch (error) {
|
|
466
|
-
if (error.name ===
|
|
466
|
+
if (error.name === 'NoSuchEntityException') {
|
|
467
467
|
return undefined;
|
|
468
468
|
}
|
|
469
469
|
else {
|
|
@@ -479,7 +479,7 @@ async function deployInfrastructure() {
|
|
|
479
479
|
const promises = [];
|
|
480
480
|
for (const func of Configuration.getLambdas()) {
|
|
481
481
|
const p = attachLayerToLambda(func.functionName, func.functionId, layerVersionArn);
|
|
482
|
-
if (process.env.DISABLE_PARALLEL_DEPLOY ===
|
|
482
|
+
if (process.env.DISABLE_PARALLEL_DEPLOY === 'true') {
|
|
483
483
|
await p;
|
|
484
484
|
}
|
|
485
485
|
else {
|
|
@@ -492,7 +492,7 @@ async function deployInfrastructure() {
|
|
|
492
492
|
await addPolicyToLambdaRole(func.functionName);
|
|
493
493
|
}
|
|
494
494
|
})(); // creates one promise
|
|
495
|
-
if (process.env.DISABLE_PARALLEL_DEPLOY ===
|
|
495
|
+
if (process.env.DISABLE_PARALLEL_DEPLOY === 'true') {
|
|
496
496
|
await p;
|
|
497
497
|
}
|
|
498
498
|
else {
|
|
@@ -504,11 +504,11 @@ async function deployInfrastructure() {
|
|
|
504
504
|
* Remove the infrastructure
|
|
505
505
|
*/
|
|
506
506
|
async function removeInfrastructure() {
|
|
507
|
-
Logger.verbose(
|
|
507
|
+
Logger.verbose('Removing Lambda Live Debugger infrastructure.');
|
|
508
508
|
const promises = [];
|
|
509
509
|
for (const func of Configuration.getLambdas()) {
|
|
510
510
|
const p = removeLayerFromLambda(func.functionName);
|
|
511
|
-
if (process.env.DISABLE_PARALLEL_DEPLOY ===
|
|
511
|
+
if (process.env.DISABLE_PARALLEL_DEPLOY === 'true') {
|
|
512
512
|
await p;
|
|
513
513
|
}
|
|
514
514
|
else {
|
|
@@ -521,7 +521,7 @@ async function removeInfrastructure() {
|
|
|
521
521
|
await removePolicyFromLambdaRole(func.functionName);
|
|
522
522
|
}
|
|
523
523
|
})(); // creates one promise
|
|
524
|
-
if (process.env.DISABLE_PARALLEL_DEPLOY ===
|
|
524
|
+
if (process.env.DISABLE_PARALLEL_DEPLOY === 'true') {
|
|
525
525
|
await p;
|
|
526
526
|
}
|
|
527
527
|
else {
|
package/dist/ioTService.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AwsCredentialIdentityProvider } from
|
|
1
|
+
import type { AwsCredentialIdentityProvider } from '@smithy/types';
|
|
2
2
|
type IoTMessageBase = {
|
|
3
3
|
workerId: string;
|
|
4
4
|
requestId: string;
|
|
@@ -25,19 +25,19 @@ export type FunctionPing = IoTMessageBase;
|
|
|
25
25
|
* IoT Message that is exchanged between the Lambda and local worker
|
|
26
26
|
*/
|
|
27
27
|
export type IoTMessage = {
|
|
28
|
-
type:
|
|
28
|
+
type: 'INVOKE';
|
|
29
29
|
data: FuctionRequest;
|
|
30
30
|
} | {
|
|
31
|
-
type:
|
|
31
|
+
type: 'SUCCESS';
|
|
32
32
|
data: FunctionResponse;
|
|
33
33
|
} | {
|
|
34
|
-
type:
|
|
34
|
+
type: 'ERROR';
|
|
35
35
|
data: FunctionErrorResponse;
|
|
36
36
|
} | {
|
|
37
|
-
type:
|
|
37
|
+
type: 'PING';
|
|
38
38
|
data: FunctionPing;
|
|
39
39
|
};
|
|
40
|
-
export type IoTMessageTypes = IoTMessage[
|
|
40
|
+
export type IoTMessageTypes = IoTMessage['type'];
|
|
41
41
|
/**
|
|
42
42
|
* IoT Service Connection with an method to publish messages
|
|
43
43
|
*/
|
package/dist/ioTService.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as iot from
|
|
2
|
-
import { splitMessageToChunks } from
|
|
3
|
-
import { IoTClient, DescribeEndpointCommand } from
|
|
4
|
-
import { Logger } from
|
|
1
|
+
import * as iot from 'aws-iot-device-sdk';
|
|
2
|
+
import { splitMessageToChunks } from './utils/splitIoTMessage.mjs';
|
|
3
|
+
import { IoTClient, DescribeEndpointCommand } from '@aws-sdk/client-iot';
|
|
4
|
+
import { Logger } from './logger.mjs';
|
|
5
5
|
let device;
|
|
6
6
|
const chunks = new Map();
|
|
7
7
|
/**
|
|
@@ -15,10 +15,10 @@ async function getIoTEndpoint({ region, credentials, }) {
|
|
|
15
15
|
credentials,
|
|
16
16
|
});
|
|
17
17
|
const response = await iot.send(new DescribeEndpointCommand({
|
|
18
|
-
endpointType:
|
|
18
|
+
endpointType: 'iot:Data-ATS',
|
|
19
19
|
}));
|
|
20
20
|
if (!response.endpointAddress)
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error('IoT Endpoint address not found');
|
|
22
22
|
return response.endpointAddress;
|
|
23
23
|
}
|
|
24
24
|
let connectedPromiseResolve;
|
|
@@ -39,7 +39,7 @@ async function connect(props) {
|
|
|
39
39
|
credentials,
|
|
40
40
|
});
|
|
41
41
|
device = new iot.device({
|
|
42
|
-
protocol:
|
|
42
|
+
protocol: 'wss',
|
|
43
43
|
host: endpoint,
|
|
44
44
|
reconnectPeriod: 1,
|
|
45
45
|
keepalive: 60,
|
|
@@ -50,26 +50,26 @@ async function connect(props) {
|
|
|
50
50
|
});
|
|
51
51
|
if (props?.topic) {
|
|
52
52
|
device.subscribe(props.topic, { qos: 1 });
|
|
53
|
-
Logger.verbose(
|
|
53
|
+
Logger.verbose('[IoT] Subscribed to topic ', props.topic);
|
|
54
54
|
}
|
|
55
|
-
device.on(
|
|
56
|
-
Logger.verbose(
|
|
55
|
+
device.on('connect', () => {
|
|
56
|
+
Logger.verbose('[IoT] Connected');
|
|
57
57
|
connectedPromiseResolve();
|
|
58
58
|
});
|
|
59
|
-
device.on(
|
|
60
|
-
Logger.error(
|
|
59
|
+
device.on('error', (err) => {
|
|
60
|
+
Logger.error('[IoT] Error', err);
|
|
61
61
|
});
|
|
62
|
-
device.on(
|
|
63
|
-
Logger.verbose(
|
|
62
|
+
device.on('close', () => {
|
|
63
|
+
Logger.verbose('[IoT] Closed');
|
|
64
64
|
});
|
|
65
|
-
device.on(
|
|
66
|
-
Logger.verbose(
|
|
65
|
+
device.on('reconnect', () => {
|
|
66
|
+
Logger.verbose('[IoT] Reconnecting...');
|
|
67
67
|
});
|
|
68
68
|
if (props?.onMessage) {
|
|
69
69
|
const messageReceived = (topic, buffer) => {
|
|
70
70
|
const chunk = JSON.parse(buffer.toString());
|
|
71
71
|
if (!chunk.id) {
|
|
72
|
-
throw new Error(
|
|
72
|
+
throw new Error('Invalid fragment');
|
|
73
73
|
}
|
|
74
74
|
let pending = chunks.get(chunk.id);
|
|
75
75
|
if (!pending) {
|
|
@@ -81,13 +81,13 @@ async function connect(props) {
|
|
|
81
81
|
const data = [...pending.values()]
|
|
82
82
|
.sort((a, b) => a.index - b.index)
|
|
83
83
|
.map((item) => item.data)
|
|
84
|
-
.join(
|
|
84
|
+
.join('');
|
|
85
85
|
chunks.delete(chunk.id);
|
|
86
86
|
const evt = JSON.parse(data);
|
|
87
87
|
props.onMessage(evt);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
device.on(
|
|
90
|
+
device.on('message', messageReceived);
|
|
91
91
|
}
|
|
92
92
|
await connectedPromise;
|
|
93
93
|
return {
|