I created a app with node.js and deploy it on aws-amplify
. I added some logs, that i want to see on the amplify-ui. Where is it possible to see the logs?
My code:
import express from 'express';
import { ConsoleLogger } from 'aws-amplify/utils';
const logger = new ConsoleLogger('villa');
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-east-1" });
const app: express.Application = express();
const bodyParser = require('body-parser');
const port = 3000;
const path = require('path');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.urlencoded({ extended: true }))
app.use(express.static(path.join(__dirname, '..', 'public')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});
// @ts-ignore
app.post('/', (req, res) => {
send(req.body.name, req.body.address, req.body.text)
});
app.listen(port, () => {
console.log(`Villa app listening on port ${port}!`);
});
// @ts-ignore
function send(name, address, text) {
logger.log("Send message log send");
logger.log("Name:", name);
logger.log("Address:", address);
logger.log("Message:", text);
// Create sendEmail params
let params = {
Destination: {
/* required */
CcAddresses: [
"cccc@laresidencebloch.com",
/* more items */
],
ToAddresses: [
address,
/* more items */
],
},
Message: {
/* required */
Body: {
/* required */
Html: {
Charset: "UTF-8",
Data: text,
},
Text: {
Charset: "UTF-8",
Data: text,
},
},
Subject: {
Charset: "UTF-8",
Data: "Nouveau Message de la Residence Bloc H",
},
},
Source: "info@laresidencebloch.com" /* required */,
ReplyToAddresses: [
"info@laresidencebloch.com",
/* more items */
],
};
// Create the promise and SES service object
let sendPromise = new AWS.SES({ apiVersion: "2010-12-01" })
.sendEmail(params)
.promise();
// Handle promise's fulfilled/rejected states
sendPromise
// @ts-ignore
.then(function (data) {
logger.log(data.MessageId);
})
// @ts-ignore
.catch(function (err) {
logger.error(err, err.stack);
});
}
I can see the Access Logs into Monitoring but i want to see the console log into the script: for example: logger.log("Send message log send");
What should i do to see those logs?
You can try the following approach:
Use AWS CloudWatch Logs: Set up your application for AWS CloudWatch
explicitly, as Amplify itself dosen't show logs in the console. You can use the following snippet as an example:
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' });
const cloudwatchlogs = new AWS.CloudWatchLogs();
Amplify's Monitoring: Try navigating to Amplify Console's Monitoring tab, there you can access logs (Not detailed logs from your code).
Hope this helps!