@gugananuvem/aws-local-simulator 1.0.9 → 1.0.11

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 +204 -192
  2. package/bin/aws-local-simulator.js +62 -62
  3. package/package.json +2 -2
  4. package/src/config/config-loader.js +112 -112
  5. package/src/config/default-config.js +65 -65
  6. package/src/config/env-loader.js +68 -66
  7. package/src/index.js +130 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +221 -219
  10. package/src/services/apigateway/index.js +66 -66
  11. package/src/services/apigateway/server.js +434 -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 +228 -228
  15. package/src/services/cognito/simulator.js +847 -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 +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 +84 -84
  23. package/src/services/index.js +18 -18
  24. package/src/services/lambda/handler-loader.js +172 -172
  25. package/src/services/lambda/index.js +72 -72
  26. package/src/services/lambda/route-registry.js +274 -274
  27. package/src/services/lambda/server.js +152 -152
  28. package/src/services/lambda/simulator.js +284 -277
  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 +273 -273
  35. package/src/services/sqs/simulator.js +659 -659
  36. package/src/template/aws-config-template.js +87 -87
  37. package/src/template/aws-config-template.mjs +90 -90
  38. package/src/template/config-template.json +203 -165
  39. package/src/utils/aws-config.js +91 -91
  40. package/src/utils/local-store.js +67 -67
  41. package/src/utils/logger.js +59 -59
