首先,需要确认Lambda函数是否已经授权将日志发送到CloudWatch。在Lambda函数的IAM角色中,确保已经添加了适当的权限。
查看代码,确保有正确的日志语句被添加到了函数中。例如,在Node.js中,可以使用console.log()语句输出日志。
检查Lambda函数的别名配置,确保日志级别已经正确设置为INFO或更高级别。在启动时仅记录INIT_START事件可能是由于日志级别设置为DEBUG或更低级别,因此只有启动事件被记录下来。
示例代码: 以下是Node.js中使用别名日志的示例代码:
exports.handler = async (event, context) => { console.log('Function started'); //其他函数代码 }
在Lambda函数别名配置中,可以将日志级别设置为INFO,以便记录函数的各个事件。例如,如果别名为“prod”,可以使用以下命令来更新日志级别:
aws lambda update-alias --function-name my-function --name prod --function-version 2 --description "Production environment" --routing-config '{"AdditionalVersionWeights": {}}' --revision-id a1b2c3d4-e5f6-7890-1234-5678abcd9012 --cli-input-json '{"Name": "prod", "FunctionName": "my-function", "FunctionVersion": "2", "Description": "Production environment", "RoutingConfig": {"AdditionalVersionWeights": {}}, "RevisionId": "a1b2c3d4-e5f6-7890-1234-5678abcd9012", "ProvisionedConcurrencyConfig": {"Enabled": true, "ProvisionedConcurrentExecutions": 10}, "TracingConfig": {"Mode": "Active"}, "DeadLetterConfig": {"TargetArn": "arn:aws:sns:us-east-1:123456789012:MyDLQ"}, "Environment": {"Variables": {"PARAM1": "VALUE1", "PARAM2": "VALUE2"}}}'