Skip to content

Commit 156bc2a

Browse files
authored
Merge pull request #63 from danmoz/opencode/issue40-20260905063139
Fixed timeout validation and README units.
2 parents 9d660b2 + b398f17 commit 156bc2a

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎middleware.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ var (
3434
_ caddyhttp.MiddlewareHandler = (*Lambda)(nil)
3535
)
3636

37-
const maxLoggedRequestIDLength = 256
37+
const (
38+
maxLoggedRequestIDLength = 256
39+
maxLambdaTimeout = 15 * time.Minute
40+
)
3841

3942
func init() {
4043
caddy.RegisterModule(&Lambda{})
@@ -124,7 +127,10 @@ func isInsecureEndpoint(endpoint string) bool {
124127
// Validate implements caddy.Validator.
125128
func (m *Lambda) Validate() error {
126129
if m.Timeout < 0 {
127-
return errors.New("timeout must be greater than zero")
130+
return errors.New("timeout must not be negative")
131+
}
132+
if time.Duration(m.Timeout) > maxLambdaTimeout {
133+
return errors.New("timeout exceeds Lambda's 15-minute execution limit")
128134
}
129135
if m.RoleARN == "" && (m.ExternalID != "" || m.SessionName != "") {
130136
return errors.New("external_id and session_name require role_arn")

‎middleware_test.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ func TestValidate(t *testing.T) {
147147
wantErrorText: "external_id and session_name require role_arn",
148148
},
149149
{
150-
name: "non-positive timeout",
150+
name: "negative timeout",
151151
middleware: Lambda{FunctionName: "test-function", Timeout: -1},
152-
wantErrorText: "timeout must be greater than zero",
152+
wantErrorText: "timeout must not be negative",
153+
},
154+
{
155+
name: "timeout exceeds limit",
156+
middleware: Lambda{FunctionName: "test-function", Timeout: caddy.Duration(maxLambdaTimeout + time.Second)},
157+
wantErrorText: "timeout exceeds Lambda's 15-minute execution limit",
153158
},
154159
}
155160

0 commit comments

Comments
 (0)