APIGateway 로그 출력 조사

8205 단어 APIGateway

CloudWatch 설정 로그 확인



【설정】 CloudWatch 로그 활성화 · 로그 레벨 ERROR · 모든 요청/응답을 로그 [API 오류] 없음
(XXX) Extended Request Id: Dt6vFHHzNjMFahw=
(XXX) Method request path: {}
(XXX) Method request query string: {}
(XXX) Method request headers: {sec-fetch-mode=navigate, referer=https://ap-northeast-1.console.aws.amazon.com/apigateway/home?region=ap-northeast-1, sec-fetch-site=cross-site, accept-language=ja,en-US;q=0.9,en;q=0.8, User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36, X-Forwarded-Proto=http
(XXX) Method request body before transformations:
(XXX) Endpoint request URI: https://【apiid】.execute-api.ap-northeast-1.amazonaws.com/dev/sample
(XXX) Endpoint request headers: {x-amzn-apigateway-api-id=【apiid】, Accept=application/json, User-Agent=AmazonAPIGateway_【apiid】, X-Amzn-Trace-Id=Root=1-5ddbd7fa-0c4187109fb1208005c00fa0}
(XXX) Endpoint request body after transformations:
(XXX) Endpoint response headers: {Date=Mon, 25 Nov 2019 13:32:42 GMT, Content-Type=application/json, Content-Length=70, Connection=keep-alive, x-amzn-RequestId=615c0930-90de-45c7-94bc-22cfc09e7dd5, Access-Control-Allow-Origin=*, x-amz-apigw-id=Dt6vFFtCtjMFuAQ=, X-Amzn-Trace-Id=Root=1-5ddbd7fa-0c4187109fb1208005c00fa0;Sampled=0}
(XXX) Endpoint response body before transformations: {"statusCode": 200, "body": "\"Hello from LambdaMethod:getTextData\""}
(XXX) Method response body after transformations: {"statusCode": 200, "body": "\"Hello from LambdaMethod:getTextData\""}
(XXX) Method response headers: {X-Amzn-Trace-Id=Root=1-5ddbd7fa-0c4187109fb1208005c00fa0;Sampled=0, Content-Type=application/json}

【설정】 CloudWatch 로그 활성화 · 로그 레벨 INFO · 요청/응답을 모두 로그 [API 오류] 없음
(XXX) Extended Request Id: Dt7aFGdjNjMFYyA=
(XXX) Verifying Usage Plan for request: XXX. API Key: API Stage: 【apiid】/test
(XXX) API Key authorized because method 'GET /backend' does not require API Key. Request will not contribute to throttle or quota limits
(XXX) Starting execution for request: XXX
(XXX) HTTP Method: GET, Resource Path: /backend
(XXX) Method request path: {}
(XXX) Method request query string: {}
(XXX) Method request headers: {sec-fetch-mode=navigate, sec-fetch-site=none, accept-language=ja,en-US;q=0.9,en;q=0.8, User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36, X-Forwarded-Proto=https, Host=【apiid】.execute-api.ap-northeast-1.amazonaws.com, sec-fetch-user=?1, X-Forwarded-Port=44
(XXX) Method request body before transformations:
(XXX) Endpoint request URI: https://【apiid】.execute-api.ap-northeast-1.amazonaws.com/dev/sample
(XXX) Endpoint request headers: {x-amzn-apigateway-api-id=【apiid】, Accept=application/json, User-Agent=AmazonAPIGateway_【apiid】, X-Amzn-Trace-Id=Root=1-5ddbd90d-c9908810aa6d94f0d26dfdc8}
(XXX) Endpoint request body after transformations:
(XXX) Sending request to https://【apiid】.execute-api.ap-northeast-1.amazonaws.com/dev/sample
(XXX) Received response. Status: 200, Integration latency: 52 ms
(XXX) Endpoint response headers: {Date=Mon, 25 Nov 2019 13:37:17 GMT, Content-Type=application/json, Content-Length=70, Connection=keep-alive, x-amzn-RequestId=4e45fba4-1dc3-4fb1-ba93-14ca9d3cf019, Access-Control-Allow-Origin=*, x-amz-apigw-id=Dt7aGHjFtjMFaiQ=, X-Amzn-Trace-Id=Root=1-5ddbd90d-c9908810aa6d94f0d26dfdc8;Sampled=0}
(XXX) Endpoint response body before transformations: {"statusCode": 200, "body": "\"Hello from LambdaMethod:getTextData\""}
(XXX) Method response body after transformations: {"statusCode": 200, "body": "\"Hello from LambdaMethod:getTextData\""}
(XXX) Method response headers: {X-Amzn-Trace-Id=Root=1-5ddbd90d-c9908810aa6d94f0d26dfdc8;Sampled=0, Content-Type=application/json}
(XXX) Successfully completed execution
(XXX) Method completed with status: 200

【설정】CloudWatch 로그 활성화, 로그 레벨 INFO, 요청 【API 오류】 없음
(XXX) Extended Request Id: Dt75sGkLNjMFY4g=
(XXX) Verifying Usage Plan for request: XXX. API Key: API Stage: 【apiid】/test
(XXX) API Key authorized because method 'GET /backend' does not require API Key. Request will not contribute to throttle or quota limits
(XXX) Starting execution for request: XXX
(XXX) HTTP Method: GET, Resource Path: /backend
(XXX) Successfully completed execution
(XXX) Method completed with status: 200

【설정】 CloudWatch 로그 활성화 · 로그 레벨 ERROR · 요청 [API 오류] 없음

로그 없음

【설정】 CloudWatch 로그 활성화 · 로그 레벨 ERROR · 요청 [API 오류] 있음
(XXX) Extended Request Id: Dt90EE2ANjMFU2Q=
(XXX) Request parameter validation failed. Missing parameters: [aa]

【설정】 CloudWatch 로그 활성화 · 로그 레벨 INFO · 요청 [API 오류] 있음
(XXX) Extended Request Id: Dt-CZFF3NjMFSuw=
(XXX) Verifying Usage Plan for request: XXX. API Key: API Stage: 【apiid】/test
(XXX) API Key authorized because method 'GET /backend' does not require API Key. Request will not contribute to throttle or quota limits
(XXX) Starting execution for request: XXX
(XXX) HTTP Method: GET, Resource Path: /backend
(XXX) Request parameter validation failed. Missing parameters: [aa]
(XXX) Method completed with status: 400

사용자 지정 액세스 로깅



로그의 형식(개인적으로 이것 정도 있으면 좋지 않을까라고)


{
    "requestId":"$context.requestId",
    "ip": "$context.identity.sourceIp",
    "requestTime":"$context.requestTime",
    "httpMethod":"$context.httpMethod",
    "resourcePath":"$context.resourcePath",
    "status":"$context.status",
    "protocol":"$context.protocol",
    "errormsg":"$context.error.message",
    "useragent":"$context.identity.userAgent",
    "latency":"$context.responseLatency"
}

출력 결과(오류시)


{
    "requestId": "4ad3c1e9-0ec4-418e-aacb-76779745107f",
    "ip": "XXX.XXX.XXX.XXX",
    "requestTime": "25/Nov/2019:14:14:57 +0000",
    "httpMethod": "GET",
    "resourcePath": "/backend",
    "status": "400",
    "protocol": "HTTP/1.1",
    "errormsg": "Missing required request parameters: [aa]",
    "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
    "latency": "9"
}

htps : // / cs. 아 ws. 아마존. 이 m/그럼_jp/아피가테와y/ぁてst/로 ゔぇぺぺ구이데/아피가테와 y-마핀 g-mp ぁ테-레후페렌세. HTML

CloudWatch 로그인 사이트



여기에서 로그를 확인할 수 있습니다. ★SQL과 같이 검색할 수 있습니다


로그 유지 기간도 고려하지 않으면. . ★조사중★



· 로그 그룹별로 로그가 삭제되는 기간을 설정할 수 있습니다.
· 로그 그룹마다 지정된 기간의 로그를 S3으로 내보낼 수 있습니다. (배치 설정은 불가능)

⇒Lambda에서 하루에 한 번씩 붙어, 기한이 만료된 로그를 S3에 넣는 것이,
편리하다고 생각했습니다.

htps //w w. 가득. . jp/Fu s/000052999. pdf
htps : // v.ぁsss d. jp / c ぉ u d / a ws / e x po rt-c ぉ 우도 tch - ぉ gs - s3 /
htp://추우인후ぉr마치온. 이 m/cぉd/포 st-569/
htps //w w.ぇbp 로후 ゜시오 l. jp / Motorin g-o-o-ws-c 우우 tch /

좋은 웹페이지 즐겨찾기