A nodejs 18 based Lambda importing from aws-sdk v3 fails to find the client-ssm package

0

I have writtena a Lambda function, based on NodeJS 18, that should send an openCypher query to a Neptune DB. The Neptune DB end point is stored as a paramater in the SSM. The below Lambda code fails with this error:

{
  "errorType": "Error",
  "errorMessage": "Cannot find package '@aws-sdk/client-ssm' imported from /var/task/index.mjs",
  "trace": [
    "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@aws-sdk/client-ssm' imported from /var/task/index.mjs",
    "    at new NodeError (node:internal/errors:393:5)",
    "    at packageResolve (node:internal/modules/esm/resolve:865:9)",
    "    at moduleResolve (node:internal/modules/esm/resolve:958:20)",
    "    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:909:12)",
    "    at defaultResolve (node:internal/modules/esm/resolve:1173:79)",
    "    at nextResolve (node:internal/modules/esm/loader:163:28)",
    "    at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)",
    "    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)",
    "    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)",
    "    at link (node:internal/modules/esm/module_job:75:36)"
  ]
}

I thought the aws-sdk v3 is already loaded for the Lambda with NodeJS 18. What am I missing?

The Lambda code:

import { SSMClient } from "@aws-sdk/client-ssm";
import { NeptuneClient } from "@aws-sdk/client-neptune";
import { GetParameterRequest } from "@aws-sdk/client-ssm/commands/GetParameterCommand";

const ssm = new SSMClient({
  region: "us-east-1",
});
const neptune = new NeptuneClient({
  region: "us-east-1",
});

export async function getParameter(parameterName) {
  const params = {
    Name: parameterName,
  };
  const request = new GetParameterRequest(params);
  const response = await ssm.send(request);
  return response.Parameter.Value;
}

export async function handler(event) {
  const NEPTUNE_ENDPOINT = await getParameter("simplify-mvp-dev-neptune-db-endpoint");
  const IAM_ROLE_ARN = await getParameter("simplify-mvp-dev-iam-role-secret-arn");

  const params = {
    DatabaseName: "db-simplify-mvp-dev",
    ResourceArn: IAM_ROLE_ARN,
    SecretArn: IAM_ROLE_ARN,
    Sql: `MATCH (n) RETURN n`,
  };

  const result = await neptune.runCypherQuery(params).promise();

  return {
    statusCode: 200,
    body: JSON.stringify(result),
  };
}
  • You might try deploying it with your handler file called index.js instead of index.mjs, it seems like using .mjs changes some behavior based on this page in the Lambda docs

mor
已提问 1 年前2259 查看次数
2 回答
1

The client you are using only exposes Control Plane actions, such as Creating/Modifying cluster instances, and is not meant to be used to query Neptune. For openCypher, the recommendation is to query Neptune using the HTTPS endpoint as described here.

AWS
已回答 1 年前
  • Thanks, @Dave-AWS. Yes, I am familiar with this documentation. It does not help me to get a Node.js 18 runtime lambda using the aws-sdk v3 to work! I even removed using SSM completely (for the time being) and just trying to make the Neptune query work - it does not. Looking at the @aws-sdk/client-neptune library (on GitHub) I could not even find a method to actually send the query command. Is there not an "internal" AWS library to openCypher query Neptune from a nodejs18 runtime Lambda? should I just send out a REST HTTP request as if I'm querying any service in the internet?

0

Hi,

I cannot reproduce the issue with the SSM Client. Can you please verify that your Lambda function is indeed using a NodeJS 18 runtime?

Moreover the NeptuneClient class does not have a runCypherQuery method, so your code would anyway not work.

To query NeptuneDB via openCypher using Javascript you need to use the HTTPS endpoint or use a Bolt library, like https://neo4j.com/developer/javascript/#neo4j-javascript-driver

AWS
专家
已回答 1 年前
  • Hi Massimilian, thank you for your reply. Yes, it is definitely Node.js 18.x Runtime. I just confirmed this in the Runtime settings below the code of the Lambda. If I understand your comment, you were able to fetch an SSM parameter using my code? As for Neptune, are you suggesting that the aws-sdk/client-neptune is not available for a Lambda to use, just like the aws-sdk/client-ssm is used?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则