@gugananuvem/aws-local-simulator 1.0.0

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 ADDED
@@ -0,0 +1,192 @@
1
+ # AWS Local Simulator
2
+
3
+ [![npm version](https://badge.fury.io/js/aws-local-simulator.svg)](https://badge.fury.io/js/aws-local-simulator)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/node/v/aws-local-simulator.svg)](https://nodejs.org)
6
+
7
+ Simulador local completo para serviços AWS. Desenvolva e teste suas aplicações AWS localmente sem custos!
8
+
9
+ ## 🚀 Serviços Suportados
10
+
11
+ | Serviço | Status | Porta Padrão | Descrição |
12
+ |---------|--------|--------------|-----------|
13
+ | DynamoDB | ✅ | 8000 | Banco de dados NoSQL |
14
+ | S3 | ✅ | 4566 | Armazenamento de objetos |
15
+ | SQS | ✅ | 9324 | Filas de mensagens |
16
+ | Lambda | ✅ | 3001 | Funções serverless |
17
+ | Cognito | ✅ | 9229 | Autenticação e autorização |
18
+ | API Gateway | ✅ | 4567 | APIs REST e HTTP |
19
+ | ECS/Fargate | 🚧 | 8080 | Orquestração de containers (em desenvolvimento) |
20
+ | SNS | 🚧 | 9911 | Notificações (em desenvolvimento) |
21
+ | EventBridge | 🚧 | 4010 | Barramento de eventos (em desenvolvimento) |
22
+
23
+ ## 📦 Instalação
24
+
25
+ ```bash
26
+ npm install --save-dev aws-local-simulator
27
+ 🚀 Uso Rápido
28
+ 1. Crie um arquivo de configuração aws-local-simulator.json:
29
+ json
30
+ {
31
+ "services": {
32
+ "dynamodb": true,
33
+ "s3": true,
34
+ "sqs": true,
35
+ "lambda": true,
36
+ "cognito": true,
37
+ "apigateway": true
38
+ },
39
+ "lambdas": [
40
+ {
41
+ "path": "/api/users",
42
+ "handler": "./src/handlers/users.js",
43
+ "env": {
44
+ "TABLE_NAME": "users-table"
45
+ }
46
+ }
47
+ ],
48
+ "dynamodb": {
49
+ "tables": [
50
+ {
51
+ "TableName": "users-table",
52
+ "KeySchema": [
53
+ { "AttributeName": "id", "KeyType": "HASH" }
54
+ ],
55
+ "AttributeDefinitions": [
56
+ { "AttributeName": "id", "AttributeType": "S" }
57
+ ]
58
+ }
59
+ ]
60
+ },
61
+ "s3": {
62
+ "buckets": ["my-bucket"]
63
+ },
64
+ "cognito": {
65
+ "userPools": [
66
+ {
67
+ "PoolName": "my-user-pool",
68
+ "AutoVerifiedAttributes": ["email"]
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ ```
74
+
75
+ # 2. Inicie o simulador:
76
+ ## Via CLI
77
+ npx aws-local-simulator start
78
+
79
+ # Ou via código
80
+ const { AWSLocalSimulator } = require('aws-local-simulator');
81
+ const simulator = new AWSLocalSimulator();
82
+ await simulator.start();
83
+
84
+ # 3. Configure seu código para usar os serviços locais:
85
+
86
+ ```javascript
87
+ // Importe a configuração AWS pronta
88
+ const { dynamoDB, s3, sqs, cognito, apigateway } = require('aws-local-simulator/aws-config');
89
+
90
+ // Use como normalmente faria
91
+ await dynamoDB.send(new PutCommand({
92
+ TableName: 'users-table',
93
+ Item: { id: '123', name: 'John' }
94
+ }));
95
+ 🔧 Configuração por Variáveis de Ambiente
96
+ Variável Descrição Padrão
97
+ AWS_LOCAL_SIMULATOR_DYNAMODB Habilita DynamoDB true
98
+ AWS_LOCAL_SIMULATOR_S3 Habilita S3 true
99
+ AWS_LOCAL_SIMULATOR_SQS Habilita SQS true
100
+ AWS_LOCAL_SIMULATOR_LAMBDA Habilita Lambda true
101
+ AWS_LOCAL_SIMULATOR_COGNITO Habilita Cognito false
102
+ AWS_LOCAL_SIMULATOR_APIGATEWAY Habilita API Gateway false
103
+ AWS_LOCAL_SIMULATOR_ECS Habilita ECS/Fargate false
104
+ AWS_LOCAL_SIMULATOR_DYNAMODB_PORT Porta DynamoDB 8000
105
+ AWS_LOCAL_SIMULATOR_S3_PORT Porta S3 4566
106
+ AWS_LOCAL_SIMULATOR_SQS_PORT Porta SQS 9324
107
+ AWS_LOCAL_SIMULATOR_LAMBDA_PORT Porta Lambda 3001
108
+ AWS_LOCAL_SIMULATOR_COGNITO_PORT Porta Cognito 9229
109
+ AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT Porta API Gateway 4567
110
+ AWS_LOCAL_SIMULATOR_ECS_PORT Porta ECS 8080
111
+ AWS_LOCAL_SIMULATOR_DATA Diretório de dados ./.aws-local-simulator-data
112
+ AWS_LOCAL_SIMULATOR_LOG Nível de log info
113
+ ```
114
+
115
+ # 📝 Comandos CLI
116
+ bash
117
+ #### Iniciar simulador
118
+ npx aws-local-simulator start [configPath]
119
+
120
+ #### Parar simulador
121
+ npx aws-local-simulator stop
122
+
123
+ #### Reiniciar
124
+ npx aws-local-simulator restart
125
+
126
+ #### Resetar dados
127
+ npx aws-local-simulator reset
128
+
129
+ #### Status
130
+ npx aws-local-simulator status
131
+
132
+ # 🔌 Endpoints
133
+ # Serviço Endpoint Admin
134
+ DynamoDB http://localhost:8000 http://localhost:8000/__admin/tables
135
+ S3 http://localhost:4566 http://localhost:4566/__admin/buckets
136
+ SQS http://localhost:9324 http://localhost:9324/__admin/queues
137
+ Lambda http://localhost:3001 http://localhost:3001/__admin/lambdas
138
+ Cognito http://localhost:9229 http://localhost:9229/__admin/userpools
139
+ API Gateway http://localhost:4567 http://localhost:4567/__admin/apis
140
+ ECS http://localhost:8080 http://localhost:8080/__admin/clusters
141
+ 🧪 Testando com AWS CLI
142
+ bash
143
+ # DynamoDB
144
+ aws dynamodb list-tables --endpoint-url http://localhost:8000
145
+
146
+ # S3
147
+ aws s3 ls --endpoint-url http://localhost:4566
148
+
149
+ # SQS
150
+ aws sqs list-queues --endpoint-url http://localhost:9324
151
+
152
+ # Cognito
153
+ aws cognito-idp list-user-pools --max-results 10 --endpoint-url http://localhost:9229
154
+
155
+ # API Gateway
156
+ aws apigateway get-rest-apis --endpoint-url http://localhost:4567
157
+ 📁 Estrutura de Dados
158
+ Os dados são persistidos em:
159
+
160
+ text
161
+ .aws-local-simulator-data/
162
+ ├── dynamodb/
163
+ ├── s3/
164
+ ├── sqs/
165
+ ├── cognito/
166
+ ├── apigateway/
167
+ └── ecs/
168
+ 🐛 Debug
169
+ Para logs detalhados:
170
+
171
+ bash
172
+ AWS_LOCAL_SIMULATOR_LOG=verboso npx aws-local-simulator start
173
+ 🤝 Contribuindo
174
+ Fork o projeto
175
+
176
+ Crie sua feature branch (git checkout -b feature/AmazingFeature)
177
+
178
+ Commit suas mudanças (git commit -m 'Add some AmazingFeature')
179
+
180
+ Push para a branch (git push origin feature/AmazingFeature)
181
+
182
+ Abra um Pull Request
183
+
184
+ 📄 Licença
185
+ MIT © Luiz Gustavo Ribeiro
186
+
187
+ ⚠️ Limitações
188
+ SNS e EventBridge em desenvolvimento
189
+
190
+ WebSocket APIs em desenvolvimento
191
+
192
+ Para uso em desenvolvimento e testes apenas
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI para AWS Local Simulator
5
+ */
6
+
7
+ const { AWSLocalSimulator } = require('../src/index');
8
+ const logger = require('../src/utils/logger');
9
+ const path = require('path');
10
+
11
+ const command = process.argv[2];
12
+ const configPath = process.argv[3];
13
+
14
+ const simulator = new AWSLocalSimulator({
15
+ configPath: configPath ? path.resolve(process.cwd(), configPath) : undefined
16
+ });
17
+
18
+ async function main() {
19
+ switch (command) {
20
+ case 'start':
21
+ await simulator.start();
22
+ break;
23
+
24
+ case 'stop':
25
+ await simulator.stop();
26
+ break;
27
+
28
+ case 'restart':
29
+ await simulator.restart();
30
+ break;
31
+
32
+ case 'reset':
33
+ await simulator.reset();
34
+ break;
35
+
36
+ case 'status':
37
+ const status = simulator.getStatus();
38
+ console.log(JSON.stringify(status, null, 2));
39
+ break;
40
+
41
+ case 'help':
42
+ default:
43
+ console.log(`
44
+ AWS Local Simulator - CLI Commands:
45
+ start [configPath] - Inicia o simulador
46
+ stop - Para o simulador
47
+ restart - Reinicia o simulador
48
+ reset - Reseta todos os dados
49
+ status - Mostra status dos serviços
50
+ help - Mostra esta ajuda
51
+
52
+ Exemplos:
53
+ npx aws-local-simulator start
54
+ npx aws-local-simulator start ./my-config.json
55
+ AWS_LOCAL_SIMULATOR_LOG=verboso npx aws-local-simulator start
56
+ `);
57
+ break;
58
+ }
59
+ }
60
+
61
+ main().catch(error => {
62
+ logger.error('Erro:', error);
63
+ process.exit(1);
64
+ });
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@gugananuvem/aws-local-simulator",
3
+ "version": "1.0.0",
4
+ "description": "Simulador local completo para serviços AWS",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "aws-local-simulator": "bin/aws-local-simulator.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node bin/aws-local-simulator.js start"
11
+ },
12
+ "jest": {
13
+ "setupFilesAfterEnv": [
14
+ "<rootDir>/tests/setup.js"
15
+ ],
16
+ "testEnvironment": "node",
17
+ "testMatch": [
18
+ "**/tests/**/*.test.js"
19
+ ],
20
+ "collectCoverageFrom": [
21
+ "src/**/*.js",
22
+ "!src/templates/**",
23
+ "!**/node_modules/**"
24
+ ],
25
+ "coverageThreshold": {
26
+ "global": {
27
+ "branches": 30,
28
+ "functions": 30,
29
+ "lines": 30,
30
+ "statements": 30
31
+ }
32
+ },
33
+ "verbose": true,
34
+ "testTimeout": 30000,
35
+ "forceExit": true,
36
+ "detectOpenHandles": true
37
+ },
38
+ "keywords": [
39
+ "aws",
40
+ "local",
41
+ "simulator",
42
+ "dynamodb",
43
+ "s3",
44
+ "sqs",
45
+ "lambda",
46
+ "cognito",
47
+ "apigateway",
48
+ "ecs",
49
+ "development",
50
+ "testing"
51
+ ],
52
+ "author": {
53
+ "name": "gugananuvem",
54
+ "email": "lgustavor@hotmail.com"
55
+ },
56
+ "license": "MIT",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/seu-usuario/aws-local-simulator.git"
60
+ },
61
+ "engines": {
62
+ "node": ">=14.0.0"
63
+ },
64
+ "files": [
65
+ "dist/"
66
+ ],
67
+ "publishConfig": {
68
+ "directory": "dist"
69
+ },
70
+ "dependencies": {
71
+ "express": "^4.18.2",
72
+ "cors": "^2.8.5",
73
+ "uuid": "^9.0.0",
74
+ "glob": "^10.3.0",
75
+ "dotenv": "^16.3.1",
76
+ "jsonwebtoken": "^9.0.2",
77
+ "urlpattern-polyfill": "^10.0.0"
78
+ },
79
+ "peerDependencies": {
80
+ "@aws-sdk/client-dynamodb": "^3.0.0",
81
+ "@aws-sdk/client-s3": "^3.0.0",
82
+ "@aws-sdk/client-sqs": "^3.0.0",
83
+ "@aws-sdk/client-cognito-identity-provider": "^3.0.0",
84
+ "@aws-sdk/client-api-gateway": "^3.0.0",
85
+ "@aws-sdk/client-ecs": "^3.0.0",
86
+ "@aws-sdk/lib-dynamodb": "^3.0.0"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "@aws-sdk/client-dynamodb": {
90
+ "optional": true
91
+ },
92
+ "@aws-sdk/client-s3": {
93
+ "optional": true
94
+ },
95
+ "@aws-sdk/client-sqs": {
96
+ "optional": true
97
+ },
98
+ "@aws-sdk/client-cognito-identity-provider": {
99
+ "optional": true
100
+ },
101
+ "@aws-sdk/client-api-gateway": {
102
+ "optional": true
103
+ },
104
+ "@aws-sdk/client-ecs": {
105
+ "optional": true
106
+ }
107
+ },
108
+ "buildDate": "2026-03-29T01:01:59.763Z",
109
+ "published": true
110
+ }
package/src/index.js ADDED
@@ -0,0 +1,131 @@
1
+ /**
2
+ * AWS Local Simulator - Entry Point Principal
3
+ */
4
+
5
+ const Server = require('./server');
6
+ const { loadConfig } = require('./config/config-loader');
7
+ const logger = require('./utils/logger');
8
+
9
+ // Exporta serviços para uso programático
10
+ const DynamoDBService = require('./services/dynamodb');
11
+ const S3Service = require('./services/s3');
12
+ const SQSService = require('./services/sqs');
13
+ const LambdaService = require('./services/lambda');
14
+ const SNSService = require('./services/sns');
15
+ const EventBridgeService = require('./services/eventbridge');
16
+
17
+ // Exporta utilitários
18
+ const LocalStore = require('./utils/local-store');
19
+ const HandlerLoader = require('./services/lambda/handler-loader');
20
+ const RouteRegistry = require('./services/lambda/route-registry');
21
+
22
+ class AWSLocalSimulator {
23
+ constructor(options = {}) {
24
+ this.options = options;
25
+ this.server = null;
26
+ this.isRunning = false;
27
+ }
28
+
29
+ async start() {
30
+ if (this.isRunning) {
31
+ logger.warn('Simulador já está rodando');
32
+ return this;
33
+ }
34
+
35
+ try {
36
+ const config = await loadConfig(this.options.configPath);
37
+ this.server = new Server(config);
38
+ await this.server.start();
39
+ this.isRunning = true;
40
+ logger.success('✅ AWS Local Simulator iniciado com sucesso');
41
+ return this;
42
+ } catch (error) {
43
+ logger.error('❌ Erro ao iniciar simulador:', error);
44
+ throw error;
45
+ }
46
+ }
47
+
48
+ async stop() {
49
+ if (!this.isRunning || !this.server) {
50
+ logger.warn('Simulador não está rodando');
51
+ return this;
52
+ }
53
+
54
+ try {
55
+ await this.server.stop();
56
+ this.isRunning = false;
57
+ logger.info('🛑 AWS Local Simulator parado');
58
+ return this;
59
+ } catch (error) {
60
+ logger.error('❌ Erro ao parar simulador:', error);
61
+ throw error;
62
+ }
63
+ }
64
+
65
+ async restart() {
66
+ await this.stop();
67
+ await this.start();
68
+ return this;
69
+ }
70
+
71
+ async reset() {
72
+ if (!this.server) {
73
+ throw new Error('Simulador não iniciado');
74
+ }
75
+ await this.server.reset();
76
+ logger.success('🗑️ Todos os dados foram resetados');
77
+ return this;
78
+ }
79
+
80
+ getStatus() {
81
+ if (!this.server) {
82
+ return { running: false };
83
+ }
84
+ return {
85
+ running: this.isRunning,
86
+ services: this.server.getStatus()
87
+ };
88
+ }
89
+
90
+ getService(serviceName) {
91
+ if (!this.server) {
92
+ return null;
93
+ }
94
+ return this.server.getService(serviceName);
95
+ }
96
+
97
+ // Métodos de conveniência
98
+ getDynamoDB() {
99
+ return this.getService('dynamodb')?.getSimulator();
100
+ }
101
+
102
+ getS3() {
103
+ return this.getService('s3')?.getSimulator();
104
+ }
105
+
106
+ getSQS() {
107
+ return this.getService('sqs')?.getSimulator();
108
+ }
109
+
110
+ getLambda() {
111
+ return this.getService('lambda')?.getSimulator();
112
+ }
113
+ }
114
+
115
+ // Exporta classes e utilitários
116
+ module.exports = {
117
+ AWSLocalSimulator,
118
+ Server,
119
+ DynamoDBService,
120
+ S3Service,
121
+ SQSService,
122
+ LambdaService,
123
+ SNSService,
124
+ EventBridgeService,
125
+ LocalStore,
126
+ HandlerLoader,
127
+ RouteRegistry
128
+ };
129
+
130
+ // Exporta também como default para ES Modules compatibilidade
131
+ module.exports.default = AWSLocalSimulator;