Fitter Man
Fitter Man

Reputation: 682

Accessing AWS native npms for fails

I'm working my way through an example for AWS Transcribe right out of Amazon's documentation, but it's failing at the require, and I'm wondering what I'm missing for the setup to get this to work. The log reports Error: Cannot find module '@aws-sdk/client-transcribe' and you can see the full example and log below.

This is my first project with lambdas and node.js, but I've gotten all the other AWS Lambda code running, so I suspect this is an error on my part. I've been searching and come up empty-handed.

const {
  TranscribeClient,
  StartTranscriptionJobCommand,
} = require("@aws-sdk/client-transcribe");

// Set the AWS Region
const REGION = "REGION"; // For example, "us-east-1"

// Set the parameters
const params = {
  TranscriptionJobName: "JOB_NAME",
  LanguageCode: "LANGUAGE_CODE", // For example, 'en-US'
  MediaFormat: "SOURCE_FILE_FORMAT", // For example, 'wav'
  Media: {
    MediaFileUri: "SOURCE_LOCATION",
    // For example, "https://transcribe-demo.s3-REGION.amazonaws.com/hello_world.wav"
  },
};

// Create an Amazon Transcribe service client object
const client = new TranscribeClient({ region: REGION });

const run = async () => {
  try {
    const data = await client.send(new StartTranscriptionJobCommand(params));
    console.log("Success - put", data);
  } catch (err) {
    console.log("Error", err);
  }
};
run();

And this is the entry in the log:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@aws-sdk/client-transcribe'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '@aws-sdk/client-transcribe'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/index.js",
        "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

    2021-01-29T23:25:31.952Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@aws-sdk/client-transcribe'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module '@aws-sdk/client-transcribe'","Require stack:","- /var/task/index.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"," at Object.<anonymous> (/var/runtime/index.js:43:30)"," at Module._compile (internal/modules/cjs/loader.js:999:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"," at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)"," at internal/main/run_main_module.js:17:47"]}

Upvotes: 1

Views: 1117

Answers (3)

bmur
bmur

Reputation: 446

Install npm, then run 'npm install' on the github repo for these examples, as per the prerequisite instructions here for these examples.

It will install all the required AWS SDK for JavaScript V3 modules required for the example. If these are missing the error you quote is triggered.

Upvotes: 1

Fitter Man
Fitter Man

Reputation: 682

It turns out there was a way to get this same functionality without installing the AWS npms beyond whatever Amazon delivers with the base lambda instance.

const AWS = require('aws-sdk');

// Set the AWS Region
const REGION = "REGION"; // For example, "us-east-1"


// Set the parameters
const params = {
  TranscriptionJobName: "JOB_NAME",
  LanguageCode: "LANGUAGE_CODE", // For example, 'en-US'
  MediaFormat: "SOURCE_FILE_FORMAT", // For example, 'wav'
  Media: {
    MediaFileUri: "SOURCE_LOCATION",
    // For example, "https://transcribe-demo.s3-REGION.amazonaws.com/hello_world.wav"
  },
};

// Create an Amazon Transcribe service client object
const client = new TranscribeClient({ region: REGION });

const run = async () => {
  try {
    transcribe.startTranscriptionJob(params, (err, data) => {
        if (err) {
            console.log("Success - put", data);
            throw(err);
        }
        else
        {
            const data = await client.send(new StartTranscriptionJobCommand(params));
            console.log("Success - put", data);
        }
    });
  } catch (err) {
    console.log("Error", err);
  }
};
run();

Upvotes: 0

Federico Sierra
Federico Sierra

Reputation: 5208

The example that you are using imports and use AWS Service V3 package clients.

At the moment the Node.js runtimes in lambda environment include AWS SDK 2.804.0.

You must include the new version in your deployment.

Upvotes: 1

Related Questions