willfarrell / middy-rds Goto Github PK
View Code? Open in Web Editor NEWMiddy middleware for creating a db connection using knex
License: MIT License
Middy middleware for creating a db connection using knex
License: MIT License
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)"
]
}
In the index file is a typo, where const sl
must be const ssl
Pull request created: #2
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
Changing the line to await request.context.db.destroy();
resolves the problem.
Setting cacheExpiry
to 0
triggers the error: "Cannot read property 'destroy' of undefined",
This occurs on line:
Line 46 in 88d755c
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:
Line 42 in 88d755c
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
}
}));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.