调用函数时使用mysqljs/mysql作为
npm install --save-dev mysql
我得到以下错误和跟踪。
{
"errorMessage": "RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Process exited before completing request"
}
--------------------------------------------------------------------
START RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Version: $LATEST
2018-07-22 19:11:46.308 (-07:00) be7822cc-8e1d-11e8-83b8-a1383ecfa1de Error: Received packet in the wrong sequence.
at N._parsePacket (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Protocol.js:270:1)
at N.write (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Parser.js:76:1)
at N.write (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Protocol.js:38:1)
at Socket.<anonymous> (/var/task/controllers/webpack:/node_modules/mysql/lib/Connection.js:91:1)
at Socket.<anonymous> (/var/task/controllers/webpack:/node_modules/mysql/lib/Connection.js:502:1)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
END RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de
REPORT RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Duration: 2514.52 ms Billed Duration: 2600 ms Memory Size: 128 MB Max Memory Used: 46 MB
RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Process exited before completing request
我的示例代码是
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import {createConnection, Connection} from 'mysql';
export const index: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
let connection = createConnection({
host: process.env["DB_RO_HOST"],
user: process.env["DB_RO_USERNAME"],
password: process.env["DB_RO_PASSWORD"],
database: process.env["DB_RO_NAME"]
});
connection.connect();
const response = {
statusCode: 200,
body: JSON.stringify("{\"test\":\"test\"}"),
};
cb(null, response);
}
当我试图调用connect()方法时,代码出错。
我的研究结果是,有几个人说,在旧版本的丑和网页中,要关掉丑中的烂。不过,我正在运行一个现代化的网页包。
我的包.json
{
"name": "aws-nodejs-typescript",
"version": "1.0.0",
"description": "Serverless webpack example using Typescript",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"source-map-support": "^0.5.0"
},
"devDependencies": {
"@types/aws-lambda": "8.10.1",
"@types/mysql": "^2.15.5",
"@types/node": "^8.10.21",
"mysql": "^2.16.0",
"serverless-webpack": "^5.1.1",
"ts-loader": "^4.2.0",
"typescript": "^2.8.1",
"webpack": "^4.5.0"
},
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
"license": "MIT"
}
1条答案
按热度按时间8hhllhi21#
这个错误是已知的:nodejs api+webpack 2 production builds=错误:接收到的数据包顺序错误
解释如下:“错误:收到的数据包顺序错误。”当连接到无服务器的aurora时
你可以通过卸载mysql和安装mysql2来修复它,mysql2与承诺一起工作