-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.p1
Description
Describe the bug
Hey I'm using the import { IntegTest, ExpectedResult } from '@aws-cdk/integ-tests-alpha'; for writing some integration tests. I'm trying to invoke a lambda function and then check the response payload that it sends back but seems the payload sent back is always of Uint8ArrayBlobAdapter instead of a string or JSON object.
At a high level gist.
integ.assertions.invokeFunction({
functionName: testLambda.functionName,
}).expect(ExpectedResult.objectLike({
StatusCode: 200,
Payload: JSON.stringify({
code: 200,
}),
}));CDK Version: 2.99.1
Expected Behavior
Be able to check the Payload and validate its the expected response in String or JSON format
Current Behavior
From the logs I see the following coming back to the lambda
2023-10-03T19:25:14.966Z 44e46c89-f5c2-4f0e-a119-8fddd2ab6000 INFO SDK response received
{
"$metadata": {
"httpStatusCode": 200,
"requestId": "5ffd7187-3dc6-4bfb-b0d0-7191d2daadbf",
"attempts": 1,
"totalRetryDelay": 0
},
"ExecutedVersion": "$LATEST",
"Payload": {
"0": 34,
"1": 53,
"2": 48,
"3": 48,
"4": 34
},
"StatusCode": 200
}
For now I'm just gonna fail the lambda :sad
Reproduction Steps
import { IntegTest, ExpectedResult } from '@aws-cdk/integ-tests-alpha';
import { App, Stack } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
const accountID = '123456789012';
const region = 'us-east-1';
const app = new App();
const stack = new Stack(app, 'SampleAppStack', {
tags: {
blockCode: 'xxxx',
},
env: {
account: accountID,
region: region,
},
});
new lambda.Function(stack, 'lambda', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromInline(`exports.handler = async (event) => {
return "200"
};`),
});
// Initialize Integ Test construct
const integStack = new Stack(app, 'IntegrationTestAssertions', {
tags: {
blockCode: 'xxxxx',
},
env: {
account: accountID,
region: region,
},
});
const integ = new IntegTest(app, 'DatabaseStackIntegrationTest', {
testCases: [stack], // Define a list of cases for this test
cdkCommandOptions: {
// Customize the integ-runner parameters
destroy: {
args: {
force: true,
},
},
},
assertionStack: integStack,
regions: [stack.region],
});
const invokeFunction = new lambda.Function(integStack, 'lambda', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromInline(`exports.handler = async (event) => {
return "200"
};`),
});
integ.assertions.invokeFunction({
functionName: invokeFunction.functionName,
payload: JSON.stringify({ data: 'Hello World!' }),
}).expect(ExpectedResult.objectLike({
StatusCode: 200,
Payload: '200',
}));
Possible Solution
No response
Additional Information/Context
aws/aws-sdk-js-v3#2252 (comment) is interesting regarding Uint8ArrayBlobAdapter
CDK CLI Version
2.99.1
Framework Version
2.99.1
Node.js Version
v18.15.0
OS
mac
Language
Typescript
Language Version
~5.1.0
Other information
'@aws-cdk/integ-runner@^2.99.1-alpha.0',
'@aws-cdk/integ-tests-alpha@^2.99.1-alpha.0',
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.p1