Giter VIP home page Giter VIP logo

middy-rds's People

Contributors

jimmy89 avatar willfarrell avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

middy-rds's Issues

Dynamic require of \"crypto\" is not supported

I'm getting the error ""Dynamic require of "crypto" is not supported" when I try to use the middy-rds middleware in a JS module file (".mjs" extension). Is there a way around this, or am I stuck having to use this middlware only in ".js" and ".cjs" files? Here's the full stack trace for context.

{
  "errorType": "Error",
  "errorMessage": "Dynamic require of \"crypto\" is not supported",
  "stack": [
    "Error: Dynamic require of \"crypto\" is not supported",
    "    at file:///var/task/node_modules/middy-rds/clients/pg.mjs:12:9",
    "    at node_modules/uuid/dist/rng.js (file:///var/task/node_modules/middy-rds/clients/pg.mjs:2451:42)",
    "    at __require2 (file:///var/task/node_modules/middy-rds/clients/pg.mjs:15:50)",
    "    at node_modules/uuid/dist/v1.js (file:///var/task/node_modules/middy-rds/clients/pg.mjs:2536:39)",
    "    at __require2 (file:///var/task/node_modules/middy-rds/clients/pg.mjs:15:50)",
    "    at node_modules/uuid/dist/index.js (file:///var/task/node_modules/middy-rds/clients/pg.mjs:2919:37)",
    "    at __require2 (file:///var/task/node_modules/middy-rds/clients/pg.mjs:15:50)",
    "    at node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js (file:///var/task/node_modules/middy-rds/clients/pg.mjs:3027:18)",
    "    at __require2 (file:///var/task/node_modules/middy-rds/clients/pg.mjs:15:50)",
    "    at node_modules/@aws-sdk/middleware-retry/dist-cjs/AdaptiveRetryStrategy.js (file:///var/task/node_modules/middy-rds/clients/pg.mjs:3135:35)"
  ]
}

Update to use bundled certificate

In /var/runtime/bootstrap it contains:

# If NODE_EXTRA_CA_CERTS is being set by the customer, don't override. Else, include RDS CA
if [ -z "${NODE_EXTRA_CA_CERTS+set}" ];
then
  export NODE_EXTRA_CA_CERTS="/etc/pki/tls/certs/ca-bundle.crt"
fi

cacheExpiry set to 0 triggers db undefined error in middlewareAfter

Update:

Changing the line to await request.context.db.destroy(); resolves the problem.

Original:

Setting cacheExpiry to 0 triggers the error: "Cannot read property 'destroy' of undefined",
This occurs on line:

await promisify(request.context.db.destroy)()

Although the before middleware copies the db in the context, the afterMiddleware does not seems to be able to contain this connection.

The beforeMiddleware code:

Object.assign(request.context, { db: await value }) // await due to fetch being a promise

Below is the code I used for local testing (e.g. with lambda-node):

const mainHandler = middy(baseHandler).use(logger({
  awsContext: true
})).use(normalizer({
  canonical: true
})).use(jsonBodyParser())
  .use(httpErrorHandler());

const connection = {
  database: getEnvVar("dbDatabase"),
  password: getEnvVar("dbPassword"),
  host: getEnvVar("dbHost"),
  user: getEnvVar("dbUsername"),
  port: getEnvVar("dbPort") || 5432,
  ssl: false
}

handler = mainHandler.use(rds({
    cacheExpiry: 0,
    client: knex,
    config: {
      client: "pg",
      connection
    }
  }));

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.