@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,99 @@
1
+ /**
2
+ * CloudFront Models Index
3
+ */
4
+
5
+ const Distribution = require('./distribution');
6
+ const Origin = require('./origin');
7
+ const Behavior = require('./behavior');
8
+ const Invalidation = require('./invalidation');
9
+
10
+ /**
11
+ * Validate a distribution configuration
12
+ * @param {object} config - Configuration to validate
13
+ * @returns {object} Validation result
14
+ */
15
+ function validate(config) {
16
+ const errors = [];
17
+ const warnings = [];
18
+
19
+ // Check required fields
20
+ if (!config.Origins || !Array.isArray(config.Origins) || config.Origins.length === 0) {
21
+ errors.push('Configuration must have at least one origin');
22
+ }
23
+
24
+ if (!config.DefaultCacheBehavior) {
25
+ errors.push('Configuration must have DefaultCacheBehavior');
26
+ }
27
+
28
+ if (!config.CallerReference) {
29
+ errors.push('Configuration must have CallerReference');
30
+ }
31
+
32
+ // Check behavior configuration
33
+ if (config.DefaultCacheBehavior) {
34
+ const behavior = config.DefaultCacheBehavior;
35
+
36
+ if (!behavior.TargetOriginId) {
37
+ errors.push('DefaultCacheBehavior must have TargetOriginId');
38
+ }
39
+
40
+ if (!behavior.ViewerProtocolPolicy) {
41
+ errors.push('DefaultCacheBehavior must have ViewerProtocolPolicy');
42
+ }
43
+
44
+ const validPolicies = ['allow-all', 'https-only', 'redirect-to-https'];
45
+ if (behavior.ViewerProtocolPolicy && !validPolicies.includes(behavior.ViewerProtocolPolicy)) {
46
+ errors.push(
47
+ `Invalid ViewerProtocolPolicy: ${behavior.ViewerProtocolPolicy}`
48
+ );
49
+ }
50
+ }
51
+
52
+ // Check cache behaviors if present
53
+ if (config.CacheBehaviors && Array.isArray(config.CacheBehaviors)) {
54
+ for (let i = 0; i < config.CacheBehaviors.length; i++) {
55
+ const behavior = config.CacheBehaviors[i];
56
+
57
+ if (!behavior.PathPattern) {
58
+ errors.push(`CacheBehavior ${i} must have PathPattern`);
59
+ }
60
+
61
+ if (!behavior.TargetOriginId) {
62
+ errors.push(`CacheBehavior ${i} must have TargetOriginId`);
63
+ }
64
+ }
65
+ }
66
+
67
+ // Check geo-restrictions if present
68
+ if (config.GeoRestriction) {
69
+ const validTypes = ['none', 'whitelist', 'blacklist'];
70
+ if (!validTypes.includes(config.GeoRestriction.RestrictionType)) {
71
+ errors.push(
72
+ `Invalid GeoRestriction type: ${config.GeoRestriction.RestrictionType}`
73
+ );
74
+ }
75
+ }
76
+
77
+ // Warnings for best practices
78
+ if (!config.Comment) {
79
+ warnings.push('It is recommended to provide a comment for the distribution');
80
+ }
81
+
82
+ if (config.Logging?.Enabled && !config.Logging?.Bucket) {
83
+ errors.push('Logging is enabled but no bucket is specified');
84
+ }
85
+
86
+ return {
87
+ isValid: errors.length === 0,
88
+ errors: errors,
89
+ warnings: warnings
90
+ };
91
+ }
92
+
93
+ module.exports = {
94
+ Distribution,
95
+ Origin,
96
+ Behavior,
97
+ Invalidation,
98
+ validate
99
+ };
@@ -0,0 +1,109 @@
1
+ /**
2
+ * CloudFront Invalidation Model
3
+ * Gerencia invalidação de cache
4
+ */
5
+
6
+ const crypto = require('crypto');
7
+
8
+ class Invalidation {
9
+ constructor(params = {}) {
10
+ this.Id = params.Id || this.generateId();
11
+ this.DistributionId = params.DistributionId;
12
+ this.CreateTime = new Date();
13
+ this.Status = params.Status || 'InProgress';
14
+ this.CallerReference = params.CallerReference || crypto.randomUUID();
15
+
16
+ // Paths to invalidate
17
+ this.Paths = params.Paths || {
18
+ Quantity: 0,
19
+ Items: []
20
+ };
21
+
22
+ // Progress (0-100)
23
+ this.Progress = params.Progress !== undefined ? params.Progress : 0;
24
+
25
+ // Estimated completion time (após 5 minutos é normalmente completo)
26
+ this.EstimatedCompletionTime = new Date(Date.now() + 5 * 60 * 1000);
27
+ }
28
+
29
+ generateId() {
30
+ return crypto.randomBytes(16).toString('hex').toUpperCase();
31
+ }
32
+
33
+ /**
34
+ * Marcar como concluída
35
+ */
36
+ complete() {
37
+ this.Status = 'Completed';
38
+ this.Progress = 100;
39
+ }
40
+
41
+ /**
42
+ * Verificar se path deve ser invalidado
43
+ */
44
+ shouldInvalidate(path) {
45
+ if (!this.Paths?.Items) {
46
+ return false;
47
+ }
48
+
49
+ for (const invalidationPath of this.Paths.Items) {
50
+ if (this.pathMatches(path, invalidationPath)) {
51
+ return true;
52
+ }
53
+ }
54
+
55
+ return false;
56
+ }
57
+
58
+ /**
59
+ * Verificar se path corresponde ao padrão de invalidação
60
+ * Suporta wildcards: *.jpg, /api/*, etc
61
+ */
62
+ pathMatches(path, pattern) {
63
+ if (pattern === '*') {
64
+ return true;
65
+ }
66
+
67
+ // Converter glob pattern para regex
68
+ const regex = new RegExp(
69
+ '^' + pattern
70
+ .replace(/\./g, '\\.')
71
+ .replace(/\*/g, '.*')
72
+ .replace(/\?/g, '.') +
73
+ '$'
74
+ );
75
+
76
+ return regex.test(path);
77
+ }
78
+
79
+ /**
80
+ * Retornar invalidação em formato AWS
81
+ */
82
+ toAWSFormat() {
83
+ return {
84
+ Id: this.Id,
85
+ DistributionId: this.DistributionId,
86
+ CreateTime: this.CreateTime,
87
+ Status: this.Status,
88
+ Paths: this.Paths,
89
+ InvalidationBatch: {
90
+ Paths: this.Paths,
91
+ CallerReference: this.CallerReference
92
+ },
93
+ Progress: this.Progress
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Obter invalidation em formato para resposta
99
+ */
100
+ getSummary() {
101
+ return {
102
+ Id: this.Id,
103
+ CreateTime: this.CreateTime,
104
+ Status: this.Status
105
+ };
106
+ }
107
+ }
108
+
109
+ module.exports = Invalidation;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * CloudFront Origin Model
3
+ * Suporta S3, HTTP, e Lambda@Edge origins
4
+ */
5
+
6
+ class Origin {
7
+ constructor(params = {}) {
8
+ this.Id = params.Id || 'default-origin';
9
+ this.DomainName = params.DomainName || 'example.com';
10
+ this.OriginPath = params.OriginPath || '';
11
+ this.CustomHeaders = params.CustomHeaders || {
12
+ Quantity: 0,
13
+ Items: []
14
+ };
15
+
16
+ // Tipo de origem
17
+ this.OriginType = this.detectOriginType(params.DomainName);
18
+
19
+ // S3 Origin
20
+ if (this.OriginType === 's3') {
21
+ this.S3OriginConfig = params.S3OriginConfig || {
22
+ OriginAccessIdentity: ''
23
+ };
24
+ }
25
+
26
+ // HTTP/HTTPS Origin
27
+ if (this.OriginType === 'http' || this.OriginType === 'lambda') {
28
+ this.CustomOriginConfig = params.CustomOriginConfig || {
29
+ HTTPPort: 80,
30
+ HTTPSPort: 443,
31
+ OriginProtocolPolicy: 'https-only',
32
+ OriginSslProtocols: {
33
+ Quantity: 3,
34
+ Items: ['TLSv1', 'TLSv1.1', 'TLSv1.2']
35
+ },
36
+ OriginReadTimeout: 30,
37
+ OriginKeepaliveTimeout: 5
38
+ };
39
+ }
40
+
41
+ // Origin Shield
42
+ this.OriginShield = params.OriginShield || {
43
+ Enabled: false,
44
+ OriginShieldRegion: null
45
+ };
46
+
47
+ // Origin Groups (para failover)
48
+ this.OriginGroupId = params.OriginGroupId || null;
49
+
50
+ // Lambda@Edge
51
+ this.LambdaFunctionAssociations = params.LambdaFunctionAssociations || {
52
+ Quantity: 0,
53
+ Items: []
54
+ };
55
+
56
+ // Origin Access Control
57
+ this.OriginAccessControlId = params.OriginAccessControlId || null;
58
+
59
+ // Connection settings
60
+ this.ConnectionAttempts = params.ConnectionAttempts || 3;
61
+ this.ConnectionTimeout = params.ConnectionTimeout || 10;
62
+ }
63
+
64
+ /**
65
+ Detectar tipo de origem
66
+ */
67
+ detectOriginType(domainName) {
68
+ if (!domainName) return 'http';
69
+
70
+ if (domainName.includes('.s3') || domainName.includes('s3.amazonaws.com')) {
71
+ return 's3';
72
+ }
73
+
74
+ if (domainName.includes('.lambda.') || domainName.includes('lambda-url')) {
75
+ return 'lambda';
76
+ }
77
+
78
+ return 'http';
79
+ }
80
+
81
+ /**
82
+ * Validar origem
83
+ */
84
+ validate() {
85
+ const errors = [];
86
+
87
+ if (!this.Id) {
88
+ errors.push('Origin Id is required');
89
+ }
90
+
91
+ if (!this.DomainName) {
92
+ errors.push('Origin DomainName is required');
93
+ }
94
+
95
+ return {
96
+ valid: errors.length === 0,
97
+ errors
98
+ };
99
+ }
100
+
101
+ /**
102
+ * Retornar origem em formato AWS
103
+ */
104
+ toAWSFormat() {
105
+ const origin = {
106
+ Id: this.Id,
107
+ DomainName: this.DomainName,
108
+ OriginPath: this.OriginPath,
109
+ CustomHeaders: this.CustomHeaders,
110
+ ConnectionAttempts: this.ConnectionAttempts,
111
+ ConnectionTimeout: this.ConnectionTimeout
112
+ };
113
+
114
+ if (this.OriginType === 's3') {
115
+ origin.S3OriginConfig = this.S3OriginConfig;
116
+ } else {
117
+ origin.CustomOriginConfig = this.CustomOriginConfig;
118
+ }
119
+
120
+ if (this.OriginShield?.Enabled) {
121
+ origin.OriginShield = this.OriginShield;
122
+ }
123
+
124
+ if (this.LambdaFunctionAssociations?.Quantity > 0) {
125
+ origin.LambdaFunctionAssociations = this.LambdaFunctionAssociations;
126
+ }
127
+
128
+ if (this.OriginAccessControlId) {
129
+ origin.OriginAccessControlId = this.OriginAccessControlId;
130
+ }
131
+
132
+ return origin;
133
+ }
134
+
135
+ /**
136
+ * Obter URL completa do origin
137
+ */
138
+ getOriginUrl(path = '/') {
139
+ const protocol = this.OriginType === 's3' || this.CustomOriginConfig?.OriginProtocolPolicy === 'https-only'
140
+ ? 'https'
141
+ : 'http';
142
+
143
+ const port = protocol === 'https'
144
+ ? (this.CustomOriginConfig?.HTTPSPort || 443)
145
+ : (this.CustomOriginConfig?.HTTPPort || 80);
146
+
147
+ const portString = (protocol === 'https' && port === 443) || (protocol === 'http' && port === 80)
148
+ ? ''
149
+ : `:${port}`;
150
+
151
+ return `${protocol}://${this.DomainName}${portString}${this.OriginPath}${path}`;
152
+ }
153
+ }
154
+
155
+ module.exports = Origin;