Amazon CloudWatch 로그로 작업하기 - Amazon Kinesis Data Analytics for SQL 애플리케이션 개발자 안내서

새 프로젝트의 경우 SQL 애플리케이션용 Kinesis Data Analytics보다 Apache Flink Studio용 새로운 관리형 서비스를 사용하는 것이 좋습니다. Apache Flink Studio용 관리형 서비스는 사용 편의성과 고급 분석 기능을 결합하여 정교한 스트림 처리 애플리케이션을 몇 분 만에 구축할 수 있도록 합니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon CloudWatch 로그로 작업하기

애플리케이션이 잘못 구성되면 애플리케이션이 시작하는 동안 실행 상태로 전환될 수 있습니다. 또는 애플리케이션 내 입력 스트림에 데이터를 업데이트할 수 있으나 처리할 수는 없습니다. 애플리케이션에 CloudWatch 로그 옵션을 추가하면 애플리케이션 구성 문제를 모니터링할 수 있습니다.

다음 조건에서 구성 오류를 생성할 수 있습니다:

  • 입력에 사용되는 Kinesis 데이터 스트림이 존재하지 않습니다.

  • 입력에 사용된 Amazon Data Firehose 전송 스트림이 존재하지 않습니다.

  • 참조 데이터 소스로 사용되는 Amazon S3 버킷이 존재하지 않습니다.

  • S3 버킷의 참조 데이터 소스에 지정된 파일이 존재하지 않습니다.

  • 관련 권한을 관리하는 AWS Identity and Access Management (IAM) 역할에 올바른 리소스가 정의되어 있지 않습니다.

  • 관련 권한을 관리하는 IAM 역할에 정확한 권한이 정의되어 있지 않습니다.

  • 관련 권한을 관리하는 IAM 역할을 수행할 권한이 없습니다.

CloudWatchAmazon에 대한 자세한 내용은 Amazon CloudWatch 사용 설명서를 참조하십시오.

PutLogEvents 정책 조치 추가

잘못된 구성 오류를 기록할 권한이 필요합니다. CloudWatch 다음 설명과 같이 IAM 역할의 권한을 추가할 수 있습니다. IAM 역할에 대한 자세한 설명은 Kinesis Data Analytics의 ID 및 액세스 관리 섹션을 참조하십시오.

신뢰 정책

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 CloudWatch Logs에 표시될 수 있는 오류에 대한 세부 정보가 포함되어 있습니다.

오류 메시지 형식

애플리케이션 구성 오류에 의해 생성되는 오류 메시지는 다음과 같은 형식으로 표시됩니다.

{ "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). 이 값을 통해 오류 메시지 스키마가 업데이트되었는지 확인할 수 있습니다.

Errors

CloudWatch Logs for 에 나타날 수 있는 오류는 다음과 같습니다.

리소스가 존재하지 않음

존재하지 않는 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" }