Winston CloudWatch Transport在Lambda上运行时不创建日志 [英] Winston CloudWatch Transport not Creating Logs When Running on Lambda
本文介绍了Winston CloudWatch Transport在Lambda上运行时不创建日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个设置为从AWS Lambda函数运行的Expressjs应用程序。当我将此应用程序部署到lambda时,lambda CloudWatch日志的控制台日志会显示出来(即/aws/lambda/lambda-name),但它不会创建配置中指定的新CloudWatch LogGroup。
如果我在本地运行lambda函数并生成日志,它将为本地环境创建一个CloudWatch日志组。Lambda函数连接到RDS实例,因此它们包含在VPC中。
已为Lambda分配了CloudWatchFullAccess策略,因此它不应该是权限错误。我已经查看了Lambda日志,没有看到任何与此相关的错误。
const env = process.env.NODE_ENV || 'local'
const config = require('../../config/env.json')[env]
const winston = require('winston')
const WinstonCloudwatch = require('winston-cloudwatch')
const crypto = require('crypto')
let startTime = new Date().toISOString()
const logger = winston.createLogger({
exitOnError: false,
level: 'info',
transports: [
new winston.transports.Console({
json: true,
colorize: true,
level: 'info'
}),
new WinstonCloudwatch({
awsAccessKeyId: config.aws.accessKeyId,
awsSecretKey: config.aws.secretAccessKey,
logGroupName: 'my-api-' + env,
logStreamName: function () {
// Spread log streams across dates as the server stays up
let date = new Date().toISOString().split('T')[0]
return 'my-requests-' + date + '-' +
crypto.createHash('md5')
.update(startTime)
.digest('hex')
},
awsRegion: 'us-east-1',
jsonMessage: true
})
]
})
const winstonStream = {
write: (message, encoding) => {
// use the 'info' log level so the output will be picked up by both transports
logger.info(message)
}
}
module.exports.logger = logger
module.exports.winstonStream = winstonStream
然后在我的Express应用程序中。
const morgan = require('morgan')
const { winstonStream } = require('./providers/loggers')
app.use(morgan('combined', { stream: winstonStream }
推荐答案
确认问题与私有网络中的lambda功能有关,并且未被授予通过本文中描述的子网、路由表、NAT和互联网网关公共访问互联网的权限。https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7
这篇关于Winston CloudWatch Transport在Lambda上运行时不创建日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文