File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
lambda-streaming-ttfb-write-sam-with-bedrock-streaming/src Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 66exports . handler = awslambda . streamifyResponse (
77 async ( event , responseStream , context ) => {
88 const lambdaRequestBody = JSON . parse ( event . body ) ;
9+ try {
10+ // Handle base64 encoded body from AWS SigV4 requests
11+ const body = event . isBase64Encoded ?
12+ Buffer . from ( event . body , 'base64' ) . toString ( 'utf-8' ) :
13+ event . body ;
14+ lambdaRequestBody = JSON . parse ( body ) ;
15+ } catch ( error ) {
16+ console . error ( 'Error parsing request body:' , error ) ;
17+ responseStream . write ( "Invalid JSON in request body." ) ;
18+ responseStream . end ( ) ;
19+ return ;
20+ }
21+
922 const prompt = lambdaRequestBody . prompt || '' ;
1023 if ( prompt == '' ) {
1124 responseStream . write ( "No prompt provided." ) ;
You can’t perform that action at this time.
0 commit comments