Skip to content

Commit 75e724e

Browse files
author
Julien Flack
committed
Added base64 decoding to handle SigV4 requests
1 parent 541a34b commit 75e724e

File tree

1 file changed

+13
-0
lines changed
  • lambda-streaming-ttfb-write-sam-with-bedrock-streaming/src

1 file changed

+13
-0
lines changed

lambda-streaming-ttfb-write-sam-with-bedrock-streaming/src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ const {
66
exports.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.");

0 commit comments

Comments
 (0)