ServerLess gives empty exception with sequelize-typescript model?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm trying to get Sequelize to work with my aws-lambda project. However, the serverless framework returns an empty exception whenever i try to use a model and i do not understand why. The response som serverless is just a pair of red brackets('{}')...
I've boiled it down to a sample:
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import { Column, Model, PrimaryKey, Sequelize , Table } from 'sequelize-typescript';
@Table
class SomeModel extends Model<SomeModel> {
@Column
@PrimaryKey
public id: number;
}
export const handler: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
const sequelize = new Sequelize({
host: '...',
database: '...',
dialect: 'mssql',
username: '...',
password: '...',
});
sequelize.addModels([SomeModel]);
sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
const dbversion = sequelize.options.databaseVersion;
const response = {
statusCode: 200,
body: JSON.stringify('DB version: ' + dbversion),
};
cb(null, response);
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
};
If i run 'serverless invoke local --verbose --function dbtest' i get:
{}
Error --------------------------------------------------
Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
at AwsInvokeLocal.invokeLocalNodeJs (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:307:13)
at AwsInvokeLocal.invokeLocal (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:131:19)
From previous event:
at Object.invoke:local:invoke [as hook] (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:27:10)
at BbPromise.reduce (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:55)
From previous event:
at PluginManager.invoke (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:22)
at PluginManager.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:422:17)
at variables.populateService.then.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:157:33)
at runCallback (timers.js:794:20)
at tryOnImmediate (timers.js:752:5)
at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
at Serverless.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:144:8)
at serverless.init.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlessbinserverless:44:28)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.10.0
Serverless Version: 1.35.1
However, IF i remove/comment out the model-class including the addModels() and all related imports...then it works as expected! In this case i get the correct version of the database back in the response...
I've been scratching my head for the last couple of days and my conclusion is that i must be missing some essential, and most likely simple, point...
Ideas?
UPDATE - Workaround found?
I think i found where it fails...i still don't understand why though...
If i change the order of the @Column and @PrimaryKey decorators on the model then everything works as expected...so primary key needs to be first, else it will throw the empty exception... but i'd like to know why?
UPDATE 2
It seems like the sequelize-typescript should be able to tell me this kinda of errors...why doesn't this show up when running the invoke-command?
https://github.com/RobinBuschmann/sequelize-typescript/blob/93330a700b11e1eaf7fdc53b05fe0b3d92eeb22b/lib/services/models.ts#L115-L118
aws-lambda serverless-framework sequelize-typescript
add a comment |
I'm trying to get Sequelize to work with my aws-lambda project. However, the serverless framework returns an empty exception whenever i try to use a model and i do not understand why. The response som serverless is just a pair of red brackets('{}')...
I've boiled it down to a sample:
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import { Column, Model, PrimaryKey, Sequelize , Table } from 'sequelize-typescript';
@Table
class SomeModel extends Model<SomeModel> {
@Column
@PrimaryKey
public id: number;
}
export const handler: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
const sequelize = new Sequelize({
host: '...',
database: '...',
dialect: 'mssql',
username: '...',
password: '...',
});
sequelize.addModels([SomeModel]);
sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
const dbversion = sequelize.options.databaseVersion;
const response = {
statusCode: 200,
body: JSON.stringify('DB version: ' + dbversion),
};
cb(null, response);
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
};
If i run 'serverless invoke local --verbose --function dbtest' i get:
{}
Error --------------------------------------------------
Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
at AwsInvokeLocal.invokeLocalNodeJs (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:307:13)
at AwsInvokeLocal.invokeLocal (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:131:19)
From previous event:
at Object.invoke:local:invoke [as hook] (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:27:10)
at BbPromise.reduce (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:55)
From previous event:
at PluginManager.invoke (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:22)
at PluginManager.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:422:17)
at variables.populateService.then.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:157:33)
at runCallback (timers.js:794:20)
at tryOnImmediate (timers.js:752:5)
at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
at Serverless.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:144:8)
at serverless.init.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlessbinserverless:44:28)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.10.0
Serverless Version: 1.35.1
However, IF i remove/comment out the model-class including the addModels() and all related imports...then it works as expected! In this case i get the correct version of the database back in the response...
I've been scratching my head for the last couple of days and my conclusion is that i must be missing some essential, and most likely simple, point...
Ideas?
UPDATE - Workaround found?
I think i found where it fails...i still don't understand why though...
If i change the order of the @Column and @PrimaryKey decorators on the model then everything works as expected...so primary key needs to be first, else it will throw the empty exception... but i'd like to know why?
UPDATE 2
It seems like the sequelize-typescript should be able to tell me this kinda of errors...why doesn't this show up when running the invoke-command?
https://github.com/RobinBuschmann/sequelize-typescript/blob/93330a700b11e1eaf7fdc53b05fe0b3d92eeb22b/lib/services/models.ts#L115-L118
aws-lambda serverless-framework sequelize-typescript
add a comment |
I'm trying to get Sequelize to work with my aws-lambda project. However, the serverless framework returns an empty exception whenever i try to use a model and i do not understand why. The response som serverless is just a pair of red brackets('{}')...
I've boiled it down to a sample:
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import { Column, Model, PrimaryKey, Sequelize , Table } from 'sequelize-typescript';
@Table
class SomeModel extends Model<SomeModel> {
@Column
@PrimaryKey
public id: number;
}
export const handler: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
const sequelize = new Sequelize({
host: '...',
database: '...',
dialect: 'mssql',
username: '...',
password: '...',
});
sequelize.addModels([SomeModel]);
sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
const dbversion = sequelize.options.databaseVersion;
const response = {
statusCode: 200,
body: JSON.stringify('DB version: ' + dbversion),
};
cb(null, response);
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
};
If i run 'serverless invoke local --verbose --function dbtest' i get:
{}
Error --------------------------------------------------
Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
at AwsInvokeLocal.invokeLocalNodeJs (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:307:13)
at AwsInvokeLocal.invokeLocal (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:131:19)
From previous event:
at Object.invoke:local:invoke [as hook] (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:27:10)
at BbPromise.reduce (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:55)
From previous event:
at PluginManager.invoke (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:22)
at PluginManager.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:422:17)
at variables.populateService.then.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:157:33)
at runCallback (timers.js:794:20)
at tryOnImmediate (timers.js:752:5)
at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
at Serverless.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:144:8)
at serverless.init.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlessbinserverless:44:28)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.10.0
Serverless Version: 1.35.1
However, IF i remove/comment out the model-class including the addModels() and all related imports...then it works as expected! In this case i get the correct version of the database back in the response...
I've been scratching my head for the last couple of days and my conclusion is that i must be missing some essential, and most likely simple, point...
Ideas?
UPDATE - Workaround found?
I think i found where it fails...i still don't understand why though...
If i change the order of the @Column and @PrimaryKey decorators on the model then everything works as expected...so primary key needs to be first, else it will throw the empty exception... but i'd like to know why?
UPDATE 2
It seems like the sequelize-typescript should be able to tell me this kinda of errors...why doesn't this show up when running the invoke-command?
https://github.com/RobinBuschmann/sequelize-typescript/blob/93330a700b11e1eaf7fdc53b05fe0b3d92eeb22b/lib/services/models.ts#L115-L118
aws-lambda serverless-framework sequelize-typescript
I'm trying to get Sequelize to work with my aws-lambda project. However, the serverless framework returns an empty exception whenever i try to use a model and i do not understand why. The response som serverless is just a pair of red brackets('{}')...
I've boiled it down to a sample:
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import { Column, Model, PrimaryKey, Sequelize , Table } from 'sequelize-typescript';
@Table
class SomeModel extends Model<SomeModel> {
@Column
@PrimaryKey
public id: number;
}
export const handler: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
const sequelize = new Sequelize({
host: '...',
database: '...',
dialect: 'mssql',
username: '...',
password: '...',
});
sequelize.addModels([SomeModel]);
sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
const dbversion = sequelize.options.databaseVersion;
const response = {
statusCode: 200,
body: JSON.stringify('DB version: ' + dbversion),
};
cb(null, response);
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
};
If i run 'serverless invoke local --verbose --function dbtest' i get:
{}
Error --------------------------------------------------
Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: Exception encountered when loading C:UsersThomasDocumentsGitHubTest.webpackservicefunctionsdbtestget-dbtest
at AwsInvokeLocal.invokeLocalNodeJs (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:307:13)
at AwsInvokeLocal.invokeLocal (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:131:19)
From previous event:
at Object.invoke:local:invoke [as hook] (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibpluginsawsinvokeLocalindex.js:27:10)
at BbPromise.reduce (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:55)
From previous event:
at PluginManager.invoke (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:391:22)
at PluginManager.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibclassesPluginManager.js:422:17)
at variables.populateService.then.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:157:33)
at runCallback (timers.js:794:20)
at tryOnImmediate (timers.js:752:5)
at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
at Serverless.run (C:UsersThomasAppDataRoamingnpmnode_modulesserverlesslibServerless.js:144:8)
at serverless.init.then (C:UsersThomasAppDataRoamingnpmnode_modulesserverlessbinserverless:44:28)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.10.0
Serverless Version: 1.35.1
However, IF i remove/comment out the model-class including the addModels() and all related imports...then it works as expected! In this case i get the correct version of the database back in the response...
I've been scratching my head for the last couple of days and my conclusion is that i must be missing some essential, and most likely simple, point...
Ideas?
UPDATE - Workaround found?
I think i found where it fails...i still don't understand why though...
If i change the order of the @Column and @PrimaryKey decorators on the model then everything works as expected...so primary key needs to be first, else it will throw the empty exception... but i'd like to know why?
UPDATE 2
It seems like the sequelize-typescript should be able to tell me this kinda of errors...why doesn't this show up when running the invoke-command?
https://github.com/RobinBuschmann/sequelize-typescript/blob/93330a700b11e1eaf7fdc53b05fe0b3d92eeb22b/lib/services/models.ts#L115-L118
aws-lambda serverless-framework sequelize-typescript
aws-lambda serverless-framework sequelize-typescript
edited Jan 3 at 12:56
Thomas Eg
asked Jan 3 at 8:40


Thomas EgThomas Eg
15
15
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018840%2fserverless-gives-empty-exception-with-sequelize-typescript-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018840%2fserverless-gives-empty-exception-with-sequelize-typescript-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown