使用 Amazon CloudWatch 日志 - 适用于 SQL 应用程序的 Amazon Kinesis Data Analytics 开发人员指南
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

对于新项目,建议您使用新的适用于 Apache Flink Studio 的托管服务,而不是使用适用于 SQL 应用程序的 Kinesis Data Analytics。Managed Service for Apache Flink Studio 不仅操作简单,还具有高级分析功能,使您能够在几分钟内构建复杂的流处理应用程序。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon CloudWatch 日志

如果未正确配置 应用程序,它可能会在应用程序启动期间转变为运行状态。或者它可以更新,但不会处理进入应用程序内部输入流的任何数据。通过向应用程序添加 CloudWatch 日志选项,您可以监控应用程序配置问题。

可能会在以下情况下产生配置错误:

  • 用于输入的 Kinesis 数据流不存在。

  • 用于输入的 Amazon Data Firehose 传输流不存在。

  • 用作引用数据源的 Amazon S3 存储桶不存在。

  • S3 存储桶的引用数据源中的指定文件不存在。

  • 管理相关权限的 Amazon Identity and Access Management (IAM) 角色中未定义正确的资源。

  • 管理相关权限的 IAM 角色中未定义正确权限。

  • 无权担任管理相关权限的 IAM 角色。

有关亚马逊的更多信息 CloudWatch,请参阅亚马逊 CloudWatch 用户指南

添加 PutLogEvents 策略操作

需要权限才能将错误配置错误写入。 CloudWatch您可以将这些权限添加到 担任的 IAM 角色中,如下所述。有关将 IAM 角色用于 的更多信息,请参阅 Kinesis Data Analytics 中的身份和访问管理

信任策略

要为 授予权限以担任 IAM 角色,您可以将以下信任策略附加到该角色。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "kinesisanalytics.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }

权限策略

要向应用程序授予 CloudWatch 从资源写入日志事件的权限,您可以使用以下 IAM 权限策略。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt0123456789000", "Effect": "Allow", "Action": [ "logs:PutLogEvents" ], "Resource": [ "arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:log-stream:my-log-stream*" ] } ] }

添加配置错误监控

使用以下 API 操作向新应用程序或现有应用程序添加 CloudWatch 日志选项或更改现有应用程序的日志选项。

注意

目前,您只能使用 API 操作向应用程序添加 CloudWatch 日志选项。您无法使用控制台添加 CloudWatch 日志选项。

创建应用程序时添加 CloudWatch 日志选项

以下代码示例演示了在创建应用程序时如何使用CreateApplication操作添加 CloudWatch 日志选项。有关 Create_Application 的更多信息,请参阅 CreateApplication

{ "ApplicationCode": "<The SQL code the new application will run on the input stream>", "ApplicationDescription": "<A friendly description for the new application>", "ApplicationName": "<The name for the new application>", "Inputs": [ ... ], "Outputs": [ ... ], "CloudWatchLoggingOptions": [{ "LogStreamARN": "<Amazon Resource Name (ARN) of the CloudWatch log stream to add to the new application>", "RoleARN": "<ARN of the role to use to access the log>" }] }

向现有应用程序添加 CloudWatch 日志选项

以下代码示例说明了如何使用 AddApplicationCloudWatchLoggingOption 操作将 CloudWatch 日志选项添加到现有应用程序中。有关 AddApplicationCloudWatchLoggingOption 的更多信息,请参阅AddApplicationCloudWatchLoggingOption

{ "ApplicationName": "<Name of the application to add the log option to>", "CloudWatchLoggingOption": { "LogStreamARN": "<ARN of the log stream to add to the application>", "RoleARN": "<ARN of the role to use to access the log>" }, "CurrentApplicationVersionId": <Version of the application to add the log to> }

更新现有 CloudWatch 日志选项

以下代码示例演示如何使用UpdateApplication操作修改现有 CloudWatch 日志选项。有关 UpdateApplication 的更多信息,请参阅UpdateApplication

{ "ApplicationName": "<Name of the application to update the log option for>", "ApplicationUpdate": { "CloudWatchLoggingOptionUpdates": [ { "CloudWatchLoggingOptionId": "<ID of the logging option to modify>", "LogStreamARNUpdate": "<ARN of the new log stream to use>", "RoleARNUpdate": "<ARN of the new role to use to access the log stream>" } ], }, "CurrentApplicationVersionId": <ID of the application version to modify> }

