Doesn't work with serverless-optimize-plugin
Closed this issue · 2 comments
Hi All,
Been using Dynasty for a while now but wanted to reduce the size of my Lambda functions so brought in the serverless-optimize-plugin. However theres an exception thrown in the code when the plugin is used and the lambda is executed.
I've done some digging and from the stacktrace (heavily reduced for brevity):
module initialization error: TypeError
at assertPath (path.js:28:11)
at dirname (path.js:1349:5)
at requireDirectory
at Object.4.require-directory
at Object.3../lib
at Object.75.dynasty/lib/dynasty
I think the issue lies with the require-directory module where since the file is now bundled and minified into one file by the optimisation plugin it fails to resolve the path as its no longer in a traditional file system anymore.
I'm going to fork this and test it (and if so create a PR to hopefully be merged back in) but wanted to raise this with you because this is a fantastic module overall and its perfectly met my needs over the years so far!
Hey @alexnaish sorry for the issues -- yes that would be great, would love a PR to fix this!
We can also pull out that require-directory
module, I can't remember historically why it was even used in the first place.
Perfect, I've raised a PR here: #110. I've given it a quick sanity test and deployed it to a test lambda and it now works.
The only issue I had was when I was passing in the AWS_SECRET_KEY / AWS_SECRET_ACCESS_KEY environment variables as credentials I was getting an exception thrown by the AWS SDK:
"errorMessage": "The security token included in the request is invalid.",
"errorType": "UnrecognizedClientException"
I removed the accessKeyId
/ secretAccessKey
variables from the dynasty constructor, allowing the Lambda to pick them up from the environment variables automatically and it works as expected. Not sure whether this blocks this PR?