feat(runners): make the scale-up SQS event source mapping optional - #5253
Open
bayramkeles61 wants to merge 1 commit into
Open
Conversation
Adds `enable_scale_up_event_source_mapping` (default `true`, so behaviour is unchanged) to the root module and to `modules/runners`, wiring it to the `enabled` argument of `aws_lambda_event_source_mapping.scale_up`. Setting it to `false` lets an external consumer own the build queue and invoke the scale-up lambda itself. The motivating case is rate limiting: `CreateFleet` consumes the account's `ec2:RunInstances` request bucket, which AWS documents at a capacity of 5 refilling at 2/sec, and `scale_up_reserved_concurrent_executions` bounds concurrent invocations rather than invocations per second — the two differ by API latency, so the same reservation yields very different call rates. A long-lived consumer can hold a token bucket; a lambda invocation cannot. Without this flag the mapping cannot be turned off from configuration at all, and disabling it out of band drifts back on the next apply.
Contributor
|
@bayramkeles61 Can you sign your commit? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
CreateFleetconsumes the account'sec2:RunInstancesrequest bucket, which AWS documents as capacity 5, refill 2/sec, per account per Region and adjustable only through a Support case. The module's owndocs/rate-limits-and-tuning.mdnotes thatCreateFleet"empirically throttles at low single-digit TPS".When that limit is hit the failure does not settle on its own: a throttled call creates no instance, so the SQS message is never deleted, so it is redelivered, so more calls are made. We measured 6,833 scale-up invocations against 122 queued messages with zero instances created — the retries manufacture the throttle that causes the retries.
The lever the module offers today is
scale_up_reserved_concurrent_executions, but that bounds invocations in flight, not invocations per second. The two differ by the API's latency, so the same reservation of 5 yields ~2.5/sec at 2s per call and ~10/sec at 500ms. There is no setting that expresses a rate.A rate limit needs a token bucket, and a token bucket needs a process that outlives a single event. Lambda invocations are independent processes with no shared state, so the counter has to live somewhere else — which means letting something else consume the build queue.
What this changes
Adds
enable_scale_up_event_source_mappingto the root module and tomodules/runners, wired to theenabledargument ofaws_lambda_event_source_mapping.scale_up.Default is
true, so behaviour is unchanged for every existing configuration. Setting it tofalselets an external consumer drain the build queue at a controlled rate and invoke the scale-up lambda itself; the handler's contract is already suitable for that, since it takes a standardSQSEventand returnsSQSBatchResponse.Why a variable rather than doing it out of band
The resource does not set
enabled, so the provider default (true) is what lands in state. Disabling the mapping with the AWS CLI therefore shows up as drift and is reverted by the nextapply— silently re-enabling a second consumer of the queue.Related
docs/rate-limits-and-tuning.mdguidance onbatch_sizereducesCreateFleetcalls per message but does not bound the call rate.Testing
tofu fmtandtofu validatepass. The change is inert at the default, andterraform-docsoutput is left to theupdate-docsworkflow.🤖 Generated with Claude Code