从应用程序中删除 CloudWatch 日志选项

以下代码示例演示如何使用DeleteApplicationCloudWatchLoggingOption操作删除现有 CloudWatch 日志选项。有关 DeleteApplicationCloudWatchLoggingOption 的更多信息,请参阅DeleteApplicationCloudWatchLoggingOption

{ "ApplicationName": "<Name of application to delete log option from>", "CloudWatchLoggingOptionId": "<ID of the application log option to delete>", "CurrentApplicationVersionId": <Version of the application to delete the log option from> }

配置错误

以下各节详细介绍了您可能在 Amazon L CloudWatch ogs 中看到的因应用程序配置错误而出现的错误。

错误消息格式

由应用程序错误配置产生的错误消息将采用以下格式显示。

{ "applicationARN": "string", "applicationVersionId": integer, "messageType": "ERROR", "message": "string", "inputId": "string", "referenceId": "string", "errorCode": "string" "messageSchemaVersion": "integer", }

错误消息中的字段包含以下信息:

  • applicationARN:生成应用程序的 Amazon 资源名称 (ARN),例如:arn:aws:kinesisanalytics:us-east-1:112233445566:application/sampleApp

  • applicationVersionId:遇到错误时的应用程序版本。有关更多信息,请参阅ApplicationDetail

  • messageType:消息类型。目前,此类型只能是 ERROR

  • message:错误的详细信息,例如:

    There is a problem related to the configuration of your input. Please check that the resource exists, the role has the correct permissions to access the resource and that Kinesis Analytics can assume the role provided.
  • inputId:与应用程序输入关联的 ID。仅当此输入为错误的原因时,此值才存在。如果 referenceId 存在,则此值不会存在。有关更多信息,请参阅DescribeApplication

  • referenceId:与应用程序引用数据源关联的 ID。仅当此源为错误的原因时,此值才会存在。如果 inputId 存在,则此值不会存在。有关更多信息,请参阅DescribeApplication

  • errorCode:错误的标识符。此 ID 为 InputErrorReferenceDataError

  • messageSchemaVersion:指定最新消息架构版本的值,当前为 1。您可以检查此值以了解错误消息架构是否已更新。

错误

CloudWatch 日志中可能出现的错误包括以下内容。

资源不存在

如果为 Kinesis 输入流指定的 ARN 不存在,但 ARN 在语法上正确,则会产生类似于下面的错误。

{ "applicationARN": "arn:aws:kinesisanalytics:us-east-1:112233445566:application/sampleApp", "applicationVersionId": "5", "messageType": "ERROR", "message": "There is a problem related to the configuration of your input. Please check that the resource exists, the role has the correct permissions to access the resource and that Kinesis Analytics can assume the role provided.", "inputId":"1.1", "errorCode": "InputError", "messageSchemaVersion": "1" }

如果用于引用数据的 Amazon S3 文件键不正确,则会产生类似于下面的错误。

{ "applicationARN": "arn:aws:kinesisanalytics:us-east-1:112233445566:application/sampleApp", "applicationVersionId": "5", "messageType": "ERROR", "message": "There is a problem related to the configuration of your reference data. Please check that the bucket and the file exist, the role has the correct permissions to access these resources and that Kinesis Analytics can assume the role provided.", "referenceId":"1.1", "errorCode": "ReferenceDataError", "messageSchemaVersion": "1" }

角色不存在

如果为不存在的 IAM 输入角色指定了 ARN,但 ARN 在语法上正确,则会产生类似于下面的错误。

{ "applicationARN": "arn:aws:kinesisanalytics:us-east-1:112233445566:application/sampleApp", "applicationVersionId": "5", "messageType": "ERROR", "message": "There is a problem related to the configuration of your input. Please check that the resource exists, the role has the correct permissions to access the resource and that Kinesis Analytics can assume the role provided.", "inputId":null, "errorCode": "InputError", "messageSchemaVersion": "1" }

角色无权访问资源

如果使用的输入角色无权访问输入资源(如 Kinesis 源流),则会产生类似于下面的错误。

{ "applicationARN": "arn:aws:kinesisanalytics:us-east-1:112233445566:application/sampleApp", "applicationVersionId": "5", "messageType": "ERROR", "message": "There is a problem related to the configuration of your input. Please check that the resource exists, the role has the correct permissions to access the resource and that Kinesis Analytics can assume the role provided.", "inputId":null, "errorCode": "InputError", "messageSchemaVersion": "1" }