-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get sequelize.js to work with serverless-bundle. #45
Comments
@ggrantrowberry What was the issue you ran into with the new beta? That should address this issue. You can checkout the |
I ran into the same problem. After some debugging, I found that the dynamic importing of knex.js and sequelize.js isn't the same. While both are dynamic import depending on the configuration, knex does it with a static import at dialect implementation level, while sequelize configure it at dialect level, and invokes |
BTW, I found the work around in here. Basically Sequelize config accepts a // hello.js
import Sequelize from 'sequelize'
import pg from 'pg'
export const hello = async function (event, context, ...rest) {
const sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USERNAME,
process.env.DB_PASSWORD,
{
host: process.env.DB_HOST,
dialect: process.env.DB_DIALECT,
dialectModule: pg
}
)
const result = await sequelize.query('select 1+1 as result')
return {
statusCode: 200,
body: JSON.stringify(
{
message: `Hello ${result}`,
input: event
},
null,
2
)
} # serverless.yml
service: sls2
provider:
name: aws
runtime: nodejs12.x
environment:
DB_DIALECT: "postgres"
DB_NAME: "sls2_name"
DB_USERNAME: "sls2_username"
DB_PASSWORD: "sls2_password"
...
custom:
bundle:
# forceInclude: # NOTE: you don't need this anymore
# - pg
ignorePackages:
- pg-native
plugins:
- serverless-bundle
functions:
hello:
handler: src/hello.hello I suggest we create an |
@blai Thanks for investigating and posting this. Agreed, that we need specific examples. Do you mind contributing one for this case? Btw, we have this note in the README and I noticed that it has the right option |
For now, let me add a note to the README with your instructions. Later we can link to an example. Edit: Added https://github.com/AnomalyInnovations/serverless-bundle/blob/master/README.md#sequelize |
I am using a lambda function to parse a file uploaded to s3 then take the data and put it in a remote mysql database. I am using sequelize.js with the mysql2 package. I've deployed my code but I get the this error, {"errorType":"Error","errorMessage":"Please install mysql2 package manually"}. I googled around and found that using serverless-webpack I just need to use the following.
https://stackoverflow.com/questions/48554917/getting-sequelize-js-library-to-work-on-amazon-lambda
I tried that but it obviously didn't work with serverless-bundle. I saw a previous issue about using knex.js that looked like a similar problem. I tried installing the serverless-bundle@beta as was suggested but it didn't install properly.
I'm brand new to serverless and I'm not sure what else to do.
The text was updated successfully, but these errors were encountered: