-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaking.html
More file actions
470 lines (432 loc) · 19.2 KB
/
faking.html
File metadata and controls
470 lines (432 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5C3LL34WWW"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5C3LL34WWW');
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Faking Services - Local Web Services</title>
<meta name="description" content="Fake AWS service operations and external API dependencies. Override AWS responses at the operation level, or create fake HTTP/GraphQL/gRPC servers for third-party APIs.">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css">
</head>
<body>
<nav class="nav">
<div class="container nav-inner">
<a href="index.html" class="nav-logo">Local Web Services</a>
<ul class="nav-links">
<li><a href="getting-started.html">Get Started</a></li>
<li><a href="sdks.html">SDKs</a></li>
<li><a href="services.html">Cloud Emulation</a></li>
<li><a href="faking.html" class="nav-active">Faking Services</a></li>
<li><a href="chaos.html">Chaos Engineering</a></li>
<li><a href="cli.html">CLI</a></li>
<li><a href="https://github.com/local-web-services/local-web-services" class="nav-github">GitHub</a></li>
</ul>
</div>
</nav>
<header class="page-header">
<div class="container">
<h1>Faking Services</h1>
<p class="section-lead">Override AWS service responses at the operation level, or create fake servers for external API dependencies. Control exactly what your application sees — without changing your code.</p>
</div>
</header>
<!-- ============================================ -->
<!-- AWS SERVICE FAKING -->
<!-- ============================================ -->
<section class="section section-alt">
<div class="container">
<h2>AWS Service Faking</h2>
<p class="section-lead">Override individual AWS API operations with custom responses. Faked operations bypass the real emulation entirely — your code gets back exactly what you define.</p>
<div class="feature-grid" style="grid-template-columns: 1fr 1fr; max-width: 900px; margin: 0 auto;">
<div class="feature-card">
<div class="feature-icon">⚙</div>
<h3>Operation-Level Control</h3>
<p>Fake specific operations like <code>GetItem</code> or <code>ReceiveMessage</code> while leaving the rest of the service running normally.</p>
</div>
<div class="feature-card">
<div class="feature-icon">⚡</div>
<h3>Service-Aware Helpers</h3>
<p>Built-in helpers auto-format responses for each service — DynamoDB JSON, S3 XML, SQS message structures — so you don't have to.</p>
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h3 class="section-subheading section-subheading--large" style="margin-top: 0;">How AWS Faking Works</h3>
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<h3>Create a Fake</h3>
<p>Create a named fake targeting a specific AWS service.</p>
<div class="code-block"><code>uvx --from local-web-services lws aws-fake create my-s3-fake --service s3</code></div>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<h3>Add Operation Rules</h3>
<p>Define what specific operations should return. Use service-aware helpers for correctly formatted responses.</p>
<div class="code-block"><code># Fake a DynamoDB GetItem with a helper
uvx --from local-web-services lws aws-fake add-operation my-ddb-fake \
--operation get-item \
--item '{"id": "123", "name": "test"}'
# Fake an S3 GetObject with string content
uvx --from local-web-services lws aws-fake add-operation my-s3-fake \
--operation get-object \
--body-string "Hello from S3"
# Fake with a raw response
uvx --from local-web-services lws aws-fake add-operation my-fake \
--operation list-objects-v2 \
--status 200 \
--body-file /path/to/response.xml</code></div>
</div>
</div>
<div class="step">
<div class="step-number">3</div>
<div class="step-content">
<h3>Requests Are Intercepted</h3>
<p>When your code calls a faked operation, the fake middleware intercepts the request before it reaches the real provider and returns your custom response.</p>
</div>
</div>
</div>
<h3 class="section-subheading">Supported Services</h3>
<div class="service-index">
<span class="op">DynamoDB</span>
<span class="op">SQS</span>
<span class="op">S3</span>
<span class="op">SNS</span>
<span class="op">EventBridge</span>
<span class="op">Step Functions</span>
<span class="op">Cognito</span>
<span class="op">SSM</span>
<span class="op">Secrets Manager</span>
<span class="op">IAM</span>
</div>
<h3 class="section-subheading">Service-Aware Helpers</h3>
<p class="section-lead">Helpers automatically format responses in the correct service-specific format.</p>
<div class="services-list">
<div class="service-detail">
<div class="service-detail-header">
<h3>DynamoDB</h3>
</div>
<div class="service-detail-section">
<h4>Helper Options</h4>
<div class="service-detail-ops">
<span class="op">--item</span>
<span class="op">get-item</span>
<span class="op">query</span>
<span class="op">scan</span>
</div>
</div>
<p class="service-note">Converts simple JSON to DynamoDB JSON format with type descriptors automatically. <code>--item '{"id": "123", "age": 30}'</code> becomes <code>{"id": {"S": "123"}, "age": {"N": "30"}}</code>.</p>
</div>
<div class="service-detail">
<div class="service-detail-header">
<h3>S3</h3>
</div>
<div class="service-detail-section">
<h4>Helper Options</h4>
<div class="service-detail-ops">
<span class="op">--body-string</span>
<span class="op">--body-file</span>
<span class="op">get-object</span>
<span class="op">list-objects-v2</span>
<span class="op">head-object</span>
</div>
</div>
<p class="service-note">Returns file content with proper headers (Content-Type, Content-Length, ETag). List operations generate correct S3 XML listings.</p>
</div>
<div class="service-detail">
<div class="service-detail-header">
<h3>SQS, SSM, Secrets Manager, Cognito, SNS, Step Functions, EventBridge</h3>
</div>
<p class="service-note">Each service has helpers that format responses in the correct structure: SQS XML messages with auto-generated IDs, SSM parameter metadata, Cognito JWT tokens, SNS message IDs, Step Functions execution ARNs, and EventBridge entry responses.</p>
</div>
</div>
<h3 class="section-subheading">Conditional Matching</h3>
<p class="section-lead">Match requests by headers to return different responses for different inputs.</p>
<div class="config-example">
<div class="code-block"><code>uvx --from local-web-services lws aws-fake add-operation my-s3-fake \
--operation get-object \
--match-header "x-custom-header=specific-value" \
--status 200 \
--body-string "Custom response for matched header"</code></div>
</div>
<h3 class="section-subheading">YAML Configuration</h3>
<p class="section-lead">AWS fakes are stored in <code>.lws/fakes/<name>/</code> and loaded automatically on startup.</p>
<div class="config-example">
<div class="code-block"><code># .lws/fakes/my-s3-fake/config.yaml
name: my-s3-fake
service: s3
enabled: true</code></div>
</div>
<div class="config-example">
<div class="code-block"><code># .lws/fakes/my-s3-fake/operations/get-object.yaml
operations:
- operation: get-object
match:
headers:
x-custom-header: "specific-value"
response:
status: 200
body: "file content"
content_type: "text/plain"
delay_ms: 100</code></div>
</div>
<h3 class="section-subheading">Runtime Control</h3>
<p class="section-lead">Enable and disable AWS fakes at runtime without restarting <code>ldk dev</code>.</p>
<div class="config-example">
<div class="code-block"><code># Enable/disable fakes for a service
uvx --from local-web-services lws aws-fake enable s3
uvx --from local-web-services lws aws-fake disable s3
# Check fake status
uvx --from local-web-services lws aws-fake status</code></div>
</div>
</div>
</section>
<!-- ============================================ -->
<!-- EXTERNAL SERVICE FAKING -->
<!-- ============================================ -->
<section class="section section-alt">
<div class="container">
<h2>External Service Faking</h2>
<p class="section-lead">Create local fake servers for external API dependencies — payment processors, third-party services, partner APIs — so your entire application runs locally without any external calls.</p>
<div class="feature-grid" style="grid-template-columns: 1fr 1fr; max-width: 900px; margin: 0 auto;">
<div class="feature-card">
<div class="feature-icon">$0</div>
<h3>No API Costs</h3>
<p>Stop burning through sandbox credits and rate limits during development. Fake servers return realistic responses without making real API calls.</p>
</div>
<div class="feature-card">
<div class="feature-icon">∅</div>
<h3>No Credentials Needed</h3>
<p>New developers don't need API keys for every third-party service. Fake servers work out of the box with zero configuration.</p>
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h3 class="section-subheading section-subheading--large" style="margin-top: 0;">How External Faking Works</h3>
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<h3>Create a Fake Server</h3>
<p>Define a fake server for each external dependency. Give it a name and optional base configuration.</p>
<div class="code-block"><code>uvx --from local-web-services lws fake create --name stripe-api</code></div>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<h3>Add Routes</h3>
<p>Define the endpoints your code calls, with the responses you want returned. Use CLI commands or YAML configuration.</p>
<div class="code-block"><code>uvx --from local-web-services lws fake add-route \
--name stripe-api \
--method POST --path /v1/charges \
--status 200 \
--body '{"id": "ch_{{uuid}}", "status": "succeeded"}'</code></div>
</div>
</div>
<div class="step">
<div class="step-number">3</div>
<div class="step-content">
<h3>Start with ldk dev</h3>
<p>Fake servers start automatically alongside your AWS services when you run <code>ldk dev</code>. Each fake gets its own local endpoint.</p>
</div>
</div>
<div class="step">
<div class="step-number">4</div>
<div class="step-content">
<h3>Point Your Code</h3>
<p>Configure your application to use the local fake endpoint instead of the real API. Environment variables are injected automatically for services defined in your IaC.</p>
</div>
</div>
</div>
</div>
</section>
<section class="section section-alt">
<div class="container">
<h2>Protocol Support</h2>
<p class="section-lead">Fake servers support the protocols your external dependencies use.</p>
<div class="feature-grid">
<div class="feature-card">
<div class="feature-icon">REST</div>
<h3>REST / HTTP</h3>
<p>Full HTTP method support (GET, POST, PUT, PATCH, DELETE). Match requests by path, headers, query parameters, and body fields. Return custom status codes, headers, and JSON/text bodies.</p>
</div>
<div class="feature-card">
<div class="feature-icon">GQL</div>
<h3>GraphQL</h3>
<p>Match GraphQL queries and mutations by operation name. Return typed response data with support for variables, nested objects, and error responses.</p>
</div>
<div class="feature-card">
<div class="feature-icon">gRPC</div>
<h3>gRPC</h3>
<p>Define service methods and return protobuf-compatible JSON responses. Supports unary calls with status codes and metadata.</p>
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h2>Defining Routes</h2>
<p class="section-lead">Routes define how your fake server responds to incoming requests. Configure them via CLI or YAML.</p>
<h3 class="section-subheading">Basic Route</h3>
<div class="config-example">
<div class="code-block"><code>routes:
- method: POST
path: /v1/charges
status: 200
headers:
Content-Type: application/json
body: |
{
"id": "ch_{{uuid}}",
"amount": {{body.amount}},
"currency": "{{body.currency}}",
"status": "succeeded",
"created": {{timestamp}}
}</code></div>
</div>
<h3 class="section-subheading">Conditional Matching</h3>
<p class="section-lead">Routes can match on headers, query parameters, and body fields to return different responses for different inputs.</p>
<div class="config-example">
<div class="code-block"><code>routes:
# Match by header
- method: GET
path: /v1/customers
match:
headers:
Authorization: "Bearer sk_test_valid"
status: 200
body: '{"data": [{"id": "cus_123"}]}'
# Match by query parameter
- method: GET
path: /v1/customers
match:
query:
email: "not-found@example.com"
status: 200
body: '{"data": []}'
# Match by body field
- method: POST
path: /v1/charges
match:
body:
amount: 99999
status: 402
body: '{"error": {"type": "card_error", "message": "Card declined"}}'</code></div>
</div>
</div>
</section>
<section class="section section-alt">
<div class="container">
<h2>Template Variables</h2>
<p class="section-lead">Use template variables in response bodies to generate dynamic, realistic responses.</p>
<div class="services-list">
<div class="service-detail">
<div class="service-detail-header">
<h3>Available Variables</h3>
</div>
<div class="service-detail-section">
<h4>Built-in Generators</h4>
<div class="service-detail-ops">
<span class="op">{{uuid}}</span>
<span class="op">{{timestamp}}</span>
<span class="op">{{random_int(min,max)}}</span>
<span class="op">{{random_choice(a,b,c)}}</span>
</div>
</div>
<div class="service-detail-section">
<h4>Request Data</h4>
<div class="service-detail-ops">
<span class="op">{{path.paramName}}</span>
<span class="op">{{query.paramName}}</span>
<span class="op">{{header.name}}</span>
<span class="op">{{body.field}}</span>
</div>
</div>
</div>
</div>
<h3 class="section-subheading">Example</h3>
<div class="config-example">
<div class="code-block"><code>routes:
- method: POST
path: /v1/payments
status: 200
body: |
{
"id": "pay_{{uuid}}",
"amount": {{body.amount}},
"currency": "{{body.currency}}",
"status": "{{random_choice(succeeded,pending,requires_action)}}",
"created": {{timestamp}},
"receipt_number": {{random_int(1000,9999)}}
}</code></div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h2>OpenAPI Import</h2>
<p class="section-lead">Automatically generate fake routes from existing OpenAPI 3.x or Swagger 2.x specifications.</p>
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<h3>Import a Spec</h3>
<p>Point <code>lws fake import-spec</code> at an OpenAPI file. Routes are generated for every endpoint with example responses from the spec.</p>
<div class="code-block"><code>uvx --from local-web-services lws fake import-spec \
--name stripe-api \
--spec openapi.yaml</code></div>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<h3>Validate Coverage</h3>
<p>Check that your fake covers all the endpoints your code actually calls. The validate command compares your fake routes against the spec and reports missing coverage.</p>
<div class="code-block"><code>uvx --from local-web-services lws fake validate \
--name stripe-api \
--spec openapi.yaml</code></div>
</div>
</div>
</div>
</div>
</section>
<footer class="footer">
<div class="container">
<div class="footer-inner">
<div class="footer-brand">
<a href="index.html" class="nav-logo">Local Web Services</a>
<p>The fastest feedback loop for cloud-native development, for humans and AI alike</p>
</div>
<div class="footer-links">
<a href="https://github.com/local-web-services/local-web-services">GitHub</a>
<a href="https://github.com/local-web-services/local-web-services/tree/main/sample-project/cdk">CDK Sample</a>
<a href="https://github.com/local-web-services/local-web-services/tree/main/sample-project/hcl">Terraform Sample</a>
<a href="https://github.com/local-web-services/local-web-services/issues">Issues</a>
</div>
</div>
<p class="footer-copy">Open source under the MIT License.</p>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-clike.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-yaml.min.js"></script>
<script src="lws.js"></script>
</body>
</html>