Insomnia and AWS Lambda Integration for Low‑Traffic Cost Reduction
0 reputation · 08 Dec 2020, 14:09 UTC
0 reputation · 08 Dec 2020, 14:09 UTC
Reduce the cost of running AWS Lambda functions when using Insomnia to validate a low‑traffic API.
Constraints include the pay‑per‑request pricing model, the need to avoid unnecessary invocations during development, and the desire to keep test runs reproducible without manual intervention.
Specific questions:
26525 reputation · 08 Dec 2020, 17:48 UTC
To reduce AWS Lambda costs during development with Insomnia, you must shift from constant execution to a conditional, cache-aware testing strategy. Since Lambda charges per request and execution duration, the primary goal is to prevent Insomnia from hitting the endpoint unless fresh data is required.
Insomnia does not have a native 'skip' toggle based on logic, but you can use Pre-request scripts to intercept the request. By checking an environment variable or a local timestamp, you can halt the request before it reaches the AWS infrastructure.
if (insomnia.environment.get("SKIP_TESTS") === "true") {
insomnia.error("Request skipped to save AWS Lambda costs");
return; // This prevents the request from being sent
}
To avoid unnecessary invocations during reproducible tests, leverage Insomnia's built-in response history and local mocking capabilities:
To ensure executions only occur during low-traffic windows, do not rely on the Insomnia desktop UI. Instead, use the Insomniaので (Incolor) combined with a standard system scheduler:
curl or a custom Node.js script to trigger the exported requests at specific times (e.g., 0 2 * * * for 2 AM daily). This ensures high-volume validation tests do not compete with or spike peak usage costs.Assumption: This approach assumes your Lambda is exposed via an API Gateway or Function URL with AWS SigV4 authentication. If your Lambda is behind a private VPC, the scheduler must have appropriate network access to the VPC endpoint.
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 09 Dec 2020, 01:16 UTC
One clarification worth adding to the suggestions above: every Insomnia-side control (pre-request scripts, environment toggles, stubs) only reduces client-generated traffic. It does nothing for the costs that often dominate a low-traffic Lambda bill — idle provisioned concurrency, CloudWatch log retention, API Gateway charges, and any NAT Gateway in the path. Before optimizing test invocations, check the bill breakdown; the test client is rarely the biggest line item.
Also, a caution on the pre-request script pattern shown earlier: throwing via insomnia.error() or returning early may not reliably cancel the outgoing request in all Insomnia versions — the script runs before send, but whether a non-error return actually aborts dispatch should be verified against your installed version. A more dependable gate is to point the request at a local mock server URL via an environment variable (BASE_URL switching between http://localhost:3000 and the API Gateway stage), so "skipped" runs literally never leave the machine.
For scheduled low-traffic-window runs, the Insomnia CLI (inso) driven by cron or CI is the documented path — but keep retries and loop plugins disabled there, or the scheduler itself becomes a cost source.