@gugananuvem/aws-local-simulator 1.0.34 → 1.0.39

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 (150) hide show
  1. package/README.md +662 -658
  2. package/package.json +11 -4
  3. package/src/config/default-config.js +71 -0
  4. package/src/config/env-loader.js +4 -2
  5. package/src/middleware/authorization.js +271 -0
  6. package/src/middleware/cloudtrail-logger.js +333 -0
  7. package/src/middleware/error-handler.js +138 -0
  8. package/src/middleware/index.js +79 -0
  9. package/src/middleware/policy-enforcement.js +407 -0
  10. package/src/server.js +74 -4
  11. package/src/services/acm/index.js +66 -0
  12. package/src/services/acm/models/certificate.js +202 -0
  13. package/src/services/acm/server.js +224 -0
  14. package/src/services/acm/simulator.js +293 -0
  15. package/src/services/alb/index.js +104 -0
  16. package/src/services/alb/models/loadBalancer.js +88 -0
  17. package/src/services/alb/models/targetGroup.js +128 -0
  18. package/src/services/alb/server.js +160 -0
  19. package/src/services/alb/simulator.js +262 -0
  20. package/src/services/apigateway/index.js +22 -0
  21. package/src/services/apigateway/server.js +247 -35
  22. package/src/services/apigateway/simulator.js +780 -26
  23. package/src/services/asg/index.js +100 -0
  24. package/src/services/asg/models/autoScalingGroup.js +110 -0
  25. package/src/services/asg/models/launchTemplate.js +41 -0
  26. package/src/services/asg/models/scalingPolicy.js +51 -0
  27. package/src/services/asg/server.js +236 -0
  28. package/src/services/asg/simulator.js +410 -0
  29. package/src/services/aurora/cluster-manager.js +731 -0
  30. package/src/services/aurora/data-api.js +514 -0
  31. package/src/services/aurora/db-engine.js +270 -0
  32. package/src/services/aurora/index.js +159 -0
  33. package/src/services/aurora/rds-api.js +189 -0
  34. package/src/services/aurora/server.js +213 -0
  35. package/src/services/aurora/sql-translator.js +334 -0
  36. package/src/services/cloudformation/index.js +2 -2
  37. package/src/services/cloudformation/server.js +1 -0
  38. package/src/services/cloudfront/cache-engine.js +225 -0
  39. package/src/services/cloudfront/geo-restrictions.js +377 -0
  40. package/src/services/cloudfront/index.js +220 -0
  41. package/src/services/cloudfront/models/behavior.js +158 -0
  42. package/src/services/cloudfront/models/distribution.js +284 -0
  43. package/src/services/cloudfront/models/index.js +99 -0
  44. package/src/services/cloudfront/models/invalidation.js +109 -0
  45. package/src/services/cloudfront/models/origin.js +155 -0
  46. package/src/services/cloudfront/origin-router.js +552 -0
  47. package/src/services/cloudfront/origin-validator.js +398 -0
  48. package/src/services/cloudfront/server.js +512 -0
  49. package/src/services/cloudfront/signed-url-generator.js +377 -0
  50. package/src/services/cloudfront/simulator.js +425 -0
  51. package/src/services/cloudfront/store.js +326 -0
  52. package/src/services/cloudshell/env-builder.js +27 -0
  53. package/src/services/cloudshell/index.js +48 -0
  54. package/src/services/cloudshell/routes.js +60 -0
  55. package/src/services/cloudshell/session-manager.js +226 -0
  56. package/src/services/cloudshell/static/.gitkeep +0 -0
  57. package/src/services/cloudshell/static/index.html +406 -0
  58. package/src/services/cloudshell/websocket-handler.js +107 -0
  59. package/src/services/cloudtrail/index.js +2 -3
  60. package/src/services/cloudtrail/server.js +68 -0
  61. package/src/services/cognito/server.js +4 -1
  62. package/src/services/dynamodb/server.js +4 -1
  63. package/src/services/dynamodb/simulator.js +2 -1
  64. package/src/services/ec2/index.js +101 -0
  65. package/src/services/ec2/instanceServer.js +311 -0
  66. package/src/services/ec2/models/ami.js +39 -0
  67. package/src/services/ec2/models/instance.js +98 -0
  68. package/src/services/ec2/models/networkInterface.js +74 -0
  69. package/src/services/ec2/models/securityGroup.js +71 -0
  70. package/src/services/ec2/server.js +350 -0
  71. package/src/services/ec2/simulator.js +436 -0
  72. package/src/services/eventbridge/server.js +36 -0
  73. package/src/services/eventbridge/simulator.js +230 -45
  74. package/src/services/iam/index.js +65 -0
  75. package/src/services/iam/middleware.js +99 -0
  76. package/src/services/iam/server.js +331 -0
  77. package/src/services/iam/simulator.js +1432 -0
  78. package/src/services/index.js +28 -0
  79. package/src/services/kinesis-analytics/index.js +105 -0
  80. package/src/services/kinesis-analytics/models/application.js +325 -0
  81. package/src/services/kinesis-analytics/models/index.js +12 -0
  82. package/src/services/kinesis-analytics/server.js +250 -0
  83. package/src/services/kinesis-analytics/simulator.js +407 -0
  84. package/src/services/kinesis-analytics/store.js +176 -0
  85. package/src/services/kinesis-data-streams/index.js +106 -0
  86. package/src/services/kinesis-data-streams/models/index.js +12 -0
  87. package/src/services/kinesis-data-streams/models/record.js +70 -0
  88. package/src/services/kinesis-data-streams/models/stream.js +280 -0
  89. package/src/services/kinesis-data-streams/server.js +255 -0
  90. package/src/services/kinesis-data-streams/simulator.js +514 -0
  91. package/src/services/kinesis-data-streams/store.js +163 -0
  92. package/src/services/kinesis-firehose/index.js +106 -0
  93. package/src/services/kinesis-firehose/models/delivery-stream.js +265 -0
  94. package/src/services/kinesis-firehose/models/index.js +10 -0
  95. package/src/services/kinesis-firehose/server.js +215 -0
  96. package/src/services/kinesis-firehose/simulator.js +388 -0
  97. package/src/services/kinesis-firehose/store.js +163 -0
  98. package/src/services/kms/server.js +4 -1
  99. package/src/services/lambda/handler-loader.js +50 -5
  100. package/src/services/lambda/index.js +26 -0
  101. package/src/services/lambda/server.js +18 -12
  102. package/src/services/lambda/simulator.js +73 -17
  103. package/src/services/opensearch/index.js +105 -0
  104. package/src/services/opensearch/models/document.js +115 -0
  105. package/src/services/opensearch/models/index.js +73 -0
  106. package/src/services/opensearch/server.js +310 -0
  107. package/src/services/opensearch/simulator.js +605 -0
  108. package/src/services/opensearch/store.js +162 -0
  109. package/src/services/organizations/control-tower-simulator.js +321 -0
  110. package/src/services/organizations/control-tower-store.js +182 -0
  111. package/src/services/organizations/iam-integration.js +413 -0
  112. package/src/services/organizations/index.js +172 -0
  113. package/src/services/organizations/models/index.js +13 -0
  114. package/src/services/organizations/models/invitation.js +48 -0
  115. package/src/services/organizations/models/organization.js +566 -0
  116. package/src/services/organizations/models/role.js +244 -0
  117. package/src/services/organizations/models/scp.js +131 -0
  118. package/src/services/organizations/server.js +736 -0
  119. package/src/services/organizations/simulator.js +593 -0
  120. package/src/services/organizations/store.js +235 -0
  121. package/src/services/organizations/vpc-integration.js +453 -0
  122. package/src/services/route53/index.js +67 -0
  123. package/src/services/route53/models/healthCheck.js +101 -0
  124. package/src/services/route53/models/hostedZone.js +37 -0
  125. package/src/services/route53/models/resourceRecord.js +106 -0
  126. package/src/services/route53/server.js +841 -0
  127. package/src/services/route53/simulator.js +350 -0
  128. package/src/services/s3/index.js +62 -0
  129. package/src/services/s3/presigned-url-generator.js +337 -0
  130. package/src/services/s3/server.js +231 -0
  131. package/src/services/s3/simulator.js +551 -4
  132. package/src/services/sns/index.js +31 -0
  133. package/src/services/sns/server.js +9 -0
  134. package/src/services/sqs/index.js +38 -0
  135. package/src/services/sqs/server.js +57 -4
  136. package/src/services/sqs/simulator.js +423 -33
  137. package/src/services/sts/simulator.js +209 -17
  138. package/src/services/vpc/README.md +459 -0
  139. package/src/services/vpc/ec2ResponseFormatter.js +431 -0
  140. package/src/services/vpc/index.js +90 -0
  141. package/src/services/vpc/models/internetGateway.js +71 -0
  142. package/src/services/vpc/models/routeTable.js +160 -0
  143. package/src/services/vpc/models/subnet.js +48 -0
  144. package/src/services/vpc/models/vpc.js +37 -0
  145. package/src/services/vpc/models/vpcEndpoint.js +100 -0
  146. package/src/services/vpc/models/vpcGateway.js +134 -0
  147. package/src/services/vpc/server.js +836 -0
  148. package/src/services/vpc/simulator.js +613 -0
  149. package/src/utils/policy-cache.js +215 -0
  150. package/aws-config +0 -154
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Policy Cache - TTL configurable
3
+ *
4
+ * Cacheia resultados de avaliação de políticas para evitar
5
+ * re-avaliação desnecessária (default: 60 segundos)
6
+ */
7
+
8
+ const logger = require('./logger');
9
+
10
+ class PolicyCache {
11
+ constructor(ttl = 60000) {
12
+ this.cache = new Map();
13
+ this.ttl = ttl; // milliseconds
14
+ this.hits = 0;
15
+ this.misses = 0;
16
+ this.stats = {
17
+ totalGets: 0,
18
+ totalSets: 0,
19
+ totalDeletes: 0,
20
+ averageHitRate: 0
21
+ };
22
+
23
+ // Cleanup de entries expiradas a cada 30 segundos
24
+ this.cleanupInterval = setInterval(() => this.cleanup(), 30000);
25
+ }
26
+
27
+ /**
28
+ * Get com verificação de expiração
29
+ */
30
+ get(key) {
31
+ this.stats.totalGets++;
32
+
33
+ const entry = this.cache.get(key);
34
+
35
+ if (!entry) {
36
+ this.misses++;
37
+ this.updateHitRate();
38
+ return null;
39
+ }
40
+
41
+ // Verificar se expirou
42
+ if (entry.expiresAt < Date.now()) {
43
+ this.cache.delete(key);
44
+ this.misses++;
45
+ this.updateHitRate();
46
+ return null;
47
+ }
48
+
49
+ this.hits++;
50
+ this.updateHitRate();
51
+ entry.lastAccessed = Date.now();
52
+ entry.accessCount++;
53
+
54
+ logger.debug(`Cache HIT: ${key}`);
55
+ return entry.value;
56
+ }
57
+
58
+ /**
59
+ * Set com TTL automático
60
+ */
61
+ set(key, value) {
62
+ this.stats.totalSets++;
63
+
64
+ const now = Date.now();
65
+ this.cache.set(key, {
66
+ value,
67
+ createdAt: now,
68
+ expiresAt: now + this.ttl,
69
+ lastAccessed: now,
70
+ accessCount: 0
71
+ });
72
+
73
+ logger.debug(`Cache SET: ${key} (expires in ${this.ttl}ms)`);
74
+ }
75
+
76
+ /**
77
+ * Invalidar entrada específica
78
+ */
79
+ delete(key) {
80
+ this.stats.totalDeletes++;
81
+ this.cache.delete(key);
82
+ logger.debug(`Cache DELETE: ${key}`);
83
+ }
84
+
85
+ /**
86
+ * Invalidar todas entries de um padrão
87
+ * Ex: "123456789012|*" → deleta todas ações desse principal
88
+ */
89
+ deletePattern(pattern) {
90
+ const regex = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`);
91
+ let deleted = 0;
92
+
93
+ for (const key of this.cache.keys()) {
94
+ if (regex.test(key)) {
95
+ this.cache.delete(key);
96
+ deleted++;
97
+ }
98
+ }
99
+
100
+ logger.debug(`Cache DELETE PATTERN: ${pattern} (deleted ${deleted} entries)`);
101
+ return deleted;
102
+ }
103
+
104
+ /**
105
+ * Clear tudo
106
+ */
107
+ clear() {
108
+ const size = this.cache.size;
109
+ this.cache.clear();
110
+ logger.debug(`Cache CLEAR: removed ${size} entries`);
111
+ }
112
+
113
+ /**
114
+ * Cleanup de entries expiradas
115
+ */
116
+ cleanup() {
117
+ const now = Date.now();
118
+ let expired = 0;
119
+
120
+ for (const [key, entry] of this.cache.entries()) {
121
+ if (entry.expiresAt < now) {
122
+ this.cache.delete(key);
123
+ expired++;
124
+ }
125
+ }
126
+
127
+ if (expired > 0) {
128
+ logger.debug(`Cache CLEANUP: removed ${expired} expired entries`);
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Retorna estatísticas do cache
134
+ */
135
+ getStats() {
136
+ this.updateHitRate();
137
+
138
+ return {
139
+ size: this.cache.size,
140
+ hits: this.hits,
141
+ misses: this.misses,
142
+ totalRequests: this.hits + this.misses,
143
+ hitRate: this.stats.averageHitRate.toFixed(2) + '%',
144
+ ttl: this.ttl,
145
+ stats: {
146
+ ...this.stats,
147
+ hits: this.hits,
148
+ misses: this.misses
149
+ }
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Atualizar hit rate
155
+ */
156
+ updateHitRate() {
157
+ const total = this.hits + this.misses;
158
+ if (total > 0) {
159
+ this.stats.averageHitRate = (this.hits / total) * 100;
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Set TTL
165
+ */
166
+ setTTL(ttl) {
167
+ this.ttl = ttl;
168
+ logger.info(`Cache TTL updated to ${ttl}ms`);
169
+ }
170
+
171
+ /**
172
+ * Get TTL
173
+ */
174
+ getTTL() {
175
+ return this.ttl;
176
+ }
177
+
178
+ /**
179
+ * Destruir e parar cleanup
180
+ */
181
+ destroy() {
182
+ clearInterval(this.cleanupInterval);
183
+ this.cache.clear();
184
+ logger.debug('Cache destroyed');
185
+ }
186
+
187
+ /**
188
+ * Invalidar cache de um principal
189
+ * Útil quando uma role tem suas políticas atualizadas
190
+ */
191
+ invalidatePrincipal(principal) {
192
+ const pattern = `${principal}|*`;
193
+ return this.deletePattern(pattern);
194
+ }
195
+
196
+ /**
197
+ * Invalidar cache de uma ação
198
+ * Útil quando uma SCP afetando uma ação é modificada
199
+ */
200
+ invalidateAction(action) {
201
+ const pattern = `*|${action}|*`;
202
+ return this.deletePattern(pattern);
203
+ }
204
+
205
+ /**
206
+ * Invalidar cache de um recurso
207
+ * Útil quando permissões em um recurso mudam
208
+ */
209
+ invalidateResource(resource) {
210
+ const pattern = `*|*|${resource}`;
211
+ return this.deletePattern(pattern);
212
+ }
213
+ }
214
+
215
+ module.exports = PolicyCache;
package/aws-config DELETED
@@ -1,154 +0,0 @@
1
- // lambda/layer/utils/aws-config.js
2
- const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
3
- const { DynamoDBDocumentClient } = require('@aws-sdk/lib-dynamodb');
4
- const { S3Client } = require('@aws-sdk/client-s3');
5
- const { SQSClient } = require('@aws-sdk/client-sqs');
6
- const { LambdaClient } = require('@aws-sdk/client-lambda');
7
- const { CognitoIdentityProviderClient } = require("@aws-sdk/client-cognito-identity-provider");
8
-
9
- // Detecta ambiente local
10
- const isLocal = process.env.IS_LOCAL === 'true' ||
11
- process.env.NODE_ENV === 'development' ||
12
- process.env.AWS_SAM_LOCAL === 'true';
13
-
14
- const isLocalS3 = process.env.IS_LOCAL_S3 === 'true'
15
- const isLocalSQS = process.env.IS_LOCAL_SQS === 'true'
16
- const isLocalDynamoDB = process.env.IS_LOCAL_DYNAMODB === 'true'
17
- const isLocalLambda = process.env.IS_LOCAL_LAMBDA === 'true'
18
- const isLocalCognito = process.env.IS_LOCAL_COGNITO === 'true'
19
-
20
- // Endpoints locais (configuráveis via variáveis de ambiente)
21
- const localEndpoints = {
22
- dynamodb: process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
23
- s3: process.env.S3_ENDPOINT || 'http://localhost:4566',
24
- sqs: process.env.SQS_ENDPOINT || 'http://localhost:9324',
25
- lambda: process.env.LAMBDA_ENDPOINT || 'http://localhost:3001',
26
- cognito: process.env.LOCAL_COGNITO || 'http://localhost:9229'
27
- };
28
-
29
- // Credenciais para ambiente local (não são validadas)
30
- const localCredentials = {
31
- accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
32
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local',
33
- sessionToken: process.env.AWS_SESSION_TOKEN || undefined
34
- };
35
-
36
- // Configuração base para todos os clients
37
- const baseConfig = {
38
- region: process.env.AWS_REGION || 'us-east-1',
39
- credentials: isLocal ? localCredentials : undefined
40
- };
41
-
42
- // ============ DynamoDB Client ============
43
- const dynamoDBClient = new DynamoDBClient({
44
- ...baseConfig,
45
- endpoint: isLocalDynamoDB ? localEndpoints.dynamodb : undefined,
46
- region: process.env.AWS_REGION || "us-east-1"
47
- });
48
-
49
- const dynamoDBDocClient = DynamoDBDocumentClient.from(dynamoDBClient, {
50
- marshallOptions: {
51
- removeUndefinedValues: true,
52
- convertEmptyValues: false
53
- },
54
- unmarshallOptions: {
55
- wrapNumbers: false
56
- }
57
- });
58
-
59
- const cognitoClient = new CognitoIdentityProviderClient({
60
- ...baseConfig,
61
- endpoint: isLocalCognito ? localEndpoints.cognito : undefined,
62
- region: process.env.AWS_REGION || 'us-east-1'
63
- });
64
-
65
- // ============ S3 Client ============
66
- const s3Client = new S3Client({
67
- ...baseConfig,
68
- endpoint: isLocalS3 ? localEndpoints.s3 : undefined,
69
- forcePathStyle: true, // Necessário para S3 local (LocalStack, MinIO, etc)
70
- // Para S3 real, não usar forcePathStyle
71
- ...(isLocalS3 ? {} : { forcePathStyle: false })
72
- });
73
-
74
- // ============ SQS Client ============
75
- const sqsClient = new SQSClient({
76
- ...baseConfig,
77
- endpoint: isLocalSQS ? localEndpoints.sqs : undefined
78
- });
79
-
80
- // ============ Lambda Client ============
81
- const lambdaClient = new LambdaClient({
82
- ...baseConfig,
83
- endpoint: isLocalLambda ? localEndpoints.lambda : undefined
84
- });
85
-
86
- // Log de configuração (apenas em desenvolvimento)
87
- if (isLocalDynamoDB || isLocalS3 || isLocalSQS || isLocalLambda) {
88
- console.log('🔧 Ambiente LOCAL detectado:');
89
- console.log(` DynamoDB: ${localEndpoints.dynamodb}`);
90
- console.log(` S3: ${localEndpoints.s3} (forcePathStyle: true)`);
91
- console.log(` SQS: ${localEndpoints.sqs}`);
92
- console.log(` Lambda: ${localEndpoints.lambda}`);
93
- console.log(` Region: ${baseConfig.region}`);
94
- }
95
- if (isLocalDynamoDB || isLocalS3 || isLocalSQS || isLocalLambda) {
96
- console.log('🔧 Ambiente LOCAL detectado:');
97
- console.log(` Region: ${baseConfig.region}`);
98
- }
99
-
100
- if (isLocalDynamoDB) {
101
- console.log(` DynamoDB: ${localEndpoints.dynamodb}`);
102
- }
103
- if (isLocalS3) {
104
- console.log(` S3: ${localEndpoints.s3} (forcePathStyle: true)`);
105
- }
106
-
107
- if (isLocalSQS) {
108
- console.log(` SQS: ${localEndpoints.sqs}`);
109
- }
110
-
111
- if (isLocalLambda) {
112
- console.log(` Lambda: ${localEndpoints.lambda}`);
113
- }
114
-
115
- if (isLocalCognito){
116
- console.log(` Cognito: ${localEndpoints.cognito}`);
117
- }
118
-
119
- module.exports = {
120
- // Clients
121
- dynamoDB: dynamoDBDocClient,
122
- cognitoClient,
123
- dynamoDBClient,
124
- s3: s3Client,
125
- sqs: sqsClient,
126
- lambda: lambdaClient,
127
-
128
- // Utilitários
129
- isLocal,
130
- localEndpoints,
131
-
132
- // Configuração
133
- config: {
134
- region: baseConfig.region,
135
- isLocal,
136
- endpoints: localEndpoints
137
- },
138
-
139
- // Função para criar clients customizados (útil para testes)
140
- createS3Client: (customEndpoint) => {
141
- return new S3Client({
142
- ...baseConfig,
143
- endpoint: customEndpoint || localEndpoints.s3,
144
- forcePathStyle: true
145
- });
146
- },
147
-
148
- createDynamoDBClient: (customEndpoint) => {
149
- return new DynamoDBClient({
150
- ...baseConfig,
151
- endpoint: customEndpoint || localEndpoints.dynamodb
152
- });
153
- }
154
- };