GithubHelp home page GithubHelp logo

Comments (1)

Iviglious avatar Iviglious commented on May 28, 2024

Hi,

In summary

The CORS error is a secondary error caused by a previous error of a missing package (aws-xray-sdk-core) in AWS Lambda.

Workaround fix

Generate local installation of all packages (libraries) and then deploy them together in AWS Lambda.

In details

When checking the CloudWatch logs of the AWS Lambda functions It can be seen the error of a missing package/library aws-xray-sdk-core:

2021-03-23T00:17:07.587Z	undefined	ERROR	Uncaught Exception 	{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'aws-xray-sdk-core'\nRequire stack:\n- /var/task/app.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'aws-xray-sdk-core'",
        "Require stack:",
        "- /var/task/app.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"
    ]
}

Currently the AWS Lambda functions only require/depend on these 3 packages:

    "aws-sdk": "^2.823.0",
    "aws-embedded-metrics": "^2.0.2",
    "aws-xray-sdk-core": "^3.2.0"

The aws-sdk seems to be already included in AWS Lambda (no error about it). However, the xray library seems to be missing (or there is some internal bug).
I tested with NodeJS 14 version of AWS Lambda and the xray library was not available there either.

Workaround fix

I did npm install inside the todo-src\getAllTodo folder then did another sam deploy and it was fine.
The CORS error disappeared.
I created a bash script to do the install of the libraries in all function folders:

cd todo-src/

cd addTodo; npm install; cd ..
cd completeTodo; npm install; cd ..
cd deleteTodo; npm install; cd ..
cd getAllTodo; npm install; cd ..
cd getTodo; npm install; cd ..
cd updateTodo; npm install; cd ..

cd ..

Feedback

  1. Check with the AWS Lambda team on why the aws-xray-sdk-core library is not available.
  2. Furthermore, it will be useful to expand/update this page: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html and give detailed list of all libraries/packages and their version supported by AWS Lambda.
  3. Deploying the whole installation of packages is not user friendly as the code gets zipped and is not visible in AWS portal.

Regards,
Iviglious

from lambda-refarch-webapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.