Skip to content

Commit ca7d46b

Browse files
committed
fix: Fix handling of request truncation
1 parent 8887994 commit ca7d46b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

node/packages/aws-lambda-sdk/instrument/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const reportRequest = async (event, context) => {
7272
spanId: Buffer.from(awsLambdaSpan.id),
7373
requestId: context.awsRequestId,
7474
timestamp: toProtobufEpochTimestamp(traceSpans.awsLambdaInvocation.startTime),
75-
body: resolveBodyString(event, 'INPUT'),
75+
body: resolveBodyString(event, 'INPUT') || undefined,
7676
origin: 1,
7777
});
7878
const payloadBuffer = (serverlessSdk._lastRequestBuffer =

node/packages/aws-lambda-sdk/test/unit/internal-extension/index.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,5 +1149,52 @@ describe('internal-extension/index.test.js', () => {
11491149
delete strippedPayload.body;
11501150
expect(JSON.parse(request.input.body)).to.deep.equal(strippedPayload);
11511151
});
1152+
1153+
it('should strip large request bodies', async () => {
1154+
const payload = {
1155+
version: '2.0',
1156+
routeKey: 'POST /v2',
1157+
rawPath: '/v2',
1158+
rawQueryString: 'lone=value&multi=one,stillone&multi=two',
1159+
headers: {
1160+
'content-length': '385',
1161+
'content-type':
1162+
'multipart/form-data; boundary=--------------------------419073009317249310175915',
1163+
'multi': 'one,stillone,two',
1164+
},
1165+
queryStringParameters: {
1166+
lone: 'value',
1167+
multi: 'one,stillone,two',
1168+
},
1169+
requestContext: {
1170+
accountId: '205994128558',
1171+
apiId: 'xxx',
1172+
domainName: 'xxx.execute-api.us-east-1.amazonaws.com',
1173+
domainPrefix: 'xx',
1174+
http: {
1175+
method: 'POST',
1176+
path: '/v2',
1177+
protocol: 'HTTP/1.1',
1178+
sourceIp: '80.55.87.22',
1179+
userAgent: 'PostmanRuntime/7.29.0',
1180+
},
1181+
requestId: 'XyGnwhe0oAMEJJw=',
1182+
routeKey: 'POST /v2',
1183+
stage: '$default',
1184+
time: '01/Sep/2022:13:46:51 +0000',
1185+
timeEpoch: 1662040011065,
1186+
},
1187+
body: `{"s":"${'t'.repeat(130 * 1000)}"}`,
1188+
isBase64Encoded: false,
1189+
};
1190+
1191+
const { request } = await handleInvocation('api-endpoint', {
1192+
isApiEndpoint: true,
1193+
isBodyAltered: true,
1194+
payload,
1195+
});
1196+
1197+
expect(request.body).to.equal(undefined);
1198+
});
11521199
});
11531200
});

0 commit comments

Comments
 (0)