@gugananuvem/aws-local-simulator 1.0.8 → 1.0.10

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 (41) hide show
  1. package/README.md +2 -1
  2. package/bin/aws-local-simulator.js +62 -1
  3. package/package.json +10 -7
  4. package/src/config/config-loader.js +113 -0
  5. package/src/config/default-config.js +65 -0
  6. package/src/config/env-loader.js +69 -0
  7. package/src/index.js +131 -1
  8. package/src/index.mjs +124 -0
  9. package/src/server.js +222 -0
  10. package/src/services/apigateway/index.js +67 -0
  11. package/src/services/apigateway/server.js +435 -0
  12. package/src/services/apigateway/simulator.js +1252 -0
  13. package/src/services/cognito/index.js +66 -0
  14. package/src/services/cognito/server.js +229 -0
  15. package/src/services/cognito/simulator.js +848 -0
  16. package/src/services/dynamodb/index.js +71 -0
  17. package/src/services/dynamodb/server.js +122 -0
  18. package/src/services/dynamodb/simulator.js +614 -0
  19. package/src/services/ecs/index.js +66 -0
  20. package/src/services/ecs/server.js +234 -0
  21. package/src/services/ecs/simulator.js +845 -0
  22. package/src/services/eventbridge/index.js +85 -0
  23. package/src/services/index.js +19 -0
  24. package/src/services/lambda/handler-loader.js +173 -0
  25. package/src/services/lambda/index.js +73 -0
  26. package/src/services/lambda/route-registry.js +275 -0
  27. package/src/services/lambda/server.js +153 -0
  28. package/src/services/lambda/simulator.js +285 -0
  29. package/src/services/s3/index.js +70 -0
  30. package/src/services/s3/server.js +239 -0
  31. package/src/services/s3/simulator.js +740 -0
  32. package/src/services/sns/index.js +76 -0
  33. package/src/services/sqs/index.js +96 -0
  34. package/src/services/sqs/server.js +274 -0
  35. package/src/services/sqs/simulator.js +660 -0
  36. package/src/template/aws-config-template.js +88 -0
  37. package/src/template/aws-config-template.mjs +91 -0
  38. package/src/template/config-template.json +203 -0
  39. package/src/utils/aws-config.js +92 -0
  40. package/src/utils/local-store.js +68 -0
  41. package/src/utils/logger.js +60 -0
@@ -0,0 +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
+
234
+ module.exports = ECSServer;