@gugananuvem/aws-local-simulator 1.0.33 ā 1.0.34
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 +834 -834
- package/aws-config +153 -153
- package/bin/aws-local-simulator.js +63 -63
- package/package.json +3 -2
- package/src/config/config-loader.js +114 -114
- package/src/config/default-config.js +79 -79
- package/src/config/env-loader.js +68 -68
- package/src/index.js +146 -146
- package/src/index.mjs +123 -123
- package/src/server.js +463 -463
- package/src/services/apigateway/index.js +75 -75
- package/src/services/apigateway/server.js +607 -607
- package/src/services/apigateway/simulator.js +1405 -1405
- package/src/services/athena/index.js +75 -75
- package/src/services/athena/server.js +101 -101
- package/src/services/athena/simulador.js +998 -998
- package/src/services/athena/simulator.js +346 -346
- package/src/services/cloudformation/index.js +106 -106
- package/src/services/cloudformation/server.js +417 -417
- package/src/services/cloudformation/simulador.js +1020 -1020
- package/src/services/cloudtrail/index.js +84 -84
- package/src/services/cloudtrail/server.js +235 -235
- package/src/services/cloudtrail/simulador.js +719 -719
- package/src/services/cloudwatch/index.js +84 -84
- package/src/services/cloudwatch/server.js +366 -366
- package/src/services/cloudwatch/simulador.js +1173 -1173
- package/src/services/cognito/index.js +79 -79
- package/src/services/cognito/server.js +297 -297
- package/src/services/cognito/simulator.js +1992 -1761
- package/src/services/config/index.js +96 -96
- package/src/services/config/server.js +215 -215
- package/src/services/config/simulador.js +1260 -1260
- package/src/services/dynamodb/index.js +74 -74
- package/src/services/dynamodb/server.js +139 -139
- package/src/services/dynamodb/simulator.js +1005 -994
- package/src/services/dynamodb/sqlite-store.js +722 -0
- package/src/services/ecs/index.js +65 -65
- package/src/services/ecs/server.js +235 -235
- package/src/services/ecs/simulator.js +844 -844
- package/src/services/eventbridge/index.js +89 -89
- package/src/services/eventbridge/server.js +209 -209
- package/src/services/eventbridge/simulator.js +684 -684
- package/src/services/index.js +45 -45
- package/src/services/kms/index.js +75 -75
- package/src/services/kms/server.js +81 -81
- package/src/services/kms/simulator.js +344 -344
- package/src/services/lambda/handler-loader.js +183 -183
- package/src/services/lambda/index.js +81 -81
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +191 -191
- package/src/services/lambda/simulator.js +364 -364
- package/src/services/parameter-store/index.js +80 -80
- package/src/services/parameter-store/server.js +50 -50
- package/src/services/parameter-store/simulator.js +201 -201
- package/src/services/s3/index.js +73 -73
- package/src/services/s3/server.js +350 -350
- package/src/services/s3/simulator.js +568 -568
- package/src/services/secret-manager/index.js +80 -80
- package/src/services/secret-manager/server.js +51 -51
- package/src/services/secret-manager/simulator.js +182 -182
- package/src/services/sns/index.js +89 -89
- package/src/services/sns/server.js +607 -607
- package/src/services/sns/simulator.js +1482 -1482
- package/src/services/sqs/index.js +98 -98
- package/src/services/sqs/server.js +360 -360
- package/src/services/sqs/simulator.js +509 -509
- package/src/services/sts/index.js +37 -37
- package/src/services/sts/server.js +144 -144
- package/src/services/sts/simulator.js +69 -69
- package/src/services/xray/index.js +83 -83
- package/src/services/xray/server.js +308 -308
- package/src/services/xray/simulador.js +994 -994
- 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 -129
- package/src/utils/local-store.js +83 -83
- package/src/utils/logger.js +59 -59
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lambda Server - Servidor HTTP para Lambda (API Gateway style)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const express = require('express');
|
|
6
|
-
const cors = require('cors');
|
|
7
|
-
const LambdaSimulator = require('./simulator');
|
|
8
|
-
const logger = require('../../utils/logger');
|
|
9
|
-
|
|
10
|
-
class LambdaServer {
|
|
11
|
-
constructor(port, config) {
|
|
12
|
-
this.port = port;
|
|
13
|
-
this.config = config;
|
|
14
|
-
this.app = express();
|
|
15
|
-
this.simulator = null;
|
|
16
|
-
this.server = null;
|
|
17
|
-
this.setupMiddlewares();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setupMiddlewares() {
|
|
21
|
-
this.app.use(express.urlencoded({ extended: true }));
|
|
22
|
-
this.app.use(cors());
|
|
23
|
-
|
|
24
|
-
// Logging de requisiƧƵes
|
|
25
|
-
if (logger.currentLogLevel === 'verboso') {
|
|
26
|
-
this.app.use((req, res, next) => {
|
|
27
|
-
const start = Date.now();
|
|
28
|
-
res.on('finish', () => {
|
|
29
|
-
const duration = Date.now() - start;
|
|
30
|
-
logger.verboso(`Lambda: ${req.method} ${req.path} - ${duration}ms`);
|
|
31
|
-
});
|
|
32
|
-
next();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async initialize() {
|
|
38
|
-
this.simulator = new LambdaSimulator(this.config);
|
|
39
|
-
await this.simulator.initialize();
|
|
40
|
-
this.setupRoutes();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setupRoutes() {
|
|
44
|
-
// Health check
|
|
45
|
-
this.app.get('/health', (req, res) => {
|
|
46
|
-
res.json({ status: 'healthy', lambdas: this.simulator.getLambdasCount() });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// AWS Lambda Invoke API: POST /2015-03-31/functions/{functionName}/invocations
|
|
50
|
-
this.app.post('/2015-03-31/functions/:functionName/invocations', async (req, res) => {
|
|
51
|
-
const { functionName } = req.params;
|
|
52
|
-
const invocationType = req.headers['x-amz-invocation-type'] || 'RequestResponse';
|
|
53
|
-
|
|
54
|
-
// Read body directly from stream, bypassing all body parsers
|
|
55
|
-
let event = {};
|
|
56
|
-
try {
|
|
57
|
-
const rawBody = await new Promise((resolve, reject) => {
|
|
58
|
-
const chunks = [];
|
|
59
|
-
req.on('data', chunk => chunks.push(chunk));
|
|
60
|
-
req.on('end', () => resolve(Buffer.concat(chunks)));
|
|
61
|
-
req.on('error', reject);
|
|
62
|
-
});
|
|
63
|
-
if (rawBody.length > 0) {
|
|
64
|
-
event = JSON.parse(rawBody.toString('utf8'));
|
|
65
|
-
}
|
|
66
|
-
} catch {
|
|
67
|
-
event = {};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
logger.debug(`Lambda invoke: ${functionName} (${invocationType})`);
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const result = await this.simulator.invoke(functionName, event, invocationType);
|
|
74
|
-
|
|
75
|
-
if (invocationType === 'Event') {
|
|
76
|
-
return res.status(202).send();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
res.status(result.StatusCode || 200).json(result.Payload);
|
|
80
|
-
} catch (err) {
|
|
81
|
-
if (err.message && err.message.includes('Function not found')) {
|
|
82
|
-
return res.status(404).json({ __type: 'ResourceNotFoundException', message: err.message });
|
|
83
|
-
}
|
|
84
|
-
logger.error('Lambda invoke error:', err);
|
|
85
|
-
res.status(500).json({ __type: 'ServiceException', message: err.message });
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Admin endpoints
|
|
90
|
-
this.setupAdminRoutes();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setupAdminRoutes() {
|
|
94
|
-
// Helper: parse Buffer body as JSON for admin routes
|
|
95
|
-
const parseJson = (req, res, next) => {
|
|
96
|
-
if (Buffer.isBuffer(req.body) && req.body.length > 0) {
|
|
97
|
-
try { req.body = JSON.parse(req.body.toString('utf8')); } catch { req.body = {}; }
|
|
98
|
-
}
|
|
99
|
-
next();
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
this.app.get('/__admin/functions', (req, res) => {
|
|
103
|
-
res.json(this.simulator.listLambdas());
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
this.app.post('/__admin/functions', parseJson, async (req, res) => {
|
|
107
|
-
try {
|
|
108
|
-
const lambda = await this.simulator.createFunction(req.body);
|
|
109
|
-
res.status(201).json(lambda);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
res.status(400).json({ error: err.message });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
this.app.put('/__admin/functions/:name', parseJson, async (req, res) => {
|
|
116
|
-
try {
|
|
117
|
-
const lambda = await this.simulator.updateFunction(req.params.name, req.body);
|
|
118
|
-
res.json(lambda);
|
|
119
|
-
} catch (err) {
|
|
120
|
-
res.status(400).json({ error: err.message });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
this.app.delete('/__admin/functions/:name', async (req, res) => {
|
|
125
|
-
const deleted = await this.simulator.deleteFunction(req.params.name);
|
|
126
|
-
if (deleted) res.json({ message: 'Lambda deleted' });
|
|
127
|
-
else res.status(404).json({ error: 'Lambda not found' });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
this.app.post('/__admin/reload', async (req, res) => {
|
|
131
|
-
await this.simulator.reloadLambdas();
|
|
132
|
-
res.json({ message: 'Lambdas recarregadas', count: this.simulator.getLambdasCount() });
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
this.app.post('/__admin/env', parseJson, (req, res) => {
|
|
136
|
-
const { key, value } = req.body;
|
|
137
|
-
if (key && value !== undefined) {
|
|
138
|
-
this.simulator.setEnvironmentVariable(key, value);
|
|
139
|
-
res.json({ message: `Environment variable ${key} set` });
|
|
140
|
-
} else {
|
|
141
|
-
res.status(400).json({ error: 'Missing key or value' });
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
this.app.get('/__admin/env', (req, res) => {
|
|
146
|
-
res.json(this.simulator.getEnvironmentVariables());
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
this.app.get('/__admin/stats', (req, res) => {
|
|
150
|
-
res.json(this.simulator.getStats());
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
start() {
|
|
155
|
-
return new Promise((resolve) => {
|
|
156
|
-
this.server = this.app.listen(this.port, () => {
|
|
157
|
-
logger.info(`š Lambda API rodando em http://localhost:${this.port}`);
|
|
158
|
-
this.printRoutes();
|
|
159
|
-
resolve();
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
printRoutes() {
|
|
165
|
-
logger.info('\nš Lambdas registradas:');
|
|
166
|
-
const lambdas = this.simulator.listLambdas();
|
|
167
|
-
for (const lambda of lambdas) {
|
|
168
|
-
logger.info(` ${lambda.name.padEnd(30)} -> ${lambda.handlerName || 'anonymous'}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
stop() {
|
|
173
|
-
return new Promise((resolve) => {
|
|
174
|
-
if (this.server) {
|
|
175
|
-
this.server.close(() => resolve());
|
|
176
|
-
} else {
|
|
177
|
-
resolve();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getStatus() {
|
|
183
|
-
return {
|
|
184
|
-
running: !!this.server,
|
|
185
|
-
port: this.port,
|
|
186
|
-
endpoint: `http://localhost:${this.port}`,
|
|
187
|
-
lambdasCount: this.simulator?.getLambdasCount() || 0
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Lambda Server - Servidor HTTP para Lambda (API Gateway style)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const express = require('express');
|
|
6
|
+
const cors = require('cors');
|
|
7
|
+
const LambdaSimulator = require('./simulator');
|
|
8
|
+
const logger = require('../../utils/logger');
|
|
9
|
+
|
|
10
|
+
class LambdaServer {
|
|
11
|
+
constructor(port, config) {
|
|
12
|
+
this.port = port;
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.app = express();
|
|
15
|
+
this.simulator = null;
|
|
16
|
+
this.server = null;
|
|
17
|
+
this.setupMiddlewares();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setupMiddlewares() {
|
|
21
|
+
this.app.use(express.urlencoded({ extended: true }));
|
|
22
|
+
this.app.use(cors());
|
|
23
|
+
|
|
24
|
+
// Logging de requisiƧƵes
|
|
25
|
+
if (logger.currentLogLevel === 'verboso') {
|
|
26
|
+
this.app.use((req, res, next) => {
|
|
27
|
+
const start = Date.now();
|
|
28
|
+
res.on('finish', () => {
|
|
29
|
+
const duration = Date.now() - start;
|
|
30
|
+
logger.verboso(`Lambda: ${req.method} ${req.path} - ${duration}ms`);
|
|
31
|
+
});
|
|
32
|
+
next();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async initialize() {
|
|
38
|
+
this.simulator = new LambdaSimulator(this.config);
|
|
39
|
+
await this.simulator.initialize();
|
|
40
|
+
this.setupRoutes();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setupRoutes() {
|
|
44
|
+
// Health check
|
|
45
|
+
this.app.get('/health', (req, res) => {
|
|
46
|
+
res.json({ status: 'healthy', lambdas: this.simulator.getLambdasCount() });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// AWS Lambda Invoke API: POST /2015-03-31/functions/{functionName}/invocations
|
|
50
|
+
this.app.post('/2015-03-31/functions/:functionName/invocations', async (req, res) => {
|
|
51
|
+
const { functionName } = req.params;
|
|
52
|
+
const invocationType = req.headers['x-amz-invocation-type'] || 'RequestResponse';
|
|
53
|
+
|
|
54
|
+
// Read body directly from stream, bypassing all body parsers
|
|
55
|
+
let event = {};
|
|
56
|
+
try {
|
|
57
|
+
const rawBody = await new Promise((resolve, reject) => {
|
|
58
|
+
const chunks = [];
|
|
59
|
+
req.on('data', chunk => chunks.push(chunk));
|
|
60
|
+
req.on('end', () => resolve(Buffer.concat(chunks)));
|
|
61
|
+
req.on('error', reject);
|
|
62
|
+
});
|
|
63
|
+
if (rawBody.length > 0) {
|
|
64
|
+
event = JSON.parse(rawBody.toString('utf8'));
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
event = {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
logger.debug(`Lambda invoke: ${functionName} (${invocationType})`);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const result = await this.simulator.invoke(functionName, event, invocationType);
|
|
74
|
+
|
|
75
|
+
if (invocationType === 'Event') {
|
|
76
|
+
return res.status(202).send();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
res.status(result.StatusCode || 200).json(result.Payload);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err.message && err.message.includes('Function not found')) {
|
|
82
|
+
return res.status(404).json({ __type: 'ResourceNotFoundException', message: err.message });
|
|
83
|
+
}
|
|
84
|
+
logger.error('Lambda invoke error:', err);
|
|
85
|
+
res.status(500).json({ __type: 'ServiceException', message: err.message });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Admin endpoints
|
|
90
|
+
this.setupAdminRoutes();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setupAdminRoutes() {
|
|
94
|
+
// Helper: parse Buffer body as JSON for admin routes
|
|
95
|
+
const parseJson = (req, res, next) => {
|
|
96
|
+
if (Buffer.isBuffer(req.body) && req.body.length > 0) {
|
|
97
|
+
try { req.body = JSON.parse(req.body.toString('utf8')); } catch { req.body = {}; }
|
|
98
|
+
}
|
|
99
|
+
next();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
this.app.get('/__admin/functions', (req, res) => {
|
|
103
|
+
res.json(this.simulator.listLambdas());
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this.app.post('/__admin/functions', parseJson, async (req, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const lambda = await this.simulator.createFunction(req.body);
|
|
109
|
+
res.status(201).json(lambda);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
res.status(400).json({ error: err.message });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
this.app.put('/__admin/functions/:name', parseJson, async (req, res) => {
|
|
116
|
+
try {
|
|
117
|
+
const lambda = await this.simulator.updateFunction(req.params.name, req.body);
|
|
118
|
+
res.json(lambda);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
res.status(400).json({ error: err.message });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
this.app.delete('/__admin/functions/:name', async (req, res) => {
|
|
125
|
+
const deleted = await this.simulator.deleteFunction(req.params.name);
|
|
126
|
+
if (deleted) res.json({ message: 'Lambda deleted' });
|
|
127
|
+
else res.status(404).json({ error: 'Lambda not found' });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this.app.post('/__admin/reload', async (req, res) => {
|
|
131
|
+
await this.simulator.reloadLambdas();
|
|
132
|
+
res.json({ message: 'Lambdas recarregadas', count: this.simulator.getLambdasCount() });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
this.app.post('/__admin/env', parseJson, (req, res) => {
|
|
136
|
+
const { key, value } = req.body;
|
|
137
|
+
if (key && value !== undefined) {
|
|
138
|
+
this.simulator.setEnvironmentVariable(key, value);
|
|
139
|
+
res.json({ message: `Environment variable ${key} set` });
|
|
140
|
+
} else {
|
|
141
|
+
res.status(400).json({ error: 'Missing key or value' });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
this.app.get('/__admin/env', (req, res) => {
|
|
146
|
+
res.json(this.simulator.getEnvironmentVariables());
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
this.app.get('/__admin/stats', (req, res) => {
|
|
150
|
+
res.json(this.simulator.getStats());
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
start() {
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
this.server = this.app.listen(this.port, () => {
|
|
157
|
+
logger.info(`š Lambda API rodando em http://localhost:${this.port}`);
|
|
158
|
+
this.printRoutes();
|
|
159
|
+
resolve();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
printRoutes() {
|
|
165
|
+
logger.info('\nš Lambdas registradas:');
|
|
166
|
+
const lambdas = this.simulator.listLambdas();
|
|
167
|
+
for (const lambda of lambdas) {
|
|
168
|
+
logger.info(` ${lambda.name.padEnd(30)} -> ${lambda.handlerName || 'anonymous'}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
stop() {
|
|
173
|
+
return new Promise((resolve) => {
|
|
174
|
+
if (this.server) {
|
|
175
|
+
this.server.close(() => resolve());
|
|
176
|
+
} else {
|
|
177
|
+
resolve();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getStatus() {
|
|
183
|
+
return {
|
|
184
|
+
running: !!this.server,
|
|
185
|
+
port: this.port,
|
|
186
|
+
endpoint: `http://localhost:${this.port}`,
|
|
187
|
+
lambdasCount: this.simulator?.getLambdasCount() || 0
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
192
|
module.exports = LambdaServer;
|