Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(integ-tests-alpha): invokeFunction is returning Uint8ArrayBlobAdapter each time versus converting to String or JSON object #27395

Closed
antoniordz96 opened this issue Oct 3, 2023 · 4 comments · Fixed by #27313
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. p1

Comments

@antoniordz96
Copy link

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',
@antoniordz96 antoniordz96 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 3, 2023
@antoniordz96
Copy link
Author

I debugged the provider lambda and it seems that the lambda invoke response.Payload is returning an object of type Uint8Array versus Uint8ArrayBlobAdapter as defined in aws sdk docs

So the logic introduced #27122 won't work specifically this if statement:

if (v && typeof(v) === 'object' && typeof((v as any).transformToString) === 'function') {

Could this be related to the default version of the AWS SDK V3 in the lambda runtime? If this link is up to date seems SDK 3.188.0 which doesn't have this change of Uint8ArrayBlobAdapter.

@peterwoodworth peterwoodworth added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2023
@peterwoodworth
Copy link
Contributor

thanks, we're working on a fix #27313

@mergify mergify bot closed this as completed in #27313 Oct 5, 2023
@mergify mergify bot closed this as completed in c68ea44 Oct 5, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

1 similar comment
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants