Troubles connecting a MySQL Database on AWS with an Alexa-Hosted-Skill in Node.js

0

I'm having troubles trying to connect both of the services, because i can connect with the DB with MySQL Workbench in local and i can configurate the database, but using the same credentials in the skill don't work. I already tryed to create a special Rol inside the IAM and give to the skill permissions to fully operate with MySQL, use the same credentials of the database and set all the IPs allowed to access the Database in the Security Group, but it still don't work and i can't find where is the issue. If anyone knows where may i've been failed coding, i'd be thankful.

Also including what i used in the lambda main code:

var mysql = require('mysql');
var connection = mysql.createConnection({
              host: "host",
              user: "user",
              password: "pass",
              port: 3306
            });
connection.connect(function(err) {
  if (err) throw err;
  speakOutput = 'Connected';
});

and inside the package.json:

{
  "dependencies": {
    "ask-sdk-core": "^2.7.0",
    "ask-sdk-model": "^1.19.0",
    "aws-sdk": "^2.326.0",
    "mysql": "^2.5.4"
  }
}

The error i recieve in CloudWatch is :

ERROR	Error requesting syllable: TypeError: connection.promise is not a function
    at requestSyllable (/var/task/index.js:558:41)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.handle (/var/task/index.js:224:31)
    at async GenericRequestDispatcher.dispatchRequest (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:95:24)
    at async GenericRequestDispatcher.dispatch (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:45:22)
    at async CustomSkill.invoke (/var/task/node_modules/ask-sdk-core/dist/skill/CustomSkill.js:68:26)
2023-09-25T12:09:38.280Z 93ae5531-f80d-4d14-bf0d-f6528bedd6fd ERROR Error requesting syllable: TypeError: connection.promise is not a function at requestSyllable (/var/task/index.js:558:41) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.handle (/var/task/index.js:224:31) at async GenericRequestDispatcher.dispatchRequest (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:95:24) at async GenericRequestDispatcher.dispatch (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:45:22) at async CustomSkill.invoke (/var/task/node_modules/ask-sdk-core/dist/skill/CustomSkill.js:68:26)

And requestSyllable function code is:

async function requestSyllable(level,idWord){
let WordSyllable;
try {
      connection.connect();
      const query = `SELECT Word FROM Syllable WHERE Lvl=${level} AND id=${idWord}`;
      await connection.query(query, (error, results) => {
        if (error) {
            throw error;
        }
       else{
            WordSyllable= results;
        }     
      });
    } catch (error) {
      console.error('Error executing SQL query:', error);
    } finally {
        connection.end();
        return WordSyllable;
    }
}
  • Please provide the error messages of your Lambda execution. It is very difficult for others to figure out the problems without detailed error messages.

Racs_99
質問済み 7ヶ月前283ビュー
1回答
0

The problem seems to be located at L558:41 in your Lambda function. I don't know which part of code are around line 558, but I spotted that the await before connection.query is redundant. connection.query is a callback-based function, and it will not return a Promise object.

profile picture
HS
回答済み 7ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