DescribeFlowLogs 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeFlowLogs 搭配 CLI 使用

下列程式碼範例示範如何使用 DescribeFlowLogs

CLI
AWS CLI

範例 1:描述您的所有流程日誌

下列describe-flow-logs範例會顯示所有流程日誌的詳細資訊。

aws ec2 describe-flow-logs

輸出:

{ "FlowLogs": [ { "CreationTime": "2018-02-21T13:22:12.644Z", "DeliverLogsPermissionArn": "arn:aws:iam::123456789012:role/flow-logs-role", "DeliverLogsStatus": "SUCCESS", "FlowLogId": "fl-aabbccdd112233445", "MaxAggregationInterval": 600, "FlowLogStatus": "ACTIVE", "LogGroupName": "FlowLogGroup", "ResourceId": "subnet-12345678901234567", "TrafficType": "ALL", "LogDestinationType": "cloud-watch-logs", "LogFormat": "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}" }, { "CreationTime": "2020-02-04T15:22:29.986Z", "DeliverLogsStatus": "SUCCESS", "FlowLogId": "fl-01234567890123456", "MaxAggregationInterval": 60, "FlowLogStatus": "ACTIVE", "ResourceId": "vpc-00112233445566778", "TrafficType": "ACCEPT", "LogDestinationType": "s3", "LogDestination": "arn:aws:s3:::my-flow-log-bucket/custom", "LogFormat": "${version} ${vpc-id} ${subnet-id} ${instance-id} ${interface-id} ${account-id} ${type} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${pkt-srcaddr} ${pkt-dstaddr} ${protocol} ${bytes} ${packets} ${start} ${end} ${action} ${tcp-flags} ${log-status}" } ] }

範例 2:描述流程日誌的子集

下列describe-flow-logs範例使用 篩選條件,僅顯示 Amazon CloudWatch Logs 中指定日誌群組中流程日誌的詳細資訊。

aws ec2 describe-flow-logs \ --filter "Name=log-group-name,Values=MyFlowLogs"
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeFlowLogs

PowerShell
for PowerShell 工具

範例 1:此範例描述一或多個具有日誌目的地類型 's3' 的流量日誌

Get-EC2FlowLog -Filter @{Name="log-destination-type";Values="s3"}

輸出:

CreationTime : 2/25/2019 9:07:36 PM DeliverLogsErrorMessage : DeliverLogsPermissionArn : DeliverLogsStatus : SUCCESS FlowLogId : fl-01b2e3d45f67f8901 FlowLogStatus : ACTIVE LogDestination : arn:aws:s3:::my-bucket-dd-tata LogDestinationType : s3 LogGroupName : ResourceId : eni-01d2dda3456b7e890 TrafficType : ALL
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DescribeFlowLogs