@gugananuvem/aws-local-simulator 1.0.10 → 1.0.12

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.
Files changed (44) hide show
  1. package/README.md +257 -193
  2. package/bin/aws-local-simulator.js +62 -62
  3. package/package.json +2 -2
  4. package/src/config/config-loader.js +114 -112
  5. package/src/config/default-config.js +67 -65
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +130 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +223 -222
  10. package/src/services/apigateway/index.js +68 -66
  11. package/src/services/apigateway/server.js +487 -434
  12. package/src/services/apigateway/simulator.js +1251 -1251
  13. package/src/services/cognito/index.js +65 -65
  14. package/src/services/cognito/server.js +279 -228
  15. package/src/services/cognito/simulator.js +1114 -847
  16. package/src/services/dynamodb/index.js +70 -70
  17. package/src/services/dynamodb/server.js +121 -121
  18. package/src/services/dynamodb/simulator.js +620 -614
  19. package/src/services/ecs/index.js +65 -65
  20. package/src/services/ecs/server.js +233 -233
  21. package/src/services/ecs/simulator.js +844 -844
  22. package/src/services/eventbridge/index.js +84 -84
  23. package/src/services/index.js +18 -18
  24. package/src/services/lambda/handler-loader.js +183 -172
  25. package/src/services/lambda/index.js +73 -72
  26. package/src/services/lambda/route-registry.js +274 -274
  27. package/src/services/lambda/server.js +145 -152
  28. package/src/services/lambda/simulator.js +172 -285
  29. package/src/services/s3/index.js +69 -69
  30. package/src/services/s3/server.js +238 -238
  31. package/src/services/s3/simulator.js +740 -740
  32. package/src/services/sns/index.js +75 -75
  33. package/src/services/sqs/index.js +95 -95
  34. package/src/services/sqs/server.js +345 -273
  35. package/src/services/sqs/simulator.js +441 -660
  36. package/src/services/sts/index.js +37 -0
  37. package/src/services/sts/server.js +142 -0
  38. package/src/services/sts/simulator.js +69 -0
  39. package/src/template/aws-config-template.js +87 -87
  40. package/src/template/aws-config-template.mjs +90 -90
  41. package/src/template/config-template.json +203 -203
  42. package/src/utils/aws-config.js +91 -91
  43. package/src/utils/local-store.js +67 -67
  44. package/src/utils/logger.js +59 -59
@@ -1,66 +1,66 @@
1
- /**
2
- * ECS Service - Simulador de Elastic Container Service
3
- * Suporta: Fargate, EC2 launch types, Tasks, Services
4
- */
5
-
6
- const ECSServer = require('./server');
7
- const ECSSimulator = require('./simulator');
8
-
9
- class ECSService {
10
- constructor(config) {
11
- this.config = config;
12
- this.name = 'ecs';
13
- this.port = config.ports.ecs || 8080;
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 ECS Service na porta ${this.port}...`);
22
-
23
- this.simulator = new ECSSimulator(this.config);
24
- await this.simulator.initialize();
25
-
26
- this.server = new ECSServer(this.port, this.config);
27
- this.server.simulator = this.simulator;
28
-
29
- await this.server.initialize();
30
-
31
- logger.debug('ECS Service inicializado');
32
- }
33
-
34
- async start() {
35
- if (this.isRunning) return;
36
- await this.server.start();
37
- this.isRunning = true;
38
- }
39
-
40
- async stop() {
41
- if (!this.isRunning) return;
42
- await this.server.stop();
43
- this.isRunning = false;
44
- }
45
-
46
- async reset() {
47
- await this.simulator.reset();
48
- }
49
-
50
- getStatus() {
51
- return {
52
- running: this.isRunning,
53
- port: this.port,
54
- endpoint: `http://localhost:${this.port}`,
55
- clustersCount: this.simulator?.getClustersCount() || 0,
56
- servicesCount: this.simulator?.getServicesCount() || 0,
57
- tasksCount: this.simulator?.getTasksCount() || 0
58
- };
59
- }
60
-
61
- getSimulator() {
62
- return this.simulator;
63
- }
64
- }
65
-
1
+ /**
2
+ * ECS Service - Simulador de Elastic Container Service
3
+ * Suporta: Fargate, EC2 launch types, Tasks, Services
4
+ */
5
+
6
+ const ECSServer = require('./server');
7
+ const ECSSimulator = require('./simulator');
8
+
9
+ class ECSService {
10
+ constructor(config) {
11
+ this.config = config;
12
+ this.name = 'ecs';
13
+ this.port = config.ports.ecs || 8080;
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 ECS Service na porta ${this.port}...`);
22
+
23
+ this.simulator = new ECSSimulator(this.config);
24
+ await this.simulator.initialize();
25
+
26
+ this.server = new ECSServer(this.port, this.config);
27
+ this.server.simulator = this.simulator;
28
+
29
+ await this.server.initialize();
30
+
31
+ logger.debug('ECS Service inicializado');
32
+ }
33
+
34
+ async start() {
35
+ if (this.isRunning) return;
36
+ await this.server.start();
37
+ this.isRunning = true;
38
+ }
39
+
40
+ async stop() {
41
+ if (!this.isRunning) return;
42
+ await this.server.stop();
43
+ this.isRunning = false;
44
+ }
45
+
46
+ async reset() {
47
+ await this.simulator.reset();
48
+ }
49
+
50
+ getStatus() {
51
+ return {
52
+ running: this.isRunning,
53
+ port: this.port,
54
+ endpoint: `http://localhost:${this.port}`,
55
+ clustersCount: this.simulator?.getClustersCount() || 0,
56
+ servicesCount: this.simulator?.getServicesCount() || 0,
57
+ tasksCount: this.simulator?.getTasksCount() || 0
58
+ };
59
+ }
60
+
61
+ getSimulator() {
62
+ return this.simulator;
63
+ }
64
+ }
65
+
66
66
  module.exports = ECSService;
