-
Notifications
You must be signed in to change notification settings - Fork 3
Fix oversized response handling #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package main | |
import ( | ||
"context" | ||
log "github.com/sirupsen/logrus" | ||
"go.amzn.com/lambda/interop" | ||
"go.amzn.com/lambda/rapidcore" | ||
"os" | ||
"runtime/debug" | ||
|
@@ -28,6 +29,7 @@ type LsOpts struct { | |
EdgePort string | ||
EnableXRayTelemetry string | ||
PostInvokeWaitMS string | ||
MaxPayloadSize string | ||
} | ||
|
||
func GetEnvOrDie(env string) string { | ||
|
@@ -50,6 +52,7 @@ func InitLsOpts() *LsOpts { | |
User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"), | ||
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "warn"), | ||
EdgePort: GetenvWithDefault("EDGE_PORT", "4566"), | ||
MaxPayloadSize: GetenvWithDefault("LOCALSTACK_MAX_PAYLOAD_SIZE", "6291556"), | ||
dominikschubert marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally no unit ( |
||
// optional or empty | ||
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"), | ||
HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","), | ||
|
@@ -77,6 +80,7 @@ func UnsetLsEnvs() { | |
"LOCALSTACK_INIT_LOG_LEVEL", | ||
"LOCALSTACK_POST_INVOKE_WAIT_MS", | ||
"LOCALSTACK_FUNCTION_ACCOUNT_ID", | ||
"LOCALSTACK_MAX_PAYLOAD_SIZE", | ||
|
||
// Docker container ID | ||
"HOSTNAME", | ||
|
@@ -128,6 +132,13 @@ func main() { | |
log.Fatal("Invalid value for LOCALSTACK_INIT_LOG_LEVEL") | ||
} | ||
|
||
// patch MaxPayloadSize | ||
payloadSize, err := strconv.Atoi(lsOpts.MaxPayloadSize) | ||
if err != nil { | ||
log.Panicln("Please specify a number for LOCALSTACK_MAX_PAYLOAD_SIZE") | ||
} | ||
interop.MaxPayloadSize = payloadSize | ||
|
||
// enable dns server | ||
dnsServerContext, stopDnsServer := context.WithCancel(context.Background()) | ||
go RunDNSRewriter(lsOpts, dnsServerContext) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// LOCALSTACK CHANGES 2024-02-13: adjust error message for ErrorResponseTooLarge to be in parity with what AWS returns; make MaxPayloadSize adjustable | ||
|
||
package interop | ||
|
||
|
@@ -18,10 +19,10 @@ import ( | |
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var MaxPayloadSize int = 6*1024*1024 + 100 // 6 MiB + 100 bytes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. annoying that we cannot use a single type due to mixed usages 😢 (server.go requires an |
||
|
||
// MaxPayloadSize max event body size declared as LAMBDA_EVENT_BODY_SIZE | ||
const ( | ||
MaxPayloadSize = 6*1024*1024 + 100 // 6 MiB + 100 bytes | ||
|
||
ResponseBandwidthRate = 2 * 1024 * 1024 // default average rate of 2 MiB/s | ||
ResponseBandwidthBurstSize = 6 * 1024 * 1024 // default burst size of 6 MiB | ||
|
||
|
@@ -355,7 +356,7 @@ type ErrorResponseTooLargeDI struct { | |
|
||
// ErrorResponseTooLarge is returned when response provided by Runtime does not fit into shared memory buffer | ||
func (s *ErrorResponseTooLarge) Error() string { | ||
return fmt.Sprintf("Response payload size (%d bytes) exceeded maximum allowed payload size (%d bytes).", s.ResponseSize, s.MaxResponseSize) | ||
return fmt.Sprintf("Response payload size exceeded maximum allowed payload size (%d bytes).", s.MaxResponseSize) | ||
} | ||
|
||
// AsErrorResponse generates ErrorInvokeResponse from ErrorResponseTooLarge | ||
|
Uh oh!
There was an error while loading. Please reload this page.