@gugananuvem/aws-local-simulator 1.0.12 → 1.0.15
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 +594 -257
- package/bin/aws-local-simulator.js +63 -63
- package/package.json +21 -10
- package/src/config/config-loader.js +114 -114
- package/src/config/default-config.js +68 -67
- package/src/config/env-loader.js +68 -68
- package/src/index.js +146 -130
- package/src/index.mjs +123 -123
- package/src/server.js +227 -223
- package/src/services/apigateway/index.js +73 -68
- package/src/services/apigateway/server.js +507 -487
- package/src/services/apigateway/simulator.js +1261 -1251
- package/src/services/athena/index.js +75 -0
- package/src/services/athena/server.js +101 -0
- package/src/services/athena/simulador.js +998 -0
- package/src/services/athena/simulator.js +346 -0
- package/src/services/cloudformation/index.js +106 -0
- package/src/services/cloudformation/server.js +417 -0
- package/src/services/cloudformation/simulador.js +1045 -0
- package/src/services/cloudtrail/index.js +84 -0
- package/src/services/cloudtrail/server.js +235 -0
- package/src/services/cloudtrail/simulador.js +719 -0
- package/src/services/cloudwatch/index.js +84 -0
- package/src/services/cloudwatch/server.js +366 -0
- package/src/services/cloudwatch/simulador.js +1173 -0
- package/src/services/cognito/index.js +79 -65
- package/src/services/cognito/server.js +301 -279
- package/src/services/cognito/simulator.js +1655 -1115
- package/src/services/config/index.js +96 -0
- package/src/services/config/server.js +215 -0
- package/src/services/config/simulador.js +1260 -0
- package/src/services/dynamodb/index.js +74 -70
- package/src/services/dynamodb/server.js +125 -121
- package/src/services/dynamodb/simulator.js +630 -620
- package/src/services/ecs/index.js +65 -65
- package/src/services/ecs/server.js +235 -233
- package/src/services/ecs/simulator.js +844 -844
- package/src/services/eventbridge/index.js +89 -85
- package/src/services/eventbridge/server.js +209 -0
- package/src/services/eventbridge/simulator.js +684 -0
- package/src/services/index.js +45 -19
- package/src/services/kms/index.js +75 -0
- package/src/services/kms/server.js +67 -0
- package/src/services/kms/simulator.js +324 -0
- package/src/services/lambda/handler-loader.js +183 -183
- package/src/services/lambda/index.js +78 -73
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +145 -145
- package/src/services/lambda/simulator.js +199 -172
- package/src/services/parameter-store/index.js +80 -0
- package/src/services/parameter-store/server.js +50 -0
- package/src/services/parameter-store/simulator.js +201 -0
- package/src/services/s3/index.js +73 -69
- package/src/services/s3/server.js +329 -238
- package/src/services/s3/simulator.js +565 -740
- package/src/services/secret-manager/index.js +80 -0
- package/src/services/secret-manager/server.js +50 -0
- package/src/services/secret-manager/simulator.js +171 -0
- package/src/services/sns/index.js +89 -76
- package/src/services/sns/server.js +580 -0
- package/src/services/sns/simulator.js +1482 -0
- package/src/services/sqs/index.js +93 -95
- package/src/services/sqs/server.js +349 -345
- package/src/services/sqs/simulator.js +441 -441
- package/src/services/sts/index.js +37 -37
- package/src/services/sts/server.js +144 -142
- package/src/services/sts/simulator.js +69 -69
- package/src/services/xray/index.js +83 -0
- package/src/services/xray/server.js +308 -0
- package/src/services/xray/simulador.js +994 -0
- package/src/template/aws-config-template.js +87 -87
- package/src/template/aws-config-template.mjs +90 -90
- package/src/template/config-template.json +203 -203
- package/src/utils/aws-config.js +91 -91
- package/src/utils/cloudtrail-audit.js +129 -0
- package/src/utils/local-store.js +83 -67
- package/src/utils/logger.js +59 -59
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handler Loader - Carrega handlers de Lambda em diferentes formatos
|
|
3
|
-
* Suporta: CommonJS, ES Modules, TypeScript (compilado)
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const { pathToFileURL } = require('url');
|
|
9
|
-
const logger = require('../../utils/logger');
|
|
10
|
-
|
|
11
|
-
class HandlerLoader {
|
|
12
|
-
/**
|
|
13
|
-
* Carrega um handler de Lambda
|
|
14
|
-
* @param {string} handlerPath - Caminho para o arquivo do handler
|
|
15
|
-
* @param {string} type - Tipo do módulo: 'commonjs', 'module', 'auto'
|
|
16
|
-
* @returns {Promise<Function>} - Função handler
|
|
17
|
-
*/
|
|
18
|
-
static async load(handlerPath, type = 'auto') {
|
|
19
|
-
// Resolve path: try cwd first, then data dir
|
|
20
|
-
let fullPath = path.resolve(process.cwd(), handlerPath);
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(fullPath)) {
|
|
23
|
-
const dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA_DIR;
|
|
24
|
-
if (dataDir) {
|
|
25
|
-
const dataPath = path.resolve(dataDir, 'lambda', handlerPath.replace(/^\.\//, ''));
|
|
26
|
-
if (fs.existsSync(dataPath)) {
|
|
27
|
-
fullPath = dataPath;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!fs.existsSync(fullPath)) {
|
|
33
|
-
throw new Error(`Handler não encontrado: ${fullPath}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
logger.verboso(`Carregando handler: ${fullPath} (type: ${type})`);
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
let handler;
|
|
40
|
-
let resolvedType = type;
|
|
41
|
-
|
|
42
|
-
// Detecta o tipo se for auto
|
|
43
|
-
if (type === 'auto') {
|
|
44
|
-
resolvedType = this.detectType(fullPath);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Carrega baseado no tipo
|
|
48
|
-
if (resolvedType === 'module' || fullPath.endsWith('.mjs')) {
|
|
49
|
-
// ES Module
|
|
50
|
-
const fileUrl = pathToFileURL(fullPath).href;
|
|
51
|
-
const module = await import(fileUrl);
|
|
52
|
-
handler = this.extractHandler(module);
|
|
53
|
-
} else {
|
|
54
|
-
// CommonJS
|
|
55
|
-
// Limpa o cache para permitir hot reload em desenvolvimento
|
|
56
|
-
if (process.env.NODE_ENV === 'development') {
|
|
57
|
-
delete require.cache[require.resolve(fullPath)];
|
|
58
|
-
}
|
|
59
|
-
const module = require(fullPath);
|
|
60
|
-
handler = this.extractHandler(module);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (typeof handler !== 'function') {
|
|
64
|
-
throw new Error(`Handler não é uma função em ${fullPath}. Exporte uma função ou um objeto com handler.`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
logger.debug(`✅ Handler carregado: ${fullPath}`);
|
|
68
|
-
|
|
69
|
-
return handler;
|
|
70
|
-
|
|
71
|
-
} catch (error) {
|
|
72
|
-
logger.error(`❌ Erro ao carregar handler ${fullPath}:`, error);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Extrai a função handler de um módulo
|
|
79
|
-
* Suporta: module.exports = handler, exports.handler, export default
|
|
80
|
-
*/
|
|
81
|
-
static extractHandler(module) {
|
|
82
|
-
// Verifica se é export default
|
|
83
|
-
if (module.default && typeof module.default === 'function') {
|
|
84
|
-
return module.default;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Verifica se é exports.handler
|
|
88
|
-
if (module.handler && typeof module.handler === 'function') {
|
|
89
|
-
return module.handler;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Verifica se o módulo inteiro é uma função
|
|
93
|
-
if (typeof module === 'function') {
|
|
94
|
-
return module;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Tenta encontrar a primeira função exportada
|
|
98
|
-
const exportedFunctions = Object.values(module).filter(v => typeof v === 'function');
|
|
99
|
-
if (exportedFunctions.length === 1) {
|
|
100
|
-
logger.warn(`⚠️ Usando a primeira função exportada como handler: ${exportedFunctions[0].name}`);
|
|
101
|
-
return exportedFunctions[0];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Se tem múltiplas funções, tenta encontrar uma chamada 'handler'
|
|
105
|
-
if (module.handler) {
|
|
106
|
-
return module.handler;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
throw new Error('Não foi possível encontrar uma função handler no módulo');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Detecta o tipo de módulo (CommonJS ou ES Module)
|
|
114
|
-
*/
|
|
115
|
-
static detectType(filePath) {
|
|
116
|
-
// Verifica extensão
|
|
117
|
-
if (filePath.endsWith('.mjs')) {
|
|
118
|
-
return 'module';
|
|
119
|
-
}
|
|
120
|
-
if (filePath.endsWith('.cjs')) {
|
|
121
|
-
return 'commonjs';
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Verifica package.json na mesma pasta ou superior
|
|
125
|
-
try {
|
|
126
|
-
let currentDir = path.dirname(filePath);
|
|
127
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
128
|
-
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
129
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
130
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
131
|
-
if (packageJson.type === 'module') {
|
|
132
|
-
return 'module';
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
currentDir = path.dirname(currentDir);
|
|
137
|
-
}
|
|
138
|
-
} catch (error) {
|
|
139
|
-
// Ignora erro
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return 'commonjs';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Recarrega um handler (útil para hot reload)
|
|
147
|
-
*/
|
|
148
|
-
static async reload(handlerPath, type = 'auto') {
|
|
149
|
-
// Limpa cache
|
|
150
|
-
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
151
|
-
delete require.cache[require.resolve(fullPath)];
|
|
152
|
-
|
|
153
|
-
// Recarrega
|
|
154
|
-
return this.load(handlerPath, type);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Valida se um caminho de handler é válido
|
|
159
|
-
*/
|
|
160
|
-
static isValid(handlerPath) {
|
|
161
|
-
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
162
|
-
return fs.existsSync(fullPath);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Retorna informações sobre o handler
|
|
167
|
-
*/
|
|
168
|
-
static async getInfo(handlerPath) {
|
|
169
|
-
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
170
|
-
const type = this.detectType(fullPath);
|
|
171
|
-
const stats = fs.statSync(fullPath);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
path: fullPath,
|
|
175
|
-
type,
|
|
176
|
-
exists: fs.existsSync(fullPath),
|
|
177
|
-
size: stats.size,
|
|
178
|
-
modified: stats.mtime,
|
|
179
|
-
isValid: this.isValid(handlerPath)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Handler Loader - Carrega handlers de Lambda em diferentes formatos
|
|
3
|
+
* Suporta: CommonJS, ES Modules, TypeScript (compilado)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const { pathToFileURL } = require('url');
|
|
9
|
+
const logger = require('../../utils/logger');
|
|
10
|
+
|
|
11
|
+
class HandlerLoader {
|
|
12
|
+
/**
|
|
13
|
+
* Carrega um handler de Lambda
|
|
14
|
+
* @param {string} handlerPath - Caminho para o arquivo do handler
|
|
15
|
+
* @param {string} type - Tipo do módulo: 'commonjs', 'module', 'auto'
|
|
16
|
+
* @returns {Promise<Function>} - Função handler
|
|
17
|
+
*/
|
|
18
|
+
static async load(handlerPath, type = 'auto') {
|
|
19
|
+
// Resolve path: try cwd first, then data dir
|
|
20
|
+
let fullPath = path.resolve(process.cwd(), handlerPath);
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(fullPath)) {
|
|
23
|
+
const dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA_DIR;
|
|
24
|
+
if (dataDir) {
|
|
25
|
+
const dataPath = path.resolve(dataDir, 'lambda', handlerPath.replace(/^\.\//, ''));
|
|
26
|
+
if (fs.existsSync(dataPath)) {
|
|
27
|
+
fullPath = dataPath;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!fs.existsSync(fullPath)) {
|
|
33
|
+
throw new Error(`Handler não encontrado: ${fullPath}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
logger.verboso(`Carregando handler: ${fullPath} (type: ${type})`);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
let handler;
|
|
40
|
+
let resolvedType = type;
|
|
41
|
+
|
|
42
|
+
// Detecta o tipo se for auto
|
|
43
|
+
if (type === 'auto') {
|
|
44
|
+
resolvedType = this.detectType(fullPath);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Carrega baseado no tipo
|
|
48
|
+
if (resolvedType === 'module' || fullPath.endsWith('.mjs')) {
|
|
49
|
+
// ES Module
|
|
50
|
+
const fileUrl = pathToFileURL(fullPath).href;
|
|
51
|
+
const module = await import(fileUrl);
|
|
52
|
+
handler = this.extractHandler(module);
|
|
53
|
+
} else {
|
|
54
|
+
// CommonJS
|
|
55
|
+
// Limpa o cache para permitir hot reload em desenvolvimento
|
|
56
|
+
if (process.env.NODE_ENV === 'development') {
|
|
57
|
+
delete require.cache[require.resolve(fullPath)];
|
|
58
|
+
}
|
|
59
|
+
const module = require(fullPath);
|
|
60
|
+
handler = this.extractHandler(module);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof handler !== 'function') {
|
|
64
|
+
throw new Error(`Handler não é uma função em ${fullPath}. Exporte uma função ou um objeto com handler.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
logger.debug(`✅ Handler carregado: ${fullPath}`);
|
|
68
|
+
|
|
69
|
+
return handler;
|
|
70
|
+
|
|
71
|
+
} catch (error) {
|
|
72
|
+
logger.error(`❌ Erro ao carregar handler ${fullPath}:`, error);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extrai a função handler de um módulo
|
|
79
|
+
* Suporta: module.exports = handler, exports.handler, export default
|
|
80
|
+
*/
|
|
81
|
+
static extractHandler(module) {
|
|
82
|
+
// Verifica se é export default
|
|
83
|
+
if (module.default && typeof module.default === 'function') {
|
|
84
|
+
return module.default;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Verifica se é exports.handler
|
|
88
|
+
if (module.handler && typeof module.handler === 'function') {
|
|
89
|
+
return module.handler;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Verifica se o módulo inteiro é uma função
|
|
93
|
+
if (typeof module === 'function') {
|
|
94
|
+
return module;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Tenta encontrar a primeira função exportada
|
|
98
|
+
const exportedFunctions = Object.values(module).filter(v => typeof v === 'function');
|
|
99
|
+
if (exportedFunctions.length === 1) {
|
|
100
|
+
logger.warn(`⚠️ Usando a primeira função exportada como handler: ${exportedFunctions[0].name}`);
|
|
101
|
+
return exportedFunctions[0];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Se tem múltiplas funções, tenta encontrar uma chamada 'handler'
|
|
105
|
+
if (module.handler) {
|
|
106
|
+
return module.handler;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
throw new Error('Não foi possível encontrar uma função handler no módulo');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Detecta o tipo de módulo (CommonJS ou ES Module)
|
|
114
|
+
*/
|
|
115
|
+
static detectType(filePath) {
|
|
116
|
+
// Verifica extensão
|
|
117
|
+
if (filePath.endsWith('.mjs')) {
|
|
118
|
+
return 'module';
|
|
119
|
+
}
|
|
120
|
+
if (filePath.endsWith('.cjs')) {
|
|
121
|
+
return 'commonjs';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Verifica package.json na mesma pasta ou superior
|
|
125
|
+
try {
|
|
126
|
+
let currentDir = path.dirname(filePath);
|
|
127
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
128
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
129
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
130
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
131
|
+
if (packageJson.type === 'module') {
|
|
132
|
+
return 'module';
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
currentDir = path.dirname(currentDir);
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
// Ignora erro
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return 'commonjs';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Recarrega um handler (útil para hot reload)
|
|
147
|
+
*/
|
|
148
|
+
static async reload(handlerPath, type = 'auto') {
|
|
149
|
+
// Limpa cache
|
|
150
|
+
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
151
|
+
delete require.cache[require.resolve(fullPath)];
|
|
152
|
+
|
|
153
|
+
// Recarrega
|
|
154
|
+
return this.load(handlerPath, type);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Valida se um caminho de handler é válido
|
|
159
|
+
*/
|
|
160
|
+
static isValid(handlerPath) {
|
|
161
|
+
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
162
|
+
return fs.existsSync(fullPath);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Retorna informações sobre o handler
|
|
167
|
+
*/
|
|
168
|
+
static async getInfo(handlerPath) {
|
|
169
|
+
const fullPath = path.resolve(process.cwd(), handlerPath);
|
|
170
|
+
const type = this.detectType(fullPath);
|
|
171
|
+
const stats = fs.statSync(fullPath);
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
path: fullPath,
|
|
175
|
+
type,
|
|
176
|
+
exists: fs.existsSync(fullPath),
|
|
177
|
+
size: stats.size,
|
|
178
|
+
modified: stats.mtime,
|
|
179
|
+
isValid: this.isValid(handlerPath)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
184
|
module.exports = HandlerLoader;
|
|
@@ -1,74 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lambda Service - Ponto de entrada
|
|
3
|
-
* Exporta o serviço principal e seus componentes
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const LambdaServer = require('./server');
|
|
7
|
-
const LambdaSimulator = require('./simulator');
|
|
8
|
-
|
|
9
|
-
class LambdaService {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.name = 'lambda';
|
|
13
|
-
this.port = config.ports.lambda;
|
|
14
|
-
this.server = null;
|
|
15
|
-
this.simulator = null;
|
|
16
|
-
this.isRunning = false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async initialize() {
|
|
20
|
-
const logger = require('../../utils/logger');
|
|
21
|
-
logger.debug(`Inicializando Lambda Service na porta ${this.port}...`);
|
|
22
|
-
|
|
23
|
-
// Cria o simulador
|
|
24
|
-
this.simulator = new LambdaSimulator(this.config);
|
|
25
|
-
await this.simulator.initialize();
|
|
26
|
-
|
|
27
|
-
// Cria o servidor HTTP
|
|
28
|
-
this.server = new LambdaServer(this.port, this.config);
|
|
29
|
-
this.server.simulator = this.simulator;
|
|
30
|
-
|
|
31
|
-
await this.server.initialize();
|
|
32
|
-
|
|
33
|
-
logger.debug('Lambda Service inicializado');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Lambda Service - Ponto de entrada
|
|
3
|
+
* Exporta o serviço principal e seus componentes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const LambdaServer = require('./server');
|
|
7
|
+
const LambdaSimulator = require('./simulator');
|
|
8
|
+
|
|
9
|
+
class LambdaService {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.name = 'lambda';
|
|
13
|
+
this.port = config.ports.lambda;
|
|
14
|
+
this.server = null;
|
|
15
|
+
this.simulator = null;
|
|
16
|
+
this.isRunning = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async initialize() {
|
|
20
|
+
const logger = require('../../utils/logger');
|
|
21
|
+
logger.debug(`Inicializando Lambda Service na porta ${this.port}...`);
|
|
22
|
+
|
|
23
|
+
// Cria o simulador
|
|
24
|
+
this.simulator = new LambdaSimulator(this.config);
|
|
25
|
+
await this.simulator.initialize();
|
|
26
|
+
|
|
27
|
+
// Cria o servidor HTTP
|
|
28
|
+
this.server = new LambdaServer(this.port, this.config);
|
|
29
|
+
this.server.simulator = this.simulator;
|
|
30
|
+
|
|
31
|
+
await this.server.initialize();
|
|
32
|
+
|
|
33
|
+
logger.debug('Lambda Service inicializado');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
injectDependencies(server) {
|
|
37
|
+
const ct = server.getService('cloudtrail');
|
|
38
|
+
if (ct?.simulator) this.simulator.audit.setTrail(ct.simulator);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async start() {
|
|
42
|
+
if (this.isRunning) return;
|
|
43
|
+
await this.server.start();
|
|
44
|
+
this.isRunning = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async stop() {
|
|
48
|
+
if (!this.isRunning) return;
|
|
49
|
+
await this.server.stop();
|
|
50
|
+
this.isRunning = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async reset() {
|
|
54
|
+
await this.simulator.reset();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getStatus() {
|
|
58
|
+
return {
|
|
59
|
+
running: this.isRunning,
|
|
60
|
+
port: this.port,
|
|
61
|
+
endpoint: `http://localhost:${this.port}`,
|
|
62
|
+
lambdasCount: this.simulator?.getLambdasCount() || 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getHandler(path) {
|
|
67
|
+
return this.simulator?.getHandler(path);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getSimulator() {
|
|
71
|
+
return this.simulator;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getServer() {
|
|
75
|
+
return this.server;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
module.exports = LambdaService;
|