@gugananuvem/aws-local-simulator 1.0.15 → 1.0.16

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 (77) hide show
  1. package/README.md +789 -594
  2. package/bin/aws-local-simulator.js +63 -63
  3. package/package.json +2 -2
  4. package/src/config/config-loader.js +114 -114
  5. package/src/config/default-config.js +68 -68
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +146 -146
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +227 -227
  10. package/src/services/apigateway/index.js +75 -73
  11. package/src/services/apigateway/server.js +570 -507
  12. package/src/services/apigateway/simulator.js +1261 -1261
  13. package/src/services/athena/index.js +75 -75
  14. package/src/services/athena/server.js +101 -101
  15. package/src/services/athena/simulador.js +998 -998
  16. package/src/services/athena/simulator.js +346 -346
  17. package/src/services/cloudformation/index.js +106 -106
  18. package/src/services/cloudformation/server.js +417 -417
  19. package/src/services/cloudformation/simulador.js +1045 -1045
  20. package/src/services/cloudtrail/index.js +84 -84
  21. package/src/services/cloudtrail/server.js +235 -235
  22. package/src/services/cloudtrail/simulador.js +719 -719
  23. package/src/services/cloudwatch/index.js +84 -84
  24. package/src/services/cloudwatch/server.js +366 -366
  25. package/src/services/cloudwatch/simulador.js +1173 -1173
  26. package/src/services/cognito/index.js +79 -79
  27. package/src/services/cognito/server.js +301 -301
  28. package/src/services/cognito/simulator.js +1655 -1655
  29. package/src/services/config/index.js +96 -96
  30. package/src/services/config/server.js +215 -215
  31. package/src/services/config/simulador.js +1260 -1260
  32. package/src/services/dynamodb/index.js +74 -74
  33. package/src/services/dynamodb/server.js +125 -125
  34. package/src/services/dynamodb/simulator.js +630 -630
  35. package/src/services/ecs/index.js +65 -65
  36. package/src/services/ecs/server.js +235 -235
  37. package/src/services/ecs/simulator.js +844 -844
  38. package/src/services/eventbridge/index.js +89 -89
  39. package/src/services/eventbridge/server.js +209 -209
  40. package/src/services/eventbridge/simulator.js +684 -684
  41. package/src/services/index.js +45 -45
  42. package/src/services/kms/index.js +75 -75
  43. package/src/services/kms/server.js +67 -67
  44. package/src/services/kms/simulator.js +324 -324
  45. package/src/services/lambda/handler-loader.js +183 -183
  46. package/src/services/lambda/index.js +78 -78
  47. package/src/services/lambda/route-registry.js +274 -274
  48. package/src/services/lambda/server.js +145 -145
  49. package/src/services/lambda/simulator.js +199 -199
  50. package/src/services/parameter-store/index.js +80 -80
  51. package/src/services/parameter-store/server.js +50 -50
  52. package/src/services/parameter-store/simulator.js +201 -201
  53. package/src/services/s3/index.js +73 -73
  54. package/src/services/s3/server.js +329 -329
  55. package/src/services/s3/simulator.js +565 -565
  56. package/src/services/secret-manager/index.js +80 -80
  57. package/src/services/secret-manager/server.js +50 -50
  58. package/src/services/secret-manager/simulator.js +171 -171
  59. package/src/services/sns/index.js +89 -89
  60. package/src/services/sns/server.js +580 -580
  61. package/src/services/sns/simulator.js +1482 -1482
  62. package/src/services/sqs/index.js +98 -93
  63. package/src/services/sqs/server.js +349 -349
  64. package/src/services/sqs/simulator.js +441 -441
  65. package/src/services/sts/index.js +37 -37
  66. package/src/services/sts/server.js +144 -144
  67. package/src/services/sts/simulator.js +69 -69
  68. package/src/services/xray/index.js +83 -83
  69. package/src/services/xray/server.js +308 -308
  70. package/src/services/xray/simulador.js +994 -994
  71. package/src/template/aws-config-template.js +87 -87
  72. package/src/template/aws-config-template.mjs +90 -90
  73. package/src/template/config-template.json +203 -203
  74. package/src/utils/aws-config.js +91 -91
  75. package/src/utils/cloudtrail-audit.js +129 -129
  76. package/src/utils/local-store.js +83 -83
  77. package/src/utils/logger.js +59 -59
