Class: ElasticGraph::GraphQLLambda::GraphQLEndpoint
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQLLambda::GraphQLEndpoint
- Defined in:
- lib/elastic_graph/graphql_lambda/graphql_endpoint.rb
Constant Summary collapse
- LAMBDA_TIMEOUT_BUFFER_MS =
Used to add a timeout buffer so that the lambda timeout should generally not be reached, instead preferring our ‘timeout_in_ms` behavior to the harsher timeout imposed by lambda itself. We prefer this in order to have consistent timeout behavior, regardless of what timeout is reached. For example, we have designed our timeout logic to disconnect from the datastore (which causes it to kill the running query) but we do not know if the lambda-based timeout would also cause that. This buffer gives our lambda enough time to respond before the hard lambda timeout so that it should (hopefully) never get reached.
Note we generally run with a 30 second overall lambda timeout so a single second of buffer still gives plenty of time to satisfy the query.
1_000- LAMBDA_MAX_RESPONSE_PAYLOAD_BYTES =
As per docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html, AWS Lambdas are limited to returning up to 6 MB responses.
Note: 6 MB is technically 6291456 bytes, but the AWS log message when you exceed the limit mentions a limit of 6291556 (100 bytes larger!). Here we use the smaller threshold since it’s the documented value.
(_ = 2**20) * 6
Instance Method Summary collapse
- #handle_request(event:, context:) ⇒ Object
-
#initialize(graphql) ⇒ GraphQLEndpoint
constructor
A new instance of GraphQLEndpoint.
Constructor Details
#initialize(graphql) ⇒ GraphQLEndpoint
Returns a new instance of GraphQLEndpoint.
36 37 38 39 40 |
# File 'lib/elastic_graph/graphql_lambda/graphql_endpoint.rb', line 36 def initialize(graphql) @graphql_http_endpoint = graphql.graphql_http_endpoint @logger = graphql.logger @monotonic_clock = graphql.monotonic_clock end |
Instance Method Details
#handle_request(event:, context:) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elastic_graph/graphql_lambda/graphql_endpoint.rb', line 42 def handle_request(event:, context:) start_time_in_ms = @monotonic_clock.now_in_ms # should be the first line so our duration logging is accurate request = request_from(event) response = @graphql_http_endpoint.process( request, max_timeout_in_ms: context.get_remaining_time_in_millis - LAMBDA_TIMEOUT_BUFFER_MS, start_time_in_ms: start_time_in_ms ) convert_response(response) end |