@@ -401,6 +401,141 @@ export enum FlowLogMaxAggregationInterval {
401
401
402
402
}
403
403
404
+ /**
405
+ * The following table describes all of the available fields for a flow log record.
406
+ */
407
+ export class LogFormat {
408
+ /**
409
+ * The VPC Flow Logs version.
410
+ */
411
+ public static readonly VERSION = new LogFormat ( '${version}' ) ;
412
+
413
+ /**
414
+ * The AWS account ID of the owner of the source network interface for which traffic is recorded.
415
+ */
416
+ public static readonly ACCOUNT_ID = new LogFormat ( '${account-id}' ) ;
417
+
418
+ /**
419
+ * The ID of the network interface for which the traffic is recorded.
420
+ */
421
+ public static readonly INTERFACE_ID = new LogFormat ( '${interface-id' ) ;
422
+
423
+ /**
424
+ * The source address for incoming traffic, or the IPv4 or IPv6 address of the network interface
425
+ * for outgoing traffic on the network interface.
426
+ */
427
+ public static readonly SRC_ADDR = new LogFormat ( '${srcaddr}' ) ;
428
+
429
+ /**
430
+ * The destination address for outgoing traffic, or the IPv4 or IPv6 address of the network interface
431
+ * for incoming traffic on the network interface.
432
+ */
433
+ public static readonly DST_ADDR = new LogFormat ( '${dstaddr}' ) ;
434
+
435
+ /**
436
+ * The source port of the traffic.
437
+ */
438
+ public static readonly SRC_PORT = new LogFormat ( '${srcport}' ) ;
439
+
440
+ /**
441
+ * The destination port of the traffic.
442
+ */
443
+ public static readonly DST_PORT = new LogFormat ( '${dstport}' ) ;
444
+
445
+ /**
446
+ * The IANA protocol number of the traffic.
447
+ */
448
+ public static readonly PROTOCOL = new LogFormat ( '${protocol}' ) ;
449
+
450
+ /**
451
+ * The number of packets transferred during the flow.
452
+ */
453
+ public static readonly PACKETS = new LogFormat ( '${packets}' ) ;
454
+
455
+ /**
456
+ * The number of bytes transferred during the flow.
457
+ */
458
+ public static readonly BYTES = new LogFormat ( '${bytes}' ) ;
459
+
460
+ /**
461
+ * The packet-level (original) source IP address of the traffic.
462
+ */
463
+ public static readonly PKT_SRC_ADDR = new LogFormat ( '${pkt-srcaddr}' ) ;
464
+
465
+ /**
466
+ * The packet-level (original) destination IP address for the traffic.
467
+ */
468
+ public static readonly PKT_DST_ADDR = new LogFormat ( '${pkt-dstaddr}' ) ;
469
+
470
+ /**
471
+ * The Region that contains the network interface for which traffic is recorded.
472
+ */
473
+ public static readonly REGION = new LogFormat ( '${region}' ) ;
474
+
475
+ /**
476
+ * The ID of the Availability Zone that contains the network interface for which traffic is recorded.
477
+ */
478
+ public static readonly AZ_ID = new LogFormat ( '${az-id}' ) ;
479
+
480
+ /**
481
+ * The type of sublocation that's returned in the sublocation-id field.
482
+ */
483
+ public static readonly SUBLOCATION_TYPE = new LogFormat ( '${sublocation-type}' ) ;
484
+
485
+ /**
486
+ * The ID of the sublocation that contains the network interface for which traffic is recorded.
487
+ */
488
+ public static readonly SUBLOCATION_ID = new LogFormat ( '${sublocation-id}' ) ;
489
+
490
+ /**
491
+ * The name of the subset of IP address ranges for the pkt-srcaddr field,
492
+ * if the source IP address is for an AWS service.
493
+ */
494
+ public static readonly PKT_SRC_AWS_SERVICE = new LogFormat ( '${pkt-src-aws-service}' ) ;
495
+
496
+ /**
497
+ * The name of the subset of IP address ranges for the pkt-dstaddr field,
498
+ * if the destination IP address is for an AWS service.
499
+ */
500
+ public static readonly PKT_DST_AWS_SERVICE = new LogFormat ( '${pkt-dst-aws-service}' ) ;
501
+
502
+ /**
503
+ * The direction of the flow with respect to the interface where traffic is captured.
504
+ */
505
+ public static readonly FLOW_DIRECTION = new LogFormat ( '${flow-direction}' ) ;
506
+
507
+ /**
508
+ * The path that egress traffic takes to the destination.
509
+ */
510
+ public static readonly TRAFFIC_PATH = new LogFormat ( '${traffic-path}' ) ;
511
+
512
+ /**
513
+ * The default format.
514
+ */
515
+ public static readonly ALL_DEFAULT_FIELDS = new LogFormat ( '${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}' ) ;
516
+
517
+ /**
518
+ * A custom format string.
519
+ *
520
+ * Gives full control over the format string fragment.
521
+ */
522
+ public static custom ( formatString : string ) : LogFormat {
523
+ return new LogFormat ( formatString ) ;
524
+ }
525
+
526
+ /**
527
+ * A custom field name.
528
+ *
529
+ * If there is no ready-made constant for a new field yet, you can use this.
530
+ * The field name will automatically be wrapped in `${ ... }`.
531
+ */
532
+ public static field ( field : string ) : LogFormat {
533
+ return new LogFormat ( `\${${ field } }` ) ;
534
+ }
535
+
536
+ protected constructor ( public readonly value : string ) { }
537
+ }
538
+
404
539
/**
405
540
* Options to add a flow log to a VPC
406
541
*/
@@ -420,6 +555,18 @@ export interface FlowLogOptions {
420
555
*/
421
556
readonly destination ?: FlowLogDestination ;
422
557
558
+ /**
559
+ * The fields to include in the flow log record, in the order in which they should appear.
560
+ *
561
+ * If multiple fields are specified, they will be separated by spaces. For full control over the literal log format
562
+ * string, pass a single field constructed with `LogFormat.custom()`.
563
+ *
564
+ * See https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html#flow-log-records
565
+ *
566
+ * @default - default log format is used.
567
+ */
568
+ readonly logFormat ?: LogFormat [ ] ;
569
+
423
570
/**
424
571
* The maximum interval of time during which a flow of packets is captured
425
572
* and aggregated into a flow log record.
@@ -521,6 +668,12 @@ export class FlowLog extends FlowLogBase {
521
668
if ( this . bucket ) {
522
669
logDestination = this . keyPrefix ? this . bucket . arnForObjects ( this . keyPrefix ) : this . bucket . bucketArn ;
523
670
}
671
+ let customLogFormat : string | undefined = undefined ;
672
+ if ( props . logFormat ) {
673
+ customLogFormat = props . logFormat . map ( elm => {
674
+ return elm . value ;
675
+ } ) . join ( ' ' ) ;
676
+ }
524
677
525
678
const flowLog = new CfnFlowLog ( this , 'FlowLog' , {
526
679
destinationOptions : destinationConfig . destinationOptions ,
@@ -533,6 +686,7 @@ export class FlowLog extends FlowLogBase {
533
686
trafficType : props . trafficType
534
687
? props . trafficType
535
688
: FlowLogTrafficType . ALL ,
689
+ logFormat : customLogFormat ,
536
690
logDestination,
537
691
} ) ;
538
692
0 commit comments