Skip to content

Commit 5cc01a0

Browse files
committed
Fix lambda url handling
1 parent c680be8 commit 5cc01a0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

aws/adaptor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
var DEBUGDumpPayload = os.Getenv("DEBUG_DUMP_PAYLOAD")
15+
var LambdaInvokeMode = os.Getenv("LAMBDA_INVOKE_MODE")
1516

1617
type LambdaIntegrationType int
1718

aws/lambda.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ func WithoutNonHTTPEventPassThrough() LambdaHandlerOption {
4545
}
4646

4747
type LambdaHandler struct {
48-
httpHandler http.Handler
49-
sessProv SDKSessionProvider
50-
sess *session.Session
51-
confProv SDKConfigProvider
52-
conf *aws.Config
53-
apiGW APIGatewayManagementAPI
54-
wsPathPrefix string
55-
nonHTTPEventPath string
48+
httpHandler http.Handler
49+
sessProv SDKSessionProvider
50+
sess *session.Session
51+
confProv SDKConfigProvider
52+
conf *aws.Config
53+
apiGW APIGatewayManagementAPI
54+
wsPathPrefix string
55+
nonHTTPEventPath string
56+
invokeLambdaWithStream func(ctx context.Context, request *events.LambdaFunctionURLRequest) (*events.LambdaFunctionURLStreamingResponse, error)
5657
}
5758

5859
type HandlerFunc func(ctx context.Context, payload json.RawMessage) (res any, err error)
@@ -63,8 +64,9 @@ func NewLambdaHandlerWithOption(h http.Handler, options []interface{}) *LambdaHa
6364
confProv: func(ctx context.Context) (aws.Config, error) {
6465
return config.LoadDefaultConfig(ctx)
6566
},
66-
wsPathPrefix: DefaultWebsocketPathPrefix,
67-
nonHTTPEventPath: DefaultNonHTTPEventPath,
67+
wsPathPrefix: DefaultWebsocketPathPrefix,
68+
nonHTTPEventPath: DefaultNonHTTPEventPath,
69+
invokeLambdaWithStream: lambdaurl.Wrap(h),
6870
}
6971

7072
for _, opt := range options {
@@ -213,11 +215,19 @@ func (l *LambdaHandler) Invoke(ctx context.Context, payload json.RawMessage) (re
213215
}
214216
res, err = l.InvokeWebsocketAPI(ctx, event)
215217
case LambdaFunctionURLIntegration:
216-
event := &events.LambdaFunctionURLRequest{}
217-
if err := json.Unmarshal(payload, event); err != nil {
218-
return nil, err
218+
if LambdaInvokeMode == "response_stream" {
219+
event := &events.LambdaFunctionURLRequest{}
220+
if err := json.Unmarshal(payload, event); err != nil {
221+
return nil, err
222+
}
223+
res, err = l.invokeLambdaWithStream(ctx, event)
224+
} else {
225+
event := &events.APIGatewayV2HTTPRequest{}
226+
if err := json.Unmarshal(payload, event); err != nil {
227+
return nil, err
228+
}
229+
res, err = l.InvokeHTTPAPI(ctx, event)
219230
}
220-
res, err = lambdaurl.Wrap(l.httpHandler)(ctx, event)
221231
default:
222232
res, err = l.HandleNonHTTPEvent(ctx, payload, "application/json")
223233
}

0 commit comments

Comments
 (0)