package/README.md CHANGED
@@ -1,594 +1,789 @@
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
- | STS | ✅ | 9326 | Credenciais temporárias |
20
- | SNS | ✅ | 9911 | Notificações pub/sub |
21
- | EventBridge | ✅ | 4010 | Barramento de eventos |
22
- | KMS | ✅ | 4000 | Gerenciamento de chaves |
23
- | Secrets Manager | ✅ | 4001 | Gerenciamento de segredos |
24
- | Parameter Store | ✅ | 4002 | Armazenamento de parâmetros |
25
- | CloudWatch | ✅ | 4011 | Logs, métricas e alarmes |
26
- | CloudTrail | ✅ | 4012 | Auditoria de API calls |
27
- | AWS Config | ✅ | 4013 | Conformidade e configuração |
28
- | CloudFormation | ✅ | 4580 | Infraestrutura como código |
29
- | Athena | ✅ | 4599 | Consultas SQL em dados no S3 |
30
- | X-Ray | ✅ | 4015 | Rastreamento distribuído |
31
- | ECS/Fargate | 🚧 | 8080 | Orquestração de containers (em desenvolvimento) |
32
-
33
- ## 📦 Instalação
34
-
35
- ```bash
36
- npm install --save-dev aws-local-simulator
37
- ```
38
-
39
- ## 🚀 Uso Rápido
40
-
41
- ### 1. Crie um arquivo de configuração `aws-local-simulator.json`:
42
-
43
- ```json
44
- {
45
- "services": {
46
- "dynamodb": true,
47
- "s3": true,
48
- "sqs": true,
49
- "lambda": true,
50
- "cognito": true,
51
- "apigateway": true,
52
- "sts": true,
53
- "sns": true,
54
- "eventbridge": true,
55
- "kms": true,
56
- "secret-manager": true,
57
- "parameter-store": true,
58
- "cloudwatch": true,
59
- "cloudtrail": true,
60
- "cloudformation": true,
61
- "xray": true,
62
- "config": true,
63
- "athena": true
64
- },
65
- "lambdas": [
66
- {
67
- "name": "my-function",
68
- "handler": "./src/handlers/users.js",
69
- "env": {
70
- "TABLE_NAME": "users-table"
71
- }
72
- }
73
- ],
74
- "dynamodb": {
75
- "tables": [
76
- {
77
- "TableName": "users-table",
78
- "KeySchema": [{ "AttributeName": "id", "KeyType": "HASH" }],
79
- "AttributeDefinitions": [{ "AttributeName": "id", "AttributeType": "S" }]
80
- }
81
- ]
82
- },
83
- "s3": {
84
- "buckets": [
85
- { "name": "my-bucket", "region": "us-east-1" }
86
- ]
87
- },
88
- "sqs": {
89
- "queues": ["my-queue", "dead-letter-queue"]
90
- },
91
- "cognito": {
92
- "userPools": [
93
- {
94
- "PoolName": "my-user-pool",
95
- "AutoVerifiedAttributes": ["email"]
96
- }
97
- ]
98
- }
99
- }
100
- ```
101
-
102
- ### 2. Inicie o simulador:
103
-
104
- ```bash
105
- # Via CLI
106
- npx aws-local-simulator start
107
-
108
- # Ou via código
109
- const { AWSLocalSimulator } = require('aws-local-simulator');
110
- const simulator = new AWSLocalSimulator();
111
- await simulator.start();
112
- ```
113
-
114
- ### 3. Configure seu código para usar os serviços locais:
115
-
116
- ```javascript
117
- const { dynamoDB, s3, sqs, cognito } = require('aws-local-simulator/aws-config');
118
-
119
- await dynamoDB.send(new PutCommand({
120
- TableName: 'users-table',
121
- Item: { id: '123', name: 'John' }
122
- }));
123
- ```
124
-
125
- ## 🔧 Configuração por Variáveis de Ambiente
126
-
127
- | Variável | Descrição | Padrão |
128
- |---------|----------|-------|
129
- | AWS_LOCAL_SIMULATOR_DYNAMODB | Habilita DynamoDB | true |
130
- | AWS_LOCAL_SIMULATOR_S3 | Habilita S3 | true |
131
- | AWS_LOCAL_SIMULATOR_SQS | Habilita SQS | true |
132
- | AWS_LOCAL_SIMULATOR_LAMBDA | Habilita Lambda | true |
133
- | AWS_LOCAL_SIMULATOR_COGNITO | Habilita Cognito | false |
134
- | AWS_LOCAL_SIMULATOR_APIGATEWAY | Habilita API Gateway | false |
135
- | AWS_LOCAL_SIMULATOR_STS | Habilita STS | true |
136
- | AWS_LOCAL_SIMULATOR_SNS | Habilita SNS | false |
137
- | AWS_LOCAL_SIMULATOR_EVENTBRIDGE | Habilita EventBridge | false |
138
- | AWS_LOCAL_SIMULATOR_KMS | Habilita KMS | false |
139
- | AWS_LOCAL_SIMULATOR_SECRET_MANAGER | Habilita Secrets Manager | false |
140
- | AWS_LOCAL_SIMULATOR_PARAMETER_STORE | Habilita Parameter Store | false |
141
- | AWS_LOCAL_SIMULATOR_CLOUDWATCH | Habilita CloudWatch | false |
142
- | AWS_LOCAL_SIMULATOR_CLOUDTRAIL | Habilita CloudTrail | false |
143
- | AWS_LOCAL_SIMULATOR_CLOUDFORMATION | Habilita CloudFormation | false |
144
- | AWS_LOCAL_SIMULATOR_ATHENA | Habilita Athena | false |
145
- | AWS_LOCAL_SIMULATOR_XRAY | Habilita X-Ray | false |
146
- | AWS_LOCAL_SIMULATOR_CONFIG | Habilita AWS Config | false |
147
- | AWS_LOCAL_SIMULATOR_ECS | Habilita ECS/Fargate | false |
148
- | AWS_LOCAL_SIMULATOR_DYNAMODB_PORT | Porta DynamoDB | 8000 |
149
- | AWS_LOCAL_SIMULATOR_S3_PORT | Porta S3 | 4566 |
150
- | AWS_LOCAL_SIMULATOR_SQS_PORT | Porta SQS | 9324 |
151
- | AWS_LOCAL_SIMULATOR_LAMBDA_PORT | Porta Lambda | 3001 |
152
- | AWS_LOCAL_SIMULATOR_COGNITO_PORT | Porta Cognito | 9229 |
153
- | AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT | Porta API Gateway | 4567 |
154
- | AWS_LOCAL_SIMULATOR_STS_PORT | Porta STS | 9326 |
155
- | AWS_LOCAL_SIMULATOR_SNS_PORT | Porta SNS | 9911 |
156
- | AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT | Porta EventBridge | 4010 |
157
- | AWS_LOCAL_SIMULATOR_KMS_PORT | Porta KMS | 4000 |
158
- | AWS_LOCAL_SIMULATOR_SECRET_MANAGER_PORT | Porta Secrets Manager | 4001 |
159
- | AWS_LOCAL_SIMULATOR_PARAMETER_STORE_PORT | Porta Parameter Store | 4002 |
160
- | AWS_LOCAL_SIMULATOR_CLOUDWATCH_PORT | Porta CloudWatch | 4011 |
161
- | AWS_LOCAL_SIMULATOR_CLOUDTRAIL_PORT | Porta CloudTrail | 4012 |
162
- | AWS_LOCAL_SIMULATOR_CONFIG_PORT | Porta AWS Config | 4013 |
163
- | AWS_LOCAL_SIMULATOR_XRAY_PORT | Porta X-Ray | 4015 |
164
- | AWS_LOCAL_SIMULATOR_CLOUDFORMATION_PORT | Porta CloudFormation | 4580 |
165
- | AWS_LOCAL_SIMULATOR_ATHENA_PORT | Porta Athena | 4599 |
166
- | AWS_LOCAL_SIMULATOR_ECS_PORT | Porta ECS | 8080 |
167
- | AWS_LOCAL_SIMULATOR_DATA | Diretório de dados | ./aws-local-simulator-data |
168
- | AWS_LOCAL_SIMULATOR_LOG | Nível de log | info |
169
-
170
- ## 📝 Comandos CLI
171
-
172
- ```bash
173
- # Iniciar simulador
174
- npx aws-local-simulator start [configPath]
175
-
176
- # Parar simulador
177
- npx aws-local-simulator stop
178
-
179
- # Reiniciar
180
- npx aws-local-simulator restart
181
-
182
- # Resetar dados
183
- npx aws-local-simulator reset
184
-
185
- # Status
186
- npx aws-local-simulator status
187
- ```
188
-
189
- ## 🔌 Endpoints
190
-
191
- | Serviço | Endpoint | Admin |
192
- |---------|----------|-------|
193
- | DynamoDB | http://localhost:8000 | http://localhost:8000/__admin/tables |
194
- | S3 | http://localhost:4566 | http://localhost:4566/__admin/buckets |
195
- | S3 Website | http://localhost:4566/website/{bucket}/ | — |
196
- | SQS | http://localhost:9324 | http://localhost:9324/__admin/queues |
197
- | Lambda | http://localhost:3001 | http://localhost:3001/__admin/functions |
198
- | Cognito | http://localhost:9229 | http://localhost:9229/__admin/userpools |
199
- | API Gateway | http://localhost:4567 | http://localhost:4567/__admin/apis |
200
- | STS | http://localhost:9326 | — |
201
- | SNS | http://localhost:9911 | http://localhost:9911/__admin/health |
202
- | EventBridge | http://localhost:4010 | — |
203
- | KMS | http://localhost:4000 | — |
204
- | Secrets Manager | http://localhost:4001 | — |
205
- | Parameter Store | http://localhost:4002 | — |
206
- | CloudWatch | http://localhost:4011 | — |
207
- | CloudTrail | http://localhost:4012 | — |
208
- | AWS Config | http://localhost:4013 | — |
209
- | X-Ray | http://localhost:4015 | — |
210
- | CloudFormation | http://localhost:4580 | http://localhost:4580/__admin/stacks |
211
- | Athena | http://localhost:4599 | http://localhost:4599/__admin/health |
212
- | ECS | http://localhost:8080 | http://localhost:8080/__admin/clusters |
213
-
214
- ## 🧪 Testando com AWS CLI
215
-
216
- ```bash
217
- # DynamoDB
218
- aws dynamodb list-tables --endpoint-url http://localhost:8000
219
-
220
- # S3
221
- aws s3 ls --endpoint-url http://localhost:4566
222
-
223
- # SQS
224
- aws sqs list-queues --endpoint-url http://localhost:9324
225
-
226
- # Lambda
227
- aws lambda invoke \
228
- --function-name my-function \
229
- --payload '{"key":"value"}' \
230
- --endpoint-url http://localhost:3001 \
231
- output.json
232
-
233
- # Cognito
234
- aws cognito-idp list-user-pools --max-results 10 --endpoint-url http://localhost:9229
235
-
236
- # Cognito cadastrar um usuario pelo adminstrador
237
- aws cognito-idp admin-create-user \
238
- --user-pool-id us-east-xxxx\
239
- --username usuario@email.com \
240
- --user-attributes \
241
- Name=email,Value=usuario@email.com \
242
- Name=email_verified,Value=false \
243
- Name=name,Value="nome usuario" \
244
- Name=custom:role,Value="user" \
245
- temporary-password "Teste@123456" \
246
- --message-action SUPPRESS \
247
- --endpoint-url http://localhost:9229
248
-
249
- # Cognito excluir um usuario
250
- aws cognito-idp admin-delete-user \
251
- --user-pool-id us-east-xxxx \
252
- --username usuario@email.com
253
- --endpoint-url http://localhost:9229
254
-
255
- # Cognito Registrar usuário
256
- aws cognito-idp sign-up \
257
- --client-id $CLIENT_ID \
258
- --username usuario@email.com \
259
- --password "Teste@123456" \
260
- --user-attributes Name=email,Value=usuario@email.com Name=name,Value="nome usuario"
261
- --endpoint-url http://localhost:9229
262
-
263
- # 2. Confirmar usuário administrativamente
264
- aws cognito-idp admin-confirm-sign-up \
265
- --user-pool-id us-east-xxxx \
266
- --username usuario@email.com
267
- --endpoint-url http://localhost:9229
268
-
269
- # O código chega no e-mail do usuário. Algo como: "Your confirmation code is 123456"
270
- aws cognito-idp confirm-sign-up \
271
- --client-id 3n4b5urk1ft4fl3mg5e62d9ado \
272
- --username usuario@email.com \
273
- --confirmation-code 123456
274
- --endpoint-url http://localhost:9229
275
-
276
- # STS
277
- aws sts get-caller-identity --endpoint-url http://localhost:9326
278
- aws sts assume-role \
279
- --role-arn "arn:aws:iam::123456789012:role/my-role" \
280
- --role-session-name "my-session" \
281
- --endpoint-url http://localhost:9326
282
-
283
- # SNS
284
- aws sns list-topics --endpoint-url http://localhost:9911
285
-
286
- # EventBridge
287
- aws events list-event-buses --endpoint-url http://localhost:4010
288
-
289
- # KMS
290
- aws kms list-keys --endpoint-url http://localhost:4000
291
-
292
- # Secrets Manager
293
- aws secretsmanager list-secrets --endpoint-url http://localhost:4001
294
-
295
- # Criar secret
296
- aws secretsmanager create-secret \
297
- --name "local/app/db-credentials" \
298
- --description "Credenciais do banco" \
299
- --secret-string '{"username":"admin","password":"secret123"}' \
300
- --endpoint-url http://localhost:4001
301
-
302
- # Ler secret
303
- aws secretsmanager get-secret-value \
304
- --secret-id "local/app/db-credentials" \
305
- --endpoint-url http://localhost:4001
306
-
307
- # Parameter Store
308
- aws ssm describe-parameters --endpoint-url http://localhost:4002
309
-
310
- # Criar parâmetro String
311
- aws ssm put-parameter \
312
- --name "/local/app/config" \
313
- --value '{"timeout":30,"maxRetries":3}' \
314
- --type String \
315
- --endpoint-url http://localhost:4002
316
-
317
- # Criar parâmetro SecureString
318
- aws ssm put-parameter \
319
- --name "/local/app/api-key" \
320
- --value "my-secret-api-key" \
321
- --type SecureString \
322
- --endpoint-url http://localhost:4002
323
-
324
- # Ler parâmetro
325
- aws ssm get-parameter \
326
- --name "/local/app/config" \
327
- --endpoint-url http://localhost:4002
328
-
329
- # CloudWatch
330
- aws cloudwatch list-metrics --endpoint-url http://localhost:4011
331
- aws logs describe-log-groups --endpoint-url http://localhost:4011
332
-
333
- # CloudTrail
334
- aws cloudtrail describe-trails --endpoint-url http://localhost:4012
335
-
336
- # CloudFormation
337
- aws cloudformation list-stacks --endpoint-url http://localhost:4580
338
-
339
- # X-Ray
340
- aws xray get-trace-summaries \
341
- --start-time $(date -d '1 hour ago' +%s) \
342
- --end-time $(date +%s) \
343
- --endpoint-url http://localhost:4015
344
-
345
- # AWS Config
346
- aws configservice describe-configuration-recorders --endpoint-url http://localhost:4013
347
-
348
- # API Gateway
349
- aws apigateway get-rest-apis --endpoint-url http://localhost:4567
350
-
351
- # Cloudformation
352
- aws cloudformation create-stack \
353
- --stack-name test-stack \
354
- --template-body file://templates/test-stack.yaml \
355
- --parameters \
356
- ParameterKey=Environment,ParameterValue=local \
357
- ParameterKey=BucketName,ParameterValue=meu-bucket \
358
- ParameterKey=QueueName,ParameterValue=minha-fila \
359
- ParameterKey=TableName,ParameterValue=minha-tabela \
360
- --endpoint-url http://localhost:4580
361
-
362
- # Ver Cloudformation resultado
363
- aws cloudformation describe-stacks \
364
- --stack-name test-stack \
365
- --endpoint-url http://localhost:4580
366
-
367
- # Athena
368
- # Criar workgroup
369
- aws athena create-work-group \
370
- --name my-workgroup \
371
- --configuration ResultConfiguration={OutputLocation=s3://meu-bucket/athena-results/} \
372
- --endpoint-url http://localhost:4599
373
-
374
- # Listar workgroups
375
- aws athena list-work-groups --endpoint-url http://localhost:4599
376
-
377
- # Executar query
378
- aws athena start-query-execution \
379
- --query-string "SELECT * FROM my_table LIMIT 10" \
380
- --query-execution-context Database=default \
381
- --result-configuration OutputLocation=s3://meu-bucket/athena-results/ \
382
- --endpoint-url http://localhost:4599
383
-
384
- # Verificar status da query
385
- aws athena get-query-execution \
386
- --query-execution-id <id-retornado> \
387
- --endpoint-url http://localhost:4599
388
-
389
- # Buscar resultados
390
- aws athena get-query-results \
391
- --query-execution-id <id-retornado> \
392
- --endpoint-url http://localhost:4599
393
-
394
- # Criar named query
395
- aws athena create-named-query \
396
- --name "my-saved-query" \
397
- --database default \
398
- --query-string "SELECT id, value FROM my_table WHERE status = 'active'" \
399
- --endpoint-url http://localhost:4599
400
-
401
- # Listar named queries
402
- aws athena list-named-queries --endpoint-url http://localhost:4599
403
- ```
404
-
405
- ## ⚙️ Configuração S3
406
-
407
- ### Buckets simples
408
-
409
- ```json
410
- {
411
- "s3": {
412
- "buckets": [
413
- "my-bucket"
414
- ]
415
- }
416
- }
417
- ```
418
-
419
- ### Buckets com região e website estático
420
-
421
- ```json
422
- {
423
- "s3": {
424
- "buckets": [
425
- { "name": "my-bucket", "region": "us-east-1" },
426
- {
427
- "name": "my-site-bucket",
428
- "region": "us-east-1",
429
- "websiteConfiguration": {
430
- "IndexDocument": { "Suffix": "index.html" },
431
- "ErrorDocument": { "Key": "error.html" }
432
- }
433
- }
434
- ]
435
- }
436
- }
437
- ```
438
-
439
- Quando `websiteConfiguration` está presente, o bucket serve arquivos estáticos.
440
-
441
- ### URL do website estático
442
-
443
- ```
444
- http://localhost:4566/website/{bucket-name}/
445
- http://localhost:4566/website/{bucket-name}/caminho/pagina.html
446
- ```
447
-
448
- Exemplos:
449
- ```
450
- http://localhost:4566/website/my-site-bucket/ → serve index.html
451
- http://localhost:4566/website/my-site-bucket/about.html → serve about.html
452
- http://localhost:4566/website/my-site-bucket/app/ → serve app/index.html
453
- ```
454
-
455
- ### Gerenciar website config via AWS CLI
456
-
457
- ```bash
458
- # Habilitar website em um bucket existente
459
- aws s3api put-bucket-website \
460
- --bucket my-site-bucket \
461
- --website-configuration '{"IndexDocument":{"Suffix":"index.html"},"ErrorDocument":{"Key":"error.html"}}' \
462
- --endpoint-url http://localhost:4566
463
-
464
- # Ver configuração de website
465
- aws s3api get-bucket-website \
466
- --bucket my-site-bucket \
467
- --endpoint-url http://localhost:4566
468
-
469
- # Remover website
470
- aws s3api delete-bucket-website \
471
- --bucket my-site-bucket \
472
- --endpoint-url http://localhost:4566
473
- ```
474
-
475
- ## ⚙️ Configuração de Lambdas
476
-
477
- Lambdas são registradas por **nome** e invocadas via API de invocação (igual à AWS real). O roteamento HTTP é feito pelo API Gateway.
478
-
479
- ```json
480
- {
481
- "lambdas": [
482
- {
483
- "name": "my-user-function",
484
- "handler": "./src/handlers/my-user-function.js",
485
- "env": {
486
- "TABLE_NAME": "users-table",
487
- "BUCKET_NAME": "my-bucket"
488
- }
489
- }
490
- ]
491
- }
492
- ```
493
-
494
- ## ⚙️ Configuração API GATEWAY
495
-
496
- O valor do **lambdaName** deve igual ao nome Lambda que está registrada com o valor **name**. Ex: "my-user-function".
497
-
498
- ```json
499
- {
500
- "apigateway": {
501
- "apis": [
502
- {
503
- "name": "Users API",
504
- "description": "API para gerenciamento de usuários",
505
- "endpoints": [
506
- {
507
- "path": "/user",
508
- "method": "GET",
509
- "lambdaName": "my-user-function",
510
- "integrationType": "lambda"
511
- },
512
- {
513
- "path": "/user",
514
- "method": "POST",
515
- "lambdaName": "my-user-function",
516
- "integrationType": "lambda"
517
- },
518
- {
519
- "path": "/user/{id}",
520
- "method": "GET",
521
- "lambdaName": "my-user-function",
522
- "integrationType": "lambda"
523
- },
524
- {
525
- "path": "/user/{id}",
526
- "method": "DELETE",
527
- "lambdaName": "my-user-function",
528
- "integrationType": "lambda"
529
- }
530
- ]
531
- }
532
- ]
533
- },
534
-
535
- }
536
- ```
537
-
538
- O handler deve exportar uma função padrão:
539
-
540
- ```javascript
541
- exports.handler = async (event, context) => {
542
- return {
543
- statusCode: 200,
544
- body: JSON.stringify({ message: 'Hello from Lambda!' })
545
- };
546
- };
547
- ```
548
-
549
- ## 📁 Estrutura de Dados
550
-
551
- Os dados são persistidos em:
552
-
553
- ```text
554
- .aws-local-simulator-data/
555
- ├── dynamodb/
556
- ├── s3/
557
- ├── sqs/
558
- ├── cognito/
559
- ├── apigateway/
560
- ├── ecs/
561
- ├── kms/
562
- ├── secret-manager/
563
- ├── parameter-store/
564
- ├── cloudwatch/
565
- ├── cloudtrail/
566
- ├── cloudformation/
567
- ├── athena/
568
- ├── xray/
569
- └── config/
570
- ```
571
-
572
- ## 🐛 Debug
573
-
574
- ```bash
575
- AWS_LOCAL_SIMULATOR_LOG=verbose npx aws-local-simulator start
576
- ```
577
-
578
- ## 🤝 Contribuindo
579
-
580
- 1. Fork o projeto
581
- 2. Crie sua feature branch (`git checkout -b feature/AmazingFeature`)
582
- 3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`)
583
- 4. Push para a branch (`git push origin feature/AmazingFeature`)
584
- 5. Abra um Pull Request
585
-
586
- ## 📄 Licença
587
-
588
- MIT © Luiz Gustavo Ribeiro
589
-
590
- ## ⚠️ Limitações
591
-
592
- - ECS/Fargate em desenvolvimento
593
- - WebSocket APIs em desenvolvimento
594
- - Para uso em desenvolvimento e testes apenas
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
+ | STS | ✅ | 9326 | Credenciais temporárias |
20
+ | SNS | ✅ | 9911 | Notificações pub/sub |
21
+ | EventBridge | ✅ | 4010 | Barramento de eventos |
22
+ | KMS | ✅ | 4000 | Gerenciamento de chaves |
23
+ | Secrets Manager | ✅ | 4001 | Gerenciamento de segredos |
24
+ | Parameter Store | ✅ | 4002 | Armazenamento de parâmetros |
25
+ | CloudWatch | ✅ | 4011 | Logs, métricas e alarmes |
26
+ | CloudTrail | ✅ | 4012 | Auditoria de API calls |
27
+ | AWS Config | ✅ | 4013 | Conformidade e configuração |
28
+ | CloudFormation | ✅ | 4580 | Infraestrutura como código |
29
+ | Athena | ✅ | 4599 | Consultas SQL em dados no S3 |
30
+ | X-Ray | ✅ | 4015 | Rastreamento distribuído |
31
+ | ECS/Fargate | 🚧 | 8080 | Orquestração de containers (em desenvolvimento) |
32
+
33
+ ## 📦 Instalação
34
+
35
+ ```bash
36
+ npm install --save-dev aws-local-simulator
37
+ ```
38
+
39
+ ## 🚀 Uso Rápido
40
+
41
+ ### 1. Crie um arquivo de configuração `aws-local-simulator.json`:
42
+
43
+ ```json
44
+ {
45
+ "services": {
46
+ "dynamodb": true,
47
+ "s3": true,
48
+ "sqs": true,
49
+ "lambda": true,
50
+ "cognito": true,
51
+ "apigateway": true,
52
+ "sts": true,
53
+ "sns": true,
54
+ "eventbridge": true,
55
+ "kms": true,
56
+ "secret-manager": true,
57
+ "parameter-store": true,
58
+ "cloudwatch": true,
59
+ "cloudtrail": true,
60
+ "cloudformation": true,
61
+ "xray": true,
62
+ "config": true,
63
+ "athena": true
64
+ },
65
+ "lambdas": [
66
+ {
67
+ "name": "my-function",
68
+ "handler": "./src/handlers/users.js",
69
+ "env": {
70
+ "TABLE_NAME": "users-table"
71
+ }
72
+ }
73
+ ],
74
+ "dynamodb": {
75
+ "tables": [
76
+ {
77
+ "TableName": "users-table",
78
+ "KeySchema": [{ "AttributeName": "id", "KeyType": "HASH" }],
79
+ "AttributeDefinitions": [{ "AttributeName": "id", "AttributeType": "S" }]
80
+ }
81
+ ]
82
+ },
83
+ "s3": {
84
+ "buckets": [
85
+ { "name": "my-bucket", "region": "us-east-1" }
86
+ ]
87
+ },
88
+ "sqs": {
89
+ "queues": ["my-queue", "dead-letter-queue"]
90
+ },
91
+ "cognito": {
92
+ "userPools": [
93
+ {
94
+ "PoolName": "my-user-pool",
95
+ "AutoVerifiedAttributes": ["email"]
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ ```
101
+
102
+ ### 2. Inicie o simulador:
103
+
104
+ ```bash
105
+ # Via CLI
106
+ npx aws-local-simulator start
107
+
108
+ # Ou via código
109
+ const { AWSLocalSimulator } = require('aws-local-simulator');
110
+ const simulator = new AWSLocalSimulator();
111
+ await simulator.start();
112
+ ```
113
+
114
+ ### 3. Configure seu código para usar os serviços locais:
115
+
116
+ ```javascript
117
+ const { dynamoDB, s3, sqs, cognito } = require('aws-local-simulator/aws-config');
118
+
119
+ await dynamoDB.send(new PutCommand({
120
+ TableName: 'users-table',
121
+ Item: { id: '123', name: 'John' }
122
+ }));
123
+ ```
124
+
125
+ ## 🔧 Configuração por Variáveis de Ambiente
126
+
127
+ | Variável | Descrição | Padrão |
128
+ |---------|----------|-------|
129
+ | AWS_LOCAL_SIMULATOR_DYNAMODB | Habilita DynamoDB | true |
130
+ | AWS_LOCAL_SIMULATOR_S3 | Habilita S3 | true |
131
+ | AWS_LOCAL_SIMULATOR_SQS | Habilita SQS | true |
132
+ | AWS_LOCAL_SIMULATOR_LAMBDA | Habilita Lambda | true |
133
+ | AWS_LOCAL_SIMULATOR_COGNITO | Habilita Cognito | false |
134
+ | AWS_LOCAL_SIMULATOR_APIGATEWAY | Habilita API Gateway | false |
135
+ | AWS_LOCAL_SIMULATOR_STS | Habilita STS | true |
136
+ | AWS_LOCAL_SIMULATOR_SNS | Habilita SNS | false |
137
+ | AWS_LOCAL_SIMULATOR_EVENTBRIDGE | Habilita EventBridge | false |
138
+ | AWS_LOCAL_SIMULATOR_KMS | Habilita KMS | false |
139
+ | AWS_LOCAL_SIMULATOR_SECRET_MANAGER | Habilita Secrets Manager | false |
140
+ | AWS_LOCAL_SIMULATOR_PARAMETER_STORE | Habilita Parameter Store | false |
141
+ | AWS_LOCAL_SIMULATOR_CLOUDWATCH | Habilita CloudWatch | false |
142
+ | AWS_LOCAL_SIMULATOR_CLOUDTRAIL | Habilita CloudTrail | false |
143
+ | AWS_LOCAL_SIMULATOR_CLOUDFORMATION | Habilita CloudFormation | false |
144
+ | AWS_LOCAL_SIMULATOR_ATHENA | Habilita Athena | false |
145
+ | AWS_LOCAL_SIMULATOR_XRAY | Habilita X-Ray | false |
146
+ | AWS_LOCAL_SIMULATOR_CONFIG | Habilita AWS Config | false |
147
+ | AWS_LOCAL_SIMULATOR_ECS | Habilita ECS/Fargate | false |
148
+ | AWS_LOCAL_SIMULATOR_DYNAMODB_PORT | Porta DynamoDB | 8000 |
149
+ | AWS_LOCAL_SIMULATOR_S3_PORT | Porta S3 | 4566 |
150
+ | AWS_LOCAL_SIMULATOR_SQS_PORT | Porta SQS | 9324 |
151
+ | AWS_LOCAL_SIMULATOR_LAMBDA_PORT | Porta Lambda | 3001 |
152
+ | AWS_LOCAL_SIMULATOR_COGNITO_PORT | Porta Cognito | 9229 |
153
+ | AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT | Porta API Gateway | 4567 |
154
+ | AWS_LOCAL_SIMULATOR_STS_PORT | Porta STS | 9326 |
155
+ | AWS_LOCAL_SIMULATOR_SNS_PORT | Porta SNS | 9911 |
156
+ | AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT | Porta EventBridge | 4010 |
157
+ | AWS_LOCAL_SIMULATOR_KMS_PORT | Porta KMS | 4000 |
158
+ | AWS_LOCAL_SIMULATOR_SECRET_MANAGER_PORT | Porta Secrets Manager | 4001 |
159
+ | AWS_LOCAL_SIMULATOR_PARAMETER_STORE_PORT | Porta Parameter Store | 4002 |
160
+ | AWS_LOCAL_SIMULATOR_CLOUDWATCH_PORT | Porta CloudWatch | 4011 |
161
+ | AWS_LOCAL_SIMULATOR_CLOUDTRAIL_PORT | Porta CloudTrail | 4012 |
162
+ | AWS_LOCAL_SIMULATOR_CONFIG_PORT | Porta AWS Config | 4013 |
163
+ | AWS_LOCAL_SIMULATOR_XRAY_PORT | Porta X-Ray | 4015 |
164
+ | AWS_LOCAL_SIMULATOR_CLOUDFORMATION_PORT | Porta CloudFormation | 4580 |
165
+ | AWS_LOCAL_SIMULATOR_ATHENA_PORT | Porta Athena | 4599 |
166
+ | AWS_LOCAL_SIMULATOR_ECS_PORT | Porta ECS | 8080 |
167
+ | AWS_LOCAL_SIMULATOR_DATA | Diretório de dados | ./aws-local-simulator-data |
168
+ | AWS_LOCAL_SIMULATOR_LOG | Nível de log | info |
169
+
170
+ ## 📝 Comandos CLI
171
+
172
+ ```bash
173
+ # Iniciar simulador
174
+ npx aws-local-simulator start [configPath]
175
+
176
+ # Parar simulador
177
+ npx aws-local-simulator stop
178
+
179
+ # Reiniciar
180
+ npx aws-local-simulator restart
181
+
182
+ # Resetar dados
183
+ npx aws-local-simulator reset
184
+
185
+ # Status
186
+ npx aws-local-simulator status
187
+ ```
188
+
189
+ ## 🔌 Endpoints
190
+
191
+ | Serviço | Endpoint | Admin |
192
+ |---------|----------|-------|
193
+ | DynamoDB | http://localhost:8000 | http://localhost:8000/__admin/tables |
194
+ | S3 | http://localhost:4566 | http://localhost:4566/__admin/buckets |
195
+ | S3 Website | http://localhost:4566/website/{bucket}/ | — |
196
+ | SQS | http://localhost:9324 | http://localhost:9324/__admin/queues |
197
+ | Lambda | http://localhost:3001 | http://localhost:3001/__admin/functions |
198
+ | Cognito | http://localhost:9229 | http://localhost:9229/__admin/userpools |
199
+ | API Gateway | http://localhost:4567 | http://localhost:4567/__admin/apis |
200
+ | STS | http://localhost:9326 | — |
201
+ | SNS | http://localhost:9911 | http://localhost:9911/__admin/health |
202
+ | EventBridge | http://localhost:4010 | — |
203
+ | KMS | http://localhost:4000 | — |
204
+ | Secrets Manager | http://localhost:4001 | — |
205
+ | Parameter Store | http://localhost:4002 | — |
206
+ | CloudWatch | http://localhost:4011 | — |
207
+ | CloudTrail | http://localhost:4012 | — |
208
+ | AWS Config | http://localhost:4013 | — |
209
+ | X-Ray | http://localhost:4015 | — |
210
+ | CloudFormation | http://localhost:4580 | http://localhost:4580/__admin/stacks |
211
+ | Athena | http://localhost:4599 | http://localhost:4599/__admin/health |
212
+ | ECS | http://localhost:8080 | http://localhost:8080/__admin/clusters |
213
+
214
+ ## 🧪 Testando com AWS CLI
215
+
216
+ ```bash
217
+ # DynamoDB
218
+ aws dynamodb list-tables --endpoint-url http://localhost:8000
219
+
220
+ # S3
221
+ aws s3 ls --endpoint-url http://localhost:4566
222
+
223
+ # SQS
224
+ aws sqs list-queues --endpoint-url http://localhost:9324
225
+
226
+ # Lambda
227
+ aws lambda invoke \
228
+ --function-name my-function \
229
+ --payload '{"key":"value"}' \
230
+ --endpoint-url http://localhost:3001 \
231
+ output.json
232
+
233
+ # Cognito
234
+ aws cognito-idp list-user-pools --max-results 10 --endpoint-url http://localhost:9229
235
+
236
+ # Cognito cadastrar um usuario pelo adminstrador
237
+ aws cognito-idp admin-create-user \
238
+ --user-pool-id us-east-xxxx\
239
+ --username usuario@email.com \
240
+ --user-attributes \
241
+ Name=email,Value=usuario@email.com \
242
+ Name=email_verified,Value=false \
243
+ Name=name,Value="nome usuario" \
244
+ Name=custom:role,Value="user" \
245
+ temporary-password "Teste@123456" \
246
+ --message-action SUPPRESS \
247
+ --endpoint-url http://localhost:9229
248
+
249
+ # Cognito excluir um usuario
250
+ aws cognito-idp admin-delete-user \
251
+ --user-pool-id us-east-xxxx \
252
+ --username usuario@email.com
253
+ --endpoint-url http://localhost:9229
254
+
255
+ # Cognito Registrar usuário
256
+ aws cognito-idp sign-up \
257
+ --client-id $CLIENT_ID \
258
+ --username usuario@email.com \
259
+ --password "Teste@123456" \
260
+ --user-attributes Name=email,Value=usuario@email.com Name=name,Value="nome usuario"
261
+ --endpoint-url http://localhost:9229
262
+
263
+ # 2. Confirmar usuário administrativamente
264
+ aws cognito-idp admin-confirm-sign-up \
265
+ --user-pool-id us-east-xxxx \
266
+ --username usuario@email.com
267
+ --endpoint-url http://localhost:9229
268
+
269
+ # O código chega no e-mail do usuário. Algo como: "Your confirmation code is 123456"
270
+ aws cognito-idp confirm-sign-up \
271
+ --client-id 3n4b5urk1ft4fl3mg5e62d9ado \
272
+ --username usuario@email.com \
273
+ --confirmation-code 123456
274
+ --endpoint-url http://localhost:9229
275
+
276
+ # STS
277
+ aws sts get-caller-identity --endpoint-url http://localhost:9326
278
+ aws sts assume-role \
279
+ --role-arn "arn:aws:iam::123456789012:role/my-role" \
280
+ --role-session-name "my-session" \
281
+ --endpoint-url http://localhost:9326
282
+
283
+ # SNS
284
+ aws sns list-topics --endpoint-url http://localhost:9911
285
+
286
+ # EventBridge
287
+ aws events list-event-buses --endpoint-url http://localhost:4010
288
+
289
+ # KMS
290
+ aws kms list-keys --endpoint-url http://localhost:4000
291
+
292
+ # Secrets Manager
293
+ aws secretsmanager list-secrets --endpoint-url http://localhost:4001
294
+
295
+ # Criar secret
296
+ aws secretsmanager create-secret \
297
+ --name "local/app/db-credentials" \
298
+ --description "Credenciais do banco" \
299
+ --secret-string '{"username":"admin","password":"secret123"}' \
300
+ --endpoint-url http://localhost:4001
301
+
302
+ # Ler secret
303
+ aws secretsmanager get-secret-value \
304
+ --secret-id "local/app/db-credentials" \
305
+ --endpoint-url http://localhost:4001
306
+
307
+ # Parameter Store
308
+ aws ssm describe-parameters --endpoint-url http://localhost:4002
309
+
310
+ # Criar parâmetro String
311
+ aws ssm put-parameter \
312
+ --name "/local/app/config" \
313
+ --value '{"timeout":30,"maxRetries":3}' \
314
+ --type String \
315
+ --endpoint-url http://localhost:4002
316
+
317
+ # Criar parâmetro SecureString
318
+ aws ssm put-parameter \
319
+ --name "/local/app/api-key" \
320
+ --value "my-secret-api-key" \
321
+ --type SecureString \
322
+ --endpoint-url http://localhost:4002
323
+
324
+ # Ler parâmetro
325
+ aws ssm get-parameter \
326
+ --name "/local/app/config" \
327
+ --endpoint-url http://localhost:4002
328
+
329
+ # CloudWatch
330
+ aws cloudwatch list-metrics --endpoint-url http://localhost:4011
331
+ aws logs describe-log-groups --endpoint-url http://localhost:4011
332
+
333
+ # CloudTrail
334
+ aws cloudtrail describe-trails --endpoint-url http://localhost:4012
335
+
336
+ # CloudFormation
337
+ aws cloudformation list-stacks --endpoint-url http://localhost:4580
338
+
339
+ # X-Ray
340
+ aws xray get-trace-summaries \
341
+ --start-time $(date -d '1 hour ago' +%s) \
342
+ --end-time $(date +%s) \
343
+ --endpoint-url http://localhost:4015
344
+
345
+ # AWS Config
346
+ aws configservice describe-configuration-recorders --endpoint-url http://localhost:4013
347
+
348
+ # API Gateway
349
+ aws apigateway get-rest-apis --endpoint-url http://localhost:4567
350
+
351
+ # Cloudformation
352
+ aws cloudformation create-stack \
353
+ --stack-name test-stack \
354
+ --template-body file://templates/test-stack.yaml \
355
+ --parameters \
356
+ ParameterKey=Environment,ParameterValue=local \
357
+ ParameterKey=BucketName,ParameterValue=meu-bucket \
358
+ ParameterKey=QueueName,ParameterValue=minha-fila \
359
+ ParameterKey=TableName,ParameterValue=minha-tabela \
360
+ --endpoint-url http://localhost:4580
361
+
362
+ # Ver Cloudformation resultado
363
+ aws cloudformation describe-stacks \
364
+ --stack-name test-stack \
365
+ --endpoint-url http://localhost:4580
366
+
367
+ # Athena
368
+ # Criar workgroup
369
+ aws athena create-work-group \
370
+ --name my-workgroup \
371
+ --configuration ResultConfiguration={OutputLocation=s3://meu-bucket/athena-results/} \
372
+ --endpoint-url http://localhost:4599
373
+
374
+ # Listar workgroups
375
+ aws athena list-work-groups --endpoint-url http://localhost:4599
376
+
377
+ # Executar query
378
+ aws athena start-query-execution \
379
+ --query-string "SELECT * FROM my_table LIMIT 10" \
380
+ --query-execution-context Database=default \
381
+ --result-configuration OutputLocation=s3://meu-bucket/athena-results/ \
382
+ --endpoint-url http://localhost:4599
383
+
384
+ # Verificar status da query
385
+ aws athena get-query-execution \
386
+ --query-execution-id <id-retornado> \
387
+ --endpoint-url http://localhost:4599
388
+
389
+ # Buscar resultados
390
+ aws athena get-query-results \
391
+ --query-execution-id <id-retornado> \
392
+ --endpoint-url http://localhost:4599
393
+
394
+ # Criar named query
395
+ aws athena create-named-query \
396
+ --name "my-saved-query" \
397
+ --database default \
398
+ --query-string "SELECT id, value FROM my_table WHERE status = 'active'" \
399
+ --endpoint-url http://localhost:4599
400
+
401
+ # Listar named queries
402
+ aws athena list-named-queries --endpoint-url http://localhost:4599
403
+ ```
404
+
405
+ ## ⚙️ Configuração S3
406
+
407
+ ### Buckets simples
408
+
409
+ ```json
410
+ {
411
+ "s3": {
412
+ "buckets": [
413
+ "my-bucket"
414
+ ]
415
+ }
416
+ }
417
+ ```
418
+
419
+ ### Buckets com região e website estático
420
+
421
+ ```json
422
+ {
423
+ "s3": {
424
+ "buckets": [
425
+ { "name": "my-bucket", "region": "us-east-1" },
426
+ {
427
+ "name": "my-site-bucket",
428
+ "region": "us-east-1",
429
+ "websiteConfiguration": {
430
+ "IndexDocument": { "Suffix": "index.html" },
431
+ "ErrorDocument": { "Key": "error.html" }
432
+ }
433
+ }
434
+ ]
435
+ }
436
+ }
437
+ ```
438
+
439
+ Quando `websiteConfiguration` está presente, o bucket serve arquivos estáticos.
440
+
441
+ ### URL do website estático
442
+
443
+ ```
444
+ http://localhost:4566/website/{bucket-name}/
445
+ http://localhost:4566/website/{bucket-name}/caminho/pagina.html
446
+ ```
447
+
448
+ Exemplos:
449
+ ```
450
+ http://localhost:4566/website/my-site-bucket/ → serve index.html
451
+ http://localhost:4566/website/my-site-bucket/about.html → serve about.html
452
+ http://localhost:4566/website/my-site-bucket/app/ → serve app/index.html
453
+ ```
454
+
455
+ ### Gerenciar website config via AWS CLI
456
+
457
+ ```bash
458
+ # Habilitar website em um bucket existente
459
+ aws s3api put-bucket-website \
460
+ --bucket my-site-bucket \
461
+ --website-configuration '{"IndexDocument":{"Suffix":"index.html"},"ErrorDocument":{"Key":"error.html"}}' \
462
+ --endpoint-url http://localhost:4566
463
+
464
+ # Ver configuração de website
465
+ aws s3api get-bucket-website \
466
+ --bucket my-site-bucket \
467
+ --endpoint-url http://localhost:4566
468
+
469
+ # Remover website
470
+ aws s3api delete-bucket-website \
471
+ --bucket my-site-bucket \
472
+ --endpoint-url http://localhost:4566
473
+ ```
474
+
475
+ ## ⚙️ Configuração de Lambdas
476
+
477
+ Lambdas são registradas por **nome** e invocadas via API de invocação (igual à AWS real). O roteamento HTTP é feito pelo API Gateway.
478
+
479
+ ```json
480
+ {
481
+ "lambdas": [
482
+ {
483
+ "name": "my-user-function",
484
+ "handler": "./src/handlers/my-user-function.js",
485
+ "env": {
486
+ "TABLE_NAME": "users-table",
487
+ "BUCKET_NAME": "my-bucket"
488
+ }
489
+ }
490
+ ]
491
+ }
492
+ ```
493
+
494
+ ## ⚙️ Configuração SQS com Lambda Trigger
495
+
496
+ Para disparar uma Lambda automaticamente quando uma mensagem chega na fila, use o formato de objeto na lista de filas com `lambdaName`:
497
+
498
+ ```json
499
+ {
500
+ "lambdas": [
501
+ {
502
+ "name": "process-orders",
503
+ "handler": "./src/handlers/process-orders.js"
504
+ }
505
+ ],
506
+ "sqs": {
507
+ "queues": [
508
+ "simple-queue",
509
+ {
510
+ "name": "orders-queue",
511
+ "lambdaName": "process-orders",
512
+ "batchSize": 5
513
+ }
514
+ ]
515
+ }
516
+ }
517
+ ```
518
+
519
+ - Filas simples (string) são criadas sem trigger
520
+ - Filas com objeto aceitam `lambdaName` (nome da Lambda registrada) e `batchSize` (padrão: 10)
521
+ - Quando uma mensagem é enviada para `orders-queue`, a Lambda `process-orders` é invocada automaticamente com o evento no formato SQS padrão da AWS
522
+
523
+ O handler recebe o evento no formato padrão AWS SQS:
524
+
525
+ ```javascript
526
+ exports.handler = async (event) => {
527
+ for (const record of event.Records) {
528
+ const body = JSON.parse(record.body);
529
+ console.log('Mensagem recebida:', body);
530
+ // processar...
531
+ }
532
+
533
+ // Retornar batchItemFailures para reprocessar mensagens específicas
534
+ return { batchItemFailures: [] };
535
+ };
536
+ ```
537
+
538
+ ## ⚙️ Configuração API GATEWAY
539
+
540
+ O valor do **lambdaName** deve igual ao nome Lambda que está registrada com o valor **name**. Ex: "my-user-function".
541
+
542
+ ```json
543
+ {
544
+ "apigateway": {
545
+ "apis": [
546
+ {
547
+ "name": "Users API",
548
+ "description": "API para gerenciamento de usuários",
549
+ "endpoints": [
550
+ {
551
+ "path": "/user",
552
+ "method": "GET",
553
+ "lambdaName": "my-user-function",
554
+ "integrationType": "lambda"
555
+ },
556
+ {
557
+ "path": "/user",
558
+ "method": "POST",
559
+ "lambdaName": "my-user-function",
560
+ "integrationType": "lambda"
561
+ },
562
+ {
563
+ "path": "/user/{id}",
564
+ "method": "GET",
565
+ "lambdaName": "my-user-function",
566
+ "integrationType": "lambda"
567
+ },
568
+ {
569
+ "path": "/user/{id}",
570
+ "method": "DELETE",
571
+ "lambdaName": "my-user-function",
572
+ "integrationType": "lambda"
573
+ },
574
+ {
575
+ "path": "/user/{id}",
576
+ "method": "ANY",
577
+ "lambdaName": "my-user-function",
578
+ "integrationType": "lambda"
579
+ }
580
+ ]
581
+ }
582
+ ]
583
+ }
584
+ }
585
+ ```
586
+
587
+ ### Método ANY
588
+
589
+ Use `"method": "ANY"` para registrar um endpoint que aceita todos os verbos HTTP (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) — equivalente ao `ANY` do AWS API Gateway real.
590
+
591
+ ```json
592
+ {
593
+ "path": "/webhook",
594
+ "method": "ANY",
595
+ "lambdaName": "my-webhook-handler",
596
+ "integrationType": "lambda"
597
+ }
598
+ ```
599
+
600
+ ### API Key
601
+
602
+ O API Gateway suporta validação de API Key via header `x-api-key`. Para proteger um endpoint, declare as `apiKeys` na configuração e use `"apiKeyRequired": true` no endpoint:
603
+
604
+ ```json
605
+ {
606
+ "apigateway": {
607
+ "apiKeys": [
608
+ {
609
+ "name": "my-app-key",
610
+ "value": "minha-chave-secreta-123"
611
+ }
612
+ ],
613
+ "apis": [
614
+ {
615
+ "name": "Protected API",
616
+ "endpoints": [
617
+ {
618
+ "path": "/protected",
619
+ "method": "GET",
620
+ "lambdaName": "my-user-function",
621
+ "integrationType": "lambda",
622
+ "apiKeyRequired": true
623
+ },
624
+ {
625
+ "path": "/public",
626
+ "method": "GET",
627
+ "lambdaName": "my-user-function",
628
+ "integrationType": "lambda"
629
+ }
630
+ ]
631
+ }
632
+ ]
633
+ }
634
+ }
635
+ ```
636
+
637
+ Ao chamar um endpoint protegido, envie o header:
638
+
639
+ ```bash
640
+ curl http://localhost:4567/protected \
641
+ -H "x-api-key: minha-chave-secreta-123"
642
+
643
+ # Sem a key → 403 Forbidden
644
+ curl http://localhost:4567/protected
645
+ ```
646
+
647
+ > **Nota:** A validação de API Key só está ativa no fluxo de proxy (`/:apiId/:stageName/*`). Endpoints declarados diretamente no `aws-local-simulator.json` via `setupConfigRoutes` não aplicam a validação de API Key no momento.
648
+
649
+ ### Cognito Authorizer
650
+
651
+ O API Gateway suporta autenticação via Cognito User Pools. Configure um `authorizer` na API e marque os endpoints protegidos com `"authorizerRequired": true`:
652
+
653
+ ```json
654
+ {
655
+ "cognito": {
656
+ "userPools": [
657
+ {
658
+ "PoolName": "my-user-pool",
659
+ "UserPoolId": "us-east-XXXXX",
660
+ "ClientId": "XXXXXX",
661
+ "AutoVerifiedAttributes": ["email"]
662
+ }
663
+ ]
664
+ },
665
+ "apigateway": {
666
+ "apis": [
667
+ {
668
+ "name": "My API",
669
+ "authorizer": {
670
+ "type": "COGNITO_USER_POOLS",
671
+ "userPoolId": "us-east-XXXXX"
672
+ },
673
+ "endpoints": [
674
+ {
675
+ "path": "/profile",
676
+ "method": "GET",
677
+ "lambdaName": "my-user-function",
678
+ "integrationType": "lambda",
679
+ "authorizerRequired": true
680
+ },
681
+ {
682
+ "path": "/public",
683
+ "method": "GET",
684
+ "lambdaName": "my-user-function",
685
+ "integrationType": "lambda"
686
+ }
687
+ ]
688
+ }
689
+ ]
690
+ }
691
+ }
692
+ ```
693
+
694
+ O simulador valida o JWT do Cognito local no header `Authorization: Bearer <token>`. Se o token for inválido ou ausente, retorna `401 Unauthorized`.
695
+
696
+ ```bash
697
+ # 1. Autenticar e obter o token
698
+ TOKEN=$(curl -s -X POST http://localhost:9229/ \
699
+ -H "Content-Type: application/x-amz-json-1.1" \
700
+ -H "X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth" \
701
+ -d '{
702
+ "AuthFlow": "USER_PASSWORD_AUTH",
703
+ "ClientId": "XXXXXX",
704
+ "AuthParameters": {
705
+ "USERNAME": "usuario@email.com",
706
+ "PASSWORD": "Senha@123"
707
+ }
708
+ }' | jq -r '.AuthenticationResult.IdToken')
709
+
710
+ # 2. Chamar endpoint protegido com o token
711
+ curl http://localhost:4567/profile \
712
+ -H "Authorization: Bearer $TOKEN"
713
+
714
+ # Sem token → 401 Unauthorized
715
+ curl http://localhost:4567/profile
716
+ ```
717
+
718
+ O token decodificado fica disponível no Lambda em `event.requestContext.authorizer.claims`:
719
+
720
+ ```javascript
721
+ exports.handler = async (event) => {
722
+ const claims = event.requestContext.authorizer?.claims;
723
+ const userId = claims?.sub;
724
+ const email = claims?.email;
725
+
726
+ return {
727
+ statusCode: 200,
728
+ body: JSON.stringify({ userId, email })
729
+ };
730
+ };
731
+ ```
732
+
733
+ O handler deve exportar uma função padrão:
734
+
735
+ ```javascript
736
+ exports.handler = async (event, context) => {
737
+ return {
738
+ statusCode: 200,
739
+ body: JSON.stringify({ message: 'Hello from Lambda!' })
740
+ };
741
+ };
742
+ ```
743
+
744
+ ## 📁 Estrutura de Dados
745
+
746
+ Os dados são persistidos em:
747
+
748
+ ```text
749
+ .aws-local-simulator-data/
750
+ ├── dynamodb/
751
+ ├── s3/
752
+ ├── sqs/
753
+ ├── cognito/
754
+ ├── apigateway/
755
+ ├── ecs/
756
+ ├── kms/
757
+ ├── secret-manager/
758
+ ├── parameter-store/
759
+ ├── cloudwatch/
760
+ ├── cloudtrail/
761
+ ├── cloudformation/
762
+ ├── athena/
763
+ ├── xray/
764
+ └── config/
765
+ ```
766
+
767
+ ## 🐛 Debug
768
+
769
+ ```bash
770
+ AWS_LOCAL_SIMULATOR_LOG=verbose npx aws-local-simulator start
771
+ ```
772
+
773
+ ## 🤝 Contribuindo
774
+
775
+ 1. Fork o projeto
776
+ 2. Crie sua feature branch (`git checkout -b feature/AmazingFeature`)
777
+ 3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`)
778
+ 4. Push para a branch (`git push origin feature/AmazingFeature`)
779
+ 5. Abra um Pull Request
780
+
781
+ ## 📄 Licença
782
+
783
+ MIT © Luiz Gustavo Ribeiro
784
+
785
+ ## ⚠️ Limitações
786
+
787
+ - ECS/Fargate em desenvolvimento
788
+ - WebSocket APIs em desenvolvimento
789
+ - Para uso em desenvolvimento e testes apenas