Knowledge Center Monthly Newsletter - March 2025
Stay up to date with the latest from the Knowledge Center. See all new and updated Knowledge Center articles published in the last month and re:Post’s top contributors.
Wie analysiere ich meine Application Load Balancer-Zugriffsprotokolle mit Amazon Athena?
Lesedauer: 4 Minute
0
Ich möchte meine Application Load Balancer-Zugriffsprotokolle mit Amazon Athena analysieren.
Kurzbeschreibung
Elastic Load Balancing aktiviert die Zugriffsprotokolle standardmäßig nicht. Wenn Sie die Zugriffsprotokolle aktivieren, geben Sie einen Amazon Simple Storage Service (Amazon S3)-Bucket an. Athena analysiert die Zugriffsprotokolle von Application Load Balancer und Classic Load Balancer und speichert die Protokolle im Amazon S3-Bucket.
Hinweis: Diese Lösung gilt nur für Application Load Balancer.
Lösung
Erstellen Sie eine Datenbank und eine Tabelle für Application Load Balancer-Protokolle
Führen Sie die folgenden Schritte aus:
- Öffnen Sie die Athena-Konsole.
- Um eine Datenbank zu erstellen, führen Sie den folgenden Befehl im Abfrage-Editor aus:
Hinweis: Es hat sich bewährt, die Datenbank in derselben AWS-Region wie der Amazon S3-Bucket zu erstellen.CREATE DATABASE alb_db
- Erstellen Sie in der Datenbank eine alb_logs-Tabelle für die Application Load Balancer-Protokolle.
Beispielabfrage:
Hinweis: Ersetzen Sie in der vorherigen Abfrage den Tabellennamen und die S3-Speicherorte durch Ihren Tabellennamen und die S3-Speicherorte. Ersetzen Sie 2022/01/01 für projection.day.range durch ein Startdatum. Für eine bessere Abfrageleistung können Sie eine Tabelle mit Partitionsprojektion erstellen.CREATE EXTERNAL TABLE IF NOT EXISTS alb_logs( type string, time string, elb string, client_ip string, client_port int, target_ip string, target_port int, request_processing_time double, target_processing_time double, response_processing_time double, elb_status_code int, target_status_code string, received_bytes bigint, sent_bytes bigint, request_verb string, request_url string, request_proto string, user_agent string, ssl_cipher string, ssl_protocol string, target_group_arn string, trace_id string, domain_name string, chosen_cert_arn string, matched_rule_priority string, request_creation_time string, actions_executed string, redirect_url string, lambda_error_reason string, target_port_list string, target_status_code_list string, classification string, classification_reason string, conn_trace_id string ) PARTITIONED BY(day STRING) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES( 'serialization.format' = '1', 'input.regex' = '([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \"([^ ]*) (.*) (- |[^ ]*)\" \"([^\"]*)\" ([A-Z0-9-_]+) ([A-Za-z0-9.-]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" ([-.0-9]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^ ]*)\" \"([^\s]+?)\" \"([^\s]+)\" \"([^ ]*)\" \"([^ ]*)\" ?([^ ]*)?( .*)?') LOCATION 's3://<your-alb-logs-directory>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/' TBLPROPERTIES( "projection.enabled" = "true", "projection.day.type" = "date", "projection.day.range" = "2022/01/01,NOW", "projection.day.format" = "yyyy/MM/dd", "projection.day.interval" = "1", "projection.day.interval.unit" = "DAYS", "storage.location.template" = "s3://<your-alb-logs-directory>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/${day}" )
- Um eine Tabelle mit Partitionen zu erstellen, die im AWS Glue-Datenkatalog gespeichert sind, führen Sie die folgende Abfrage aus:
Hinweis: Ersetzen Sie in der vorherigen Abfrage den Tabellennamen und die S3-Speicherorte durch Ihren Tabellennamen und die S3-Speicherorte.CREATE EXTERNAL TABLE IF NOT EXISTS alb_logs_partitioned(type string, time string, elb string, client_ip string, client_port int, target_ip string, target_port int, request_processing_time double, target_processing_time double, response_processing_time double, elb_status_code int, target_status_code string, received_bytes bigint, sent_bytes bigint, request_verb string, request_url string, request_proto string, user_agent string, ssl_cipher string, ssl_protocol string, target_group_arn string, trace_id string, domain_name string, chosen_cert_arn string, matched_rule_priority string, request_creation_time string, actions_executed string, redirect_url string, lambda_error_reason string, target_port_list string, target_status_code_list string, classification string, classification_reason string, conn_trace_id string ) PARTITIONED BY(day string) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES( 'serialization.format' = '1', 'input.regex' ='([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \"([^ ]*) (.*) (- |[^ ]*)\" \"([^\"]*)\" ([A-Z0-9-_]+) ([A-Za-z0-9.-]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" ([-.0-9]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^ ]*)\" \"([^\s]+?)\" \"([^\s]+)\" \"([^ ]*)\" \"([^ ]*)\" ?([^ ]*)?( .*)?') LOCATION 's3://<your-alb-logs-directory>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/'
- (Optional) Um die Partitionen zu laden, führen Sie die folgende ALTER TABLE ADD PARTITION DDL-Anweisung aus:
Hinweis: Wenn Ihre Tabelle Partitionsprojektion verwendet, überspringen Sie den Schritt Partitionen laden. Verwenden Sie keinen AWS Glue-Crawler für die Application Load Balancer-Protokolle.ALTER TABLE alb_logs_partitioned ADD PARTITION (day = '2022/05/21') LOCATION's3://<your-alb-logs-directory>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/2022/05/21/'
- Wählen Sie im Navigationsbereich unter Tabellen die Option Tabellenvorschau aus.
- Sie können die Daten aus den Application Load Balancer-Zugriffsprotokollen im Ergebnis-Fenster einsehen.
Hinweis: Verwenden Sie den Abfrage-Editor, um SQL-Anweisungen für die Tabelle auszuführen.
Ähnliche Informationen

AWS OFFICIALAktualisiert vor 9 Monaten
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 3 Jahren
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Monaten