We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 541a34b commit 75e724eCopy full SHA for 75e724e
1 file changed
lambda-streaming-ttfb-write-sam-with-bedrock-streaming/src/index.js
@@ -6,6 +6,19 @@ const {
6
exports.handler = awslambda.streamifyResponse(
7
async (event, responseStream, context) => {
8
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
+
22
const prompt = lambdaRequestBody.prompt || '';
23
if (prompt == '') {
24
responseStream.write("No prompt provided.");
0 commit comments