@@ -1,165 +1,203 @@
1
- {
2
- "services": {
3
- "dynamodb": true,
4
- "s3": true,
5
- "sqs": true,
6
- "lambda": true,
7
- "sns": false,
8
- "eventbridge": false,
9
- "apigateway": true
10
- },
11
- "ports": {
12
- "dynamodb": 8000,
13
- "s3": 4566,
14
- "sqs": 9324,
15
- "lambda": 3001,
16
- "sns": 9911,
17
- "eventbridge": 4010
18
- },
19
- "lambdas": [
20
- {
21
- "path": "/api/users",
22
- "handler": "./src/handlers/users.js",
23
- "type": "commonjs",
24
- "env": {
25
- "TABLE_NAME": "users-table",
26
- "BUCKET_NAME": "user-files"
27
- }
28
- },
29
- {
30
- "path": "/api/products",
31
- "handler": "./src/handlers/products.mjs",
32
- "type": "module",
33
- "env": {
34
- "TABLE_NAME": "products-table"
35
- }
36
- }
37
- ],
38
- "dynamodb": {
39
- "tables": [
40
- {
41
- "TableName": "users-table",
42
- "KeySchema": [
43
- { "AttributeName": "userId", "KeyType": "HASH" }
44
- ],
45
- "AttributeDefinitions": [
46
- { "AttributeName": "userId", "AttributeType": "S" }
47
- ],
48
- "ProvisionedThroughput": {
49
- "ReadCapacityUnits": 5,
50
- "WriteCapacityUnits": 5
51
- }
52
- }
53
- ]
54
- },
55
- "s3": {
56
- "buckets": ["users-files", "public-assets"]
57
- },
58
- "sqs": {
59
- "queues": [
60
- {
61
- "name": "notifications-queue",
62
- "lambdaPath": "/api/notifications",
63
- "batchSize": 10
64
- }
65
- ]
66
- },
67
- "apigateway": {
68
- "defaultCors": {
69
- "allowOrigins": ["http://localhost:3000"],
70
- "allowMethods": ["GET", "POST", "PUT", "DELETE"],
71
- "allowHeaders": ["Content-Type", "Authorization"],
72
- "maxAge": 300
73
- },
74
- "defaultThrottling": {
75
- "burstLimit": 50,
76
- "rateLimit": 10
77
- },
78
- "enableAccessLogging": true
79
- },
80
- "restApis": [
81
- {
82
- "name": "MyAPI",
83
- "description": "My REST API",
84
- "resources": [
85
- {
86
- "path": "/users",
87
- "methods": [
88
- {
89
- "httpMethod": "GET",
90
- "authorizationType": "NONE",
91
- "integration": {
92
- "type": "HTTP",
93
- "uri": "http://localhost:3001/users",
94
- "httpMethod": "GET"
95
- }
96
- },
97
- {
98
- "httpMethod": "POST",
99
- "authorizationType": "NONE",
100
- "integration": {
101
- "type": "AWS",
102
- "uri": "arn:aws:lambda:local:function:createUser"
103
- }
104
- }
105
- ]
106
- },
107
- {
108
- "path": "/users/{userId}",
109
- "methods": [
110
- {
111
- "httpMethod": "GET",
112
- "authorizationType": "NONE",
113
- "integration": {
114
- "type": "HTTP",
115
- "uri": "http://localhost:3001/users/{userId}",
116
- "httpMethod": "GET"
117
- }
118
- }
119
- ]
120
- }
121
- ],
122
- "stages": [
123
- {
124
- "stageName": "dev",
125
- "variables": {
126
- "ENVIRONMENT": "development"
127
- }
128
- },
129
- {
130
- "stageName": "prod",
131
- "variables": {
132
- "ENVIRONMENT": "production"
133
- }
134
- }
135
- ]
136
- }
137
- ],
138
- "apiKeys": [
139
- {
140
- "name": "MyAPIKey",
141
- "description": "Key for MyAPI",
142
- "enabled": true
143
- }
144
- ],
145
- "usagePlans": [
146
- {
147
- "name": "BasicPlan",
148
- "description": "Basic usage plan",
149
- "throttle": {
150
- "burstLimit": 100,
151
- "rateLimit": 10
152
- },
153
- "quota": {
154
- "limit": 10000,
155
- "period": "DAY"
156
- },
157
- "apiStages": [
158
- {
159
- "apiId": "api_123",
160
- "stage": "dev"
161
- }
162
- ]
163
- }
164
- ]
165
- }
1
+ {
2
+ "services": {
3
+ "dynamodb": true,
4
+ "s3": true,
5
+ "sqs": true,
6
+ "lambda": true,
7
+ "sns": false,
8
+ "eventbridge": false,
9
+ "apigateway": true,
10
+ "ecs": false
11
+ },
12
+ "ports": {
13
+ "dynamodb": 8000,
14
+ "s3": 4566,
15
+ "sqs": 9324,
16
+ "lambda": 3001,
17
+ "sns": 9911,
18
+ "eventbridge": 4010
19
+ },
20
+ "lambdas": [
21
+ {
22
+ "path": "/api/users",
23
+ "handler": "./src/handlers/users.js",
24
+ "type": "commonjs",
25
+ "env": {
26
+ "TABLE_NAME": "users-table",
27
+ "BUCKET_NAME": "user-files"
28
+ }
29
+ },
30
+ {
31
+ "path": "/api/products",
32
+ "handler": "./src/handlers/products.mjs",
33
+ "type": "module",
34
+ "env": {
35
+ "TABLE_NAME": "products-table"
36
+ }
37
+ }
38
+ ],
39
+ "dynamodb": {
40
+ "tables": [
41
+ {
42
+ "TableName": "users-table",
43
+ "KeySchema": [{ "AttributeName": "userId", "KeyType": "HASH" }],
44
+ "AttributeDefinitions": [{ "AttributeName": "userId", "AttributeType": "S" }],
45
+ "ProvisionedThroughput": {
46
+ "ReadCapacityUnits": 5,
47
+ "WriteCapacityUnits": 5
48
+ }
49
+ }
50
+ ]
51
+ },
52
+ "s3": {
53
+ "buckets": ["users-files", "public-assets"]
54
+ },
55
+ "sqs": {
56
+ "queues": [
57
+ {
58
+ "name": "notifications-queue",
59
+ "lambdaPath": "/api/notifications",
60
+ "batchSize": 10
61
+ }
62
+ ]
63
+ },
64
+ "apigateway": {
65
+ "defaultCors": {
66
+ "allowOrigins": ["http://localhost:3000"],
67
+ "allowMethods": ["GET", "POST", "PUT", "DELETE"],
68
+ "allowHeaders": ["Content-Type", "Authorization"],
69
+ "maxAge": 300
70
+ },
71
+ "defaultThrottling": {
72
+ "burstLimit": 50,
73
+ "rateLimit": 10
74
+ },
75
+ "enableAccessLogging": true
76
+ },
77
+ "restApis": [
78
+ {
79
+ "name": "MyAPI",
80
+ "description": "My REST API",
81
+ "resources": [
82
+ {
83
+ "path": "/users",
84
+ "methods": [
85
+ {
86
+ "httpMethod": "GET",
87
+ "authorizationType": "NONE",
88
+ "integration": {
89
+ "type": "HTTP",
90
+ "uri": "http://localhost:3001/users",
91
+ "httpMethod": "GET"
92
+ }
93
+ },
94
+ {
95
+ "httpMethod": "POST",
96
+ "authorizationType": "NONE",
97
+ "integration": {
98
+ "type": "AWS",
99
+ "uri": "arn:aws:lambda:local:function:createUser"
100
+ }
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "path": "/users/{userId}",
106
+ "methods": [
107
+ {
108
+ "httpMethod": "GET",
109
+ "authorizationType": "NONE",
110
+ "integration": {
111
+ "type": "HTTP",
112
+ "uri": "http://localhost:3001/users/{userId}",
113
+ "httpMethod": "GET"
114
+ }
115
+ }
116
+ ]
117
+ }
118
+ ],
119
+ "stages": [
120
+ {
121
+ "stageName": "dev",
122
+ "variables": {
123
+ "ENVIRONMENT": "development"
124
+ }
125
+ },
126
+ {
127
+ "stageName": "prod",
128
+ "variables": {
129
+ "ENVIRONMENT": "production"
130
+ }
131
+ }
132
+ ]
133
+ }
134
+ ],
135
+ "apiKeys": [
136
+ {
137
+ "name": "MyAPIKey",
138
+ "description": "Key for MyAPI",
139
+ "enabled": true
140
+ }
141
+ ],
142
+ "usagePlans": [
143
+ {
144
+ "name": "BasicPlan",
145
+ "description": "Basic usage plan",
146
+ "throttle": {
147
+ "burstLimit": 100,
148
+ "rateLimit": 10
149
+ },
150
+ "quota": {
151
+ "limit": 10000,
152
+ "period": "DAY"
153
+ },
154
+ "apiStages": [
155
+ {
156
+ "apiId": "api_123",
157
+ "stage": "dev"
158
+ }
159
+ ]
160
+ }
161
+ ],
162
+ "ecs": {
163
+ "clusters": ["production", "staging", "development"],
164
+ "defaultTaskCpu": 512,
165
+ "defaultTaskMemory": 1024,
166
+ "containerRuntime": "simulate"
167
+ },
168
+ "taskDefinitions": [
169
+ {
170
+ "family": "my-app",
171
+ "containerDefinitions": [
172
+ {
173
+ "name": "web",
174
+ "image": "nginx:alpine",
175
+ "cpu": 256,
176
+ "memory": 512,
177
+ "essential": true,
178
+ "portMappings": [
179
+ {
180
+ "containerPort": 80,
181
+ "hostPort": 0,
182
+ "protocol": "tcp"
183
+ }
184
+ ],
185
+ "environment": [{ "name": "ENVIRONMENT", "value": "local" }]
186
+ }
187
+ ],
188
+ "networkMode": "awsvpc",
189
+ "cpu": "512",
190
+ "memory": "1024"
191
+ }
192
+ ],
193
+ "services-ecs": [
194
+ {
195
+ "name": "my-web-service",
196
+ "cluster": "development",
197
+ "taskDefinition": "my-app",
198
+ "desiredCount": 2,
199
+ "schedulingStrategy": "REPLICA"
200
+ }
201
+ ]
202
+
203
+ }
@@ -1,92 +1,92 @@
1
- // src/utils/aws-config.js
2
-
3
- /**
4
- * Cria configuração para AWS SDK baseada no ambiente
5
- */
6
- function createAWSConfig(options = {}) {
7
- const isLocal = process.env.NODE_ENV === 'development' || process.env.IS_LOCAL === 'true';
8
-
9
- const config = {
10
- region: options.region || process.env.AWS_REGION || 'us-east-1',
11
- credentials: options.credentials || {
12
- accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
13
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local'
14
- }
15
- };
16
-
17
- if (isLocal || options.forceLocal) {
18
- config.endpoints = {
19
- dynamoDB: options.dynamoDBEndpoint || process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
20
- s3: options.s3Endpoint || process.env.S3_ENDPOINT || 'http://localhost:4566',
21
- sqs: options.sqsEndpoint || process.env.SQS_ENDPOINT || 'http://localhost:9324',
22
- lambda: options.lambdaEndpoint || process.env.LAMBDA_ENDPOINT || 'http://localhost:3001'
23
- };
24
- }
25
-
26
- return config;
27
- }
28
-
29
- /**
30
- * Cria cliente DynamoDB configurado
31
- */
32
- function createDynamoDBClient(options = {}) {
33
- const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
34
- const config = createAWSConfig(options);
35
-
36
- const clientConfig = {
37
- region: config.region,
38
- credentials: config.credentials
39
- };
40
-
41
- if (config.endpoints?.dynamoDB) {
42
- clientConfig.endpoint = config.endpoints.dynamoDB;
43
- }
44
-
45
- return new DynamoDBClient(clientConfig);
46
- }
47
-
48
- /**
49
- * Cria cliente S3 configurado
50
- */
51
- function createS3Client(options = {}) {
52
- const { S3Client } = require('@aws-sdk/client-s3');
53
- const config = createAWSConfig(options);
54
-
55
- const clientConfig = {
56
- region: config.region,
57
- credentials: config.credentials
58
- };
59
-
60
- if (config.endpoints?.s3) {
61
- clientConfig.endpoint = config.endpoints.s3;
62
- clientConfig.forcePathStyle = true; // Necessário para S3 local
63
- }
64
-
65
- return new S3Client(clientConfig);
66
- }
67
-
68
- /**
69
- * Cria cliente SQS configurado
70
- */
71
- function createSQSClient(options = {}) {
72
- const { SQSClient } = require('@aws-sdk/client-sqs');
73
- const config = createAWSConfig(options);
74
-
75
- const clientConfig = {
76
- region: config.region,
77
- credentials: config.credentials
78
- };
79
-
80
- if (config.endpoints?.sqs) {
81
- clientConfig.endpoint = config.endpoints.sqs;
82
- }
83
-
84
- return new SQSClient(clientConfig);
85
- }
86
-
87
- module.exports = {
88
- createAWSConfig,
89
- createDynamoDBClient,
90
- createS3Client,
91
- createSQSClient
1
+ // src/utils/aws-config.js
2
+
3
+ /**
4
+ * Cria configuração para AWS SDK baseada no ambiente
5
+ */
6
+ function createAWSConfig(options = {}) {
7
+ const isLocal = process.env.NODE_ENV === 'development' || process.env.IS_LOCAL === 'true';
8
+
9
+ const config = {
10
+ region: options.region || process.env.AWS_REGION || 'us-east-1',
11
+ credentials: options.credentials || {
12
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
13
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local'
14
+ }
15
+ };
16
+
17
+ if (isLocal || options.forceLocal) {
18
+ config.endpoints = {
19
+ dynamoDB: options.dynamoDBEndpoint || process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
20
+ s3: options.s3Endpoint || process.env.S3_ENDPOINT || 'http://localhost:4566',
21
+ sqs: options.sqsEndpoint || process.env.SQS_ENDPOINT || 'http://localhost:9324',
22
+ lambda: options.lambdaEndpoint || process.env.LAMBDA_ENDPOINT || 'http://localhost:3001'
23
+ };
24
+ }
25
+
26
+ return config;
27
+ }
28
+
29
+ /**
30
+ * Cria cliente DynamoDB configurado
31
+ */
32
+ function createDynamoDBClient(options = {}) {
33
+ const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
34
+ const config = createAWSConfig(options);
35
+
36
+ const clientConfig = {
37
+ region: config.region,
38
+ credentials: config.credentials
39
+ };
40
+
41
+ if (config.endpoints?.dynamoDB) {
42
+ clientConfig.endpoint = config.endpoints.dynamoDB;
43
+ }
44
+
45
+ return new DynamoDBClient(clientConfig);
46
+ }
47
+
48
+ /**
49
+ * Cria cliente S3 configurado
50
+ */
51
+ function createS3Client(options = {}) {
52
+ const { S3Client } = require('@aws-sdk/client-s3');
53
+ const config = createAWSConfig(options);
54
+
55
+ const clientConfig = {
56
+ region: config.region,
57
+ credentials: config.credentials
58
+ };
59
+
60
+ if (config.endpoints?.s3) {
61
+ clientConfig.endpoint = config.endpoints.s3;
62
+ clientConfig.forcePathStyle = true; // Necessário para S3 local
63
+ }
64
+
65
+ return new S3Client(clientConfig);
66
+ }
67
+
68
+ /**
69
+ * Cria cliente SQS configurado
70
+ */
71
+ function createSQSClient(options = {}) {
72
+ const { SQSClient } = require('@aws-sdk/client-sqs');
73
+ const config = createAWSConfig(options);
74
+
75
+ const clientConfig = {
76
+ region: config.region,
77
+ credentials: config.credentials
78
+ };
79
+
80
+ if (config.endpoints?.sqs) {
81
+ clientConfig.endpoint = config.endpoints.sqs;
82
+ }
83
+
84
+ return new SQSClient(clientConfig);
85
+ }
86
+
87
+ module.exports = {
88
+ createAWSConfig,
89
+ createDynamoDBClient,
90
+ createS3Client,
91
+ createSQSClient
92
92
  };