aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.05k stars 573 forks source link

'AWS CRT binary not present' when using cloudfront-keyvaluestore in Lambda runtime #5663

Closed luukdobber closed 7 months ago

luukdobber commented 8 months ago

Checkboxes for prior research

Describe the bug

I am trying to use @aws-sdk/client-cloudfront-keyvaluestore in the NODEJS_20_X lambda runtime. Calling any of the keyvaluestore API's causes the error AWS CRT binary not present in any of the following locations:\n\t/bin/linux-x64-glibc/aws-crt-nodejs.

Before running into the error mentioned above, I ran in to the issues described in https://github.com/aws/aws-sdk-js-v3/issues/5576. I worked around that error with the changes mentioned in https://github.com/aws/aws-sdk-js-v3/issues/5576#issuecomment-1854958060. But then I ran into the AWS CRT binary error.

SDK version number

@aws-sdk/client-cloudfront-keyvaluestore@3.485.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

NODEJS_20_X lambda runtime

Reproduction Steps

Deploy a Lambda function with the following configuration (CDK):

const kvLambda = new NodejsFunction(this, 'KvsTestLambda', {
      entry: 'lib/lambdas/kvs-test.ts',
      runtime: lambda.Runtime.NODEJS_20_X,
      environment: {
        KVS_ARN: <insert KVS ARN>
      },
      bundling: {
        externalModules: [] // Force AWS SDK to be bundled, KeyValueStore is not yet available in the Lambda runtime version of @aws-sdk
      }
    })

kvLambda.addToRolePolicy(new cdk.aws_iam.PolicyStatement({
  actions: [
    'cloudfront-keyvaluestore:*',
    'cloudfront:*'
  ],
  resources: ['*']
}))

Lambda code:

import * as cloudfront from '@aws-sdk/client-cloudfront'
import * as kv from '@aws-sdk/client-cloudfront-keyvaluestore'
// https://github.com/aws/aws-sdk-js-v3/issues/5576
import { SignatureV4MultiRegion } from '@aws-sdk/signature-v4-multi-region'
import '@aws-sdk/signature-v4-crt'

export const handler = async (event) => {
  const kvStoreArn = process.env.KVS_ARN
  if (!kvStoreArn) {
    throw new Error('KVS_ARN is not defined')
  }

  // Test CloudFront API to make sure the problem is isolated to the cloudfront-keyvaluestore
  const cfClient = new cloudfront.CloudFrontClient()
  const distResult = await cfClient.send(new cloudfront.ListDistributionsCommand({}))
  console.log(JSON.stringify(distResult))

  // Call keyvaluestore API
  const kvClient = new kv.CloudFrontKeyValueStoreClient({
    signerConstructor: SignatureV4MultiRegion
  })
  const result = await kvClient.send(new kv.DescribeKeyValueStoreCommand({
    KvsARN: kvStoreArn
  }))

  console.log(JSON.stringify(result))
}

Observed Behavior

The cloudfront.ListDistributionsCommand command works as expected, the kv.DescribeKeyValueStoreCommand results in an error:

{
    "errorType": "Error",
    "errorMessage": "AWS CRT binary not present in any of the following locations:\n\t/bin/linux-x64-glibc/aws-crt-nodejs",
    "stack": [
        "Error: AWS CRT binary not present in any of the following locations:",
        "\t/bin/linux-x64-glibc/aws-crt-nodejs",
        "    at node_modules/aws-crt/dist/native/binding.js (/var/task/index.js:42005:13)",
        "    at __require (/var/task/index.js:12:50)",
        "    at node_modules/aws-crt/dist/native/auth.js (/var/task/index.js:42448:38)",
        "    at __require (/var/task/index.js:12:50)",
        "    at node_modules/aws-crt/dist/index.js (/var/task/index.js:46048:30)",
        "    at __require (/var/task/index.js:12:50)",
        "    at node_modules/@aws-sdk/signature-v4-crt/dist-cjs/CrtSignerV4.js (/var/task/index.js:46174:21)",
        "    at __require (/var/task/index.js:12:50)",
        "    at node_modules/@aws-sdk/signature-v4-crt/dist-cjs/index.js (/var/task/index.js:46304:25)",
        "    at __require (/var/task/index.js:12:50)"
    ]
}

Expected Behavior

I expect the kv.DescribeKeyValueStoreCommand to return a result.

Possible Solution

No response

Additional Information/Context

No response

rr923 commented 7 months ago

I have the same issue when trying to use client-cloudfront-keyvaluestore with SST.

aBurmeseDev commented 7 months ago

Hi @luukdobber @rr923 - thanks for your patience.

I had attempted to reproduce this multiple times but was unable to. It's also strange that you mentioned it works for cloudfront.ListDistributionsCommand command and not kv.DescribeKeyValueStoreCommand. Were you able to locate the file for aws-crt at locations:\n\t/bin/linux-x64-glibc/aws-crt-nodejs. Can you check which version of aws-crt is installed?

Also to double check if you ran npm install @aws-sdk/signature-v4-crt to install the package: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-signature-v4-crt/

github-actions[bot] commented 7 months ago

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

luukdobber commented 7 months ago

Hi @aBurmeseDev ,

Thanks for your reply and sorry for my late response. I somehow missed your message until the issue was closed.

Did you try to reproduce it in the NODEJS_20_X lambda runtime? Could you share your working Lambda and CDK code so I can compare it with mine? The code in my opening post still results in the AWS CRT binary not present error. Please note that I override the NodeJSFunction bundling settings because I need a newer SDK-version for the CloudFront KeyValueStore than the one available in NODEJS_20_X.

github-actions[bot] commented 6 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.