@@ -1,234 +1,234 @@
1
- /**
2
- * ECS Server - Servidor HTTP para ECS API
3
- */
4
-
5
- const express = require('express');
6
- const logger = require('../../utils/logger');
7
-
8
- class ECSServer {
9
- constructor(port, config) {
10
- this.port = port;
11
- this.config = config;
12
- this.app = express();
13
- this.simulator = null;
14
- this.server = null;
15
- this.setupMiddlewares();
16
- }
17
-
18
- setupMiddlewares() {
19
- this.app.use(express.json());
20
-
21
- if (logger.currentLogLevel === 'verboso') {
22
- this.app.use((req, res, next) => {
23
- const start = Date.now();
24
- res.on('finish', () => {
25
- const duration = Date.now() - start;
26
- logger.verboso(`ECS: ${req.method} ${req.path} - ${duration}ms`);
27
- });
28
- next();
29
- });
30
- }
31
- }
32
-
33
- async initialize() {
34
- this.setupRoutes();
35
- logger.debug('ECS Server inicializado');
36
- }
37
-
38
- setupRoutes() {
39
- // Health check
40
- this.app.get('/health', (req, res) => {
41
- res.json({
42
- status: 'healthy',
43
- service: 'ecs-simulator',
44
- version: '1.0.0'
45
- });
46
- });
47
-
48
- // Cluster operations
49
- this.app.post('/clusters', (req, res) => {
50
- const { clusterName } = req.body;
51
- const result = this.simulator.createCluster(clusterName);
52
- if (result.error) {
53
- res.status(result.status).json(result.error);
54
- } else {
55
- res.json(result.cluster);
56
- }
57
- });
58
-
59
- this.app.get('/clusters', (req, res) => {
60
- const clusters = this.simulator.listClusters();
61
- res.json({ clusterArns: clusters.map(c => `arn:aws:ecs:local:000000000000:cluster/${c}`) });
62
- });
63
-
64
- this.app.get('/clusters/:clusterName', (req, res) => {
65
- try {
66
- const result = this.simulator.describeCluster(req.params.clusterName);
67
- res.json(result);
68
- } catch (error) {
69
- res.status(404).json({ error: error.message });
70
- }
71
- });
72
-
73
- this.app.delete('/clusters/:clusterName', (req, res) => {
74
- const result = this.simulator.deleteCluster(req.params.clusterName);
75
- if (result.error) {
76
- res.status(result.status).json(result.error);
77
- } else {
78
- res.json({ message: 'Cluster deleted' });
79
- }
80
- });
81
-
82
- // Task Definition operations
83
- this.app.post('/task-definitions', (req, res) => {
84
- const result = this.simulator.registerTaskDefinition(req.body);
85
- if (result.error) {
86
- res.status(result.status).json(result.error);
87
- } else {
88
- res.json(result.taskDefinition);
89
- }
90
- });
91
-
92
- // Service operations
93
- this.app.post('/services', (req, res) => {
94
- const result = this.simulator.createService(req.body);
95
- if (result.error) {
96
- res.status(result.status).json(result.error);
97
- } else {
98
- res.json(result.service);
99
- }
100
- });
101
-
102
- this.app.put('/services/:serviceName', (req, res) => {
103
- const result = this.simulator.updateService({
104
- ...req.body,
105
- service: req.params.serviceName
106
- });
107
- if (result.error) {
108
- res.status(result.status).json(result.error);
109
- } else {
110
- res.json(result.service);
111
- }
112
- });
113
-
114
- // Task operations
115
- this.app.post('/tasks', (req, res) => {
116
- this.simulator.runTask(req.body).then(result => {
117
- if (result.error) {
118
- res.status(result.status).json(result.error);
119
- } else {
120
- res.json(result.task);
121
- }
122
- });
123
- });
124
-
125
- this.app.get('/tasks', (req, res) => {
126
- const result = this.simulator.listTasks(req.query);
127
- res.json(result);
128
- });
129
-
130
- this.app.post('/tasks/describe', (req, res) => {
131
- const result = this.simulator.describeTasks(req.body);
132
- res.json(result);
133
- });
134
-
135
- this.app.post('/tasks/:taskArn/stop', (req, res) => {
136
- this.simulator.stopTask(req.params.taskArn).then(result => {
137
- if (result.error) {
138
- res.status(result.status).json(result.error);
139
- } else {
140
- res.json(result.task);
141
- }
142
- });
143
- });
144
-
145
- // Admin endpoints
146
- this.setupAdminRoutes();
147
- }
148
-
149
- setupAdminRoutes() {
150
- this.app.get('/__admin/clusters', (req, res) => {
151
- res.json({
152
- clusters: this.simulator.getClustersCount(),
153
- services: this.simulator.getServicesCount(),
154
- tasks: this.simulator.getTasksCount(),
155
- runningContainers: this.simulator.getRunningContainers()
156
- });
157
- });
158
-
159
- this.app.get('/__admin/clusters/:clusterName/details', (req, res) => {
160
- const cluster = this.simulator.clusters.get(req.params.clusterName);
161
- if (cluster) {
162
- res.json(cluster);
163
- } else {
164
- res.status(404).json({ error: 'Cluster not found' });
165
- }
166
- });
167
-
168
- this.app.get('/__admin/containers', (req, res) => {
169
- const containers = [];
170
- for (const [id, process] of this.simulator.containerProcesses) {
171
- containers.push({
172
- containerId: id,
173
- taskArn: process.taskArn,
174
- container: process.container,
175
- running: process.running,
176
- startTime: process.startTime
177
- });
178
- }
179
- res.json(containers);
180
- });
181
-
182
- this.app.get('/__admin/ports', (req, res) => {
183
- res.json({
184
- availablePorts: Array.from(this.simulator.availablePorts),
185
- usedPorts: this.getUsedPorts()
186
- });
187
- });
188
- }
189
-
190
- getUsedPorts() {
191
- const usedPorts = [];
192
- for (const [_, process] of this.simulator.containerProcesses) {
193
- for (const mapping of process.container.portMappings) {
194
- if (mapping.hostPort) {
195
- usedPorts.push(mapping.hostPort);
196
- }
197
- }
198
- }
199
- return usedPorts;
200
- }
201
-
202
- start() {
203
- return new Promise((resolve) => {
204
- this.server = this.app.listen(this.port, () => {
205
- logger.info(`🐳 ECS/Fargate rodando em http://localhost:${this.port}`);
206
- resolve();
207
- });
208
- });
209
- }
210
-
211
- stop() {
212
- return new Promise((resolve) => {
213
- if (this.server) {
214
- this.server.close(() => resolve());
215
- } else {
216
- resolve();
217
- }
218
- });
219
- }
220
-
221
- getStatus() {
222
- return {
223
- running: !!this.server,
224
- port: this.port,
225
- endpoint: `http://localhost:${this.port}`,
226
- clustersCount: this.simulator?.getClustersCount() || 0,
227
- servicesCount: this.simulator?.getServicesCount() || 0,
228
- tasksCount: this.simulator?.getTasksCount() || 0,
229
- runningContainers: this.simulator?.getRunningContainers() || 0
230
- };
231
- }
232
- }
233
-
1
+ /**
2
+ * ECS Server - Servidor HTTP para ECS API
3
+ */
4
+
5
+ const express = require('express');
6
+ const logger = require('../../utils/logger');
7
+
8
+ class ECSServer {
9
+ constructor(port, config) {
10
+ this.port = port;
11
+ this.config = config;
12
+ this.app = express();
13
+ this.simulator = null;
14
+ this.server = null;
15
+ this.setupMiddlewares();
16
+ }
17
+
18
+ setupMiddlewares() {
19
+ this.app.use(express.json());
20
+
21
+ if (logger.currentLogLevel === 'verboso') {
22
+ this.app.use((req, res, next) => {
23
+ const start = Date.now();
24
+ res.on('finish', () => {
25
+ const duration = Date.now() - start;
26
+ logger.verboso(`ECS: ${req.method} ${req.path} - ${duration}ms`);
27
+ });
28
+ next();
29
+ });
30
+ }
31
+ }
32
+
33
+ async initialize() {
34
+ this.setupRoutes();
35
+ logger.debug('ECS Server inicializado');
36
+ }
37
+
38
+ setupRoutes() {
39
+ // Health check
40
+ this.app.get('/health', (req, res) => {
41
+ res.json({
42
+ status: 'healthy',
43
+ service: 'ecs-simulator',
44
+ version: '1.0.0'
45
+ });
46
+ });
47
+
48
+ // Cluster operations
49
+ this.app.post('/clusters', (req, res) => {
50
+ const { clusterName } = req.body;
51
+ const result = this.simulator.createCluster(clusterName);
52
+ if (result.error) {
53
+ res.status(result.status).json(result.error);
54
+ } else {
55
+ res.json(result.cluster);
56
+ }
57
+ });
58
+
59
+ this.app.get('/clusters', (req, res) => {
60
+ const clusters = this.simulator.listClusters();
61
+ res.json({ clusterArns: clusters.map(c => `arn:aws:ecs:local:000000000000:cluster/${c}`) });
62
+ });
63
+
64
+ this.app.get('/clusters/:clusterName', (req, res) => {
65
+ try {
66
+ const result = this.simulator.describeCluster(req.params.clusterName);
67
+ res.json(result);
68
+ } catch (error) {
69
+ res.status(404).json({ error: error.message });
70
+ }
71
+ });
72
+
73
+ this.app.delete('/clusters/:clusterName', (req, res) => {
74
+ const result = this.simulator.deleteCluster(req.params.clusterName);
75
+ if (result.error) {
76
+ res.status(result.status).json(result.error);
77
+ } else {
78
+ res.json({ message: 'Cluster deleted' });
79
+ }
80
+ });
81
+
82
+ // Task Definition operations
83
+ this.app.post('/task-definitions', (req, res) => {
84
+ const result = this.simulator.registerTaskDefinition(req.body);
85
+ if (result.error) {
86
+ res.status(result.status).json(result.error);
87
+ } else {
88
+ res.json(result.taskDefinition);
89
+ }
90
+ });
91
+
92
+ // Service operations
93
+ this.app.post('/services', (req, res) => {
94
+ const result = this.simulator.createService(req.body);
95
+ if (result.error) {
96
+ res.status(result.status).json(result.error);
97
+ } else {
98
+ res.json(result.service);
99
+ }
100
+ });
101
+
102
+ this.app.put('/services/:serviceName', (req, res) => {
103
+ const result = this.simulator.updateService({
104
+ ...req.body,
105
+ service: req.params.serviceName
106
+ });
107
+ if (result.error) {
108
+ res.status(result.status).json(result.error);
109
+ } else {
110
+ res.json(result.service);
111
+ }
112
+ });
113
+
114
+ // Task operations
115
+ this.app.post('/tasks', (req, res) => {
116
+ this.simulator.runTask(req.body).then(result => {
117
+ if (result.error) {
118
+ res.status(result.status).json(result.error);
119
+ } else {
120
+ res.json(result.task);
121
+ }
122
+ });
123
+ });
124
+
125
+ this.app.get('/tasks', (req, res) => {
126
+ const result = this.simulator.listTasks(req.query);
127
+ res.json(result);
128
+ });
129
+
130
+ this.app.post('/tasks/describe', (req, res) => {
131
+ const result = this.simulator.describeTasks(req.body);
132
+ res.json(result);
133
+ });
134
+
135
+ this.app.post('/tasks/:taskArn/stop', (req, res) => {
136
+ this.simulator.stopTask(req.params.taskArn).then(result => {
137
+ if (result.error) {
138
+ res.status(result.status).json(result.error);
139
+ } else {
140
+ res.json(result.task);
141
+ }
142
+ });
143
+ });
144
+
145
+ // Admin endpoints
146
+ this.setupAdminRoutes();
147
+ }
148
+
149
+ setupAdminRoutes() {
150
+ this.app.get('/__admin/clusters', (req, res) => {
151
+ res.json({
152
+ clusters: this.simulator.getClustersCount(),
153
+ services: this.simulator.getServicesCount(),
154
+ tasks: this.simulator.getTasksCount(),
155
+ runningContainers: this.simulator.getRunningContainers()
156
+ });
157
+ });
158
+
159
+ this.app.get('/__admin/clusters/:clusterName/details', (req, res) => {
160
+ const cluster = this.simulator.clusters.get(req.params.clusterName);
161
+ if (cluster) {
162
+ res.json(cluster);
163
+ } else {
164
+ res.status(404).json({ error: 'Cluster not found' });
165
+ }
166
+ });
167
+
168
+ this.app.get('/__admin/containers', (req, res) => {
169
+ const containers = [];
170
+ for (const [id, process] of this.simulator.containerProcesses) {
171
+ containers.push({
172
+ containerId: id,
173
+ taskArn: process.taskArn,
174
+ container: process.container,
175
+ running: process.running,
176
+ startTime: process.startTime
177
+ });
178
+ }
179
+ res.json(containers);
180
+ });
181
+
182
+ this.app.get('/__admin/ports', (req, res) => {
183
+ res.json({
184
+ availablePorts: Array.from(this.simulator.availablePorts),
185
+ usedPorts: this.getUsedPorts()
186
+ });
187
+ });
188
+ }
189
+
190
+ getUsedPorts() {
191
+ const usedPorts = [];
192
+ for (const [_, process] of this.simulator.containerProcesses) {
193
+ for (const mapping of process.container.portMappings) {
194
+ if (mapping.hostPort) {
195
+ usedPorts.push(mapping.hostPort);
196
+ }
197
+ }
198
+ }
199
+ return usedPorts;
200
+ }
201
+
202
+ start() {
203
+ return new Promise((resolve) => {
204
+ this.server = this.app.listen(this.port, () => {
205
+ logger.info(`🐳 ECS/Fargate rodando em http://localhost:${this.port}`);
206
+ resolve();
207
+ });
208
+ });
209
+ }
210
+
211
+ stop() {
212
+ return new Promise((resolve) => {
213
+ if (this.server) {
214
+ this.server.close(() => resolve());
215
+ } else {
216
+ resolve();
217
+ }
218
+ });
219
+ }
220
+
221
+ getStatus() {
222
+ return {
223
+ running: !!this.server,
224
+ port: this.port,
225
+ endpoint: `http://localhost:${this.port}`,
226
+ clustersCount: this.simulator?.getClustersCount() || 0,
227
+ servicesCount: this.simulator?.getServicesCount() || 0,
228
+ tasksCount: this.simulator?.getTasksCount() || 0,
229
+ runningContainers: this.simulator?.getRunningContainers() || 0
230
+ };
231
+ }
232
+ }
233
+
234
234
  module.exports = ECSServer;