@@ -63,6 +63,10 @@ const config = {
6363
6464 // Enable data warehouse access to CloudFront logs
6565 enableDataWarehouseAccess : stackConfig . getBoolean ( "enableDataWarehouseAccess" ) || false ,
66+
67+ // cdnLogDeliverySourceName is the name of the CloudFront-created log delivery source.
68+ // If not set, CDN log delivery configuration will be skipped.
69+ cdnLogDeliverySourceName : stackConfig . get ( "cdnLogDeliverySourceName" ) || undefined ,
6670} ;
6771
6872const aiAppStack = new pulumi . StackReference ( 'pulumi/pulumi-ai-app-infra/prod' ) ;
@@ -800,37 +804,40 @@ const cdn = new aws.cloudfront.Distribution(
800804 } ,
801805) ;
802806
803- // Configure CloudFront v2 logging to S3 using CloudWatch Log Delivery
804807// https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-infrastructure-V2-S3.html
805- const cdnLogDeliverySource = new aws . cloudwatch . LogDeliverySource ( "cdn-log-delivery-source" , {
806- region : "us-east-1" ,
807- name : pulumi . interpolate `${ cdn . id } -access-logs` ,
808- logType : "ACCESS_LOGS" ,
809- resourceArn : cdn . arn ,
810- } ) ;
811808
812- const cdnLogDeliveryDestination = new aws . cloudwatch . LogDeliveryDestination ( "cdn-log-delivery-destination" , {
813- region : "us-east-1" ,
814- name : "cdn-s3-destination" ,
815- outputFormat : "parquet" ,
816- deliveryDestinationConfiguration : {
817- destinationResourceArn : websiteLogsBucket . arn ,
818- } ,
819- } , {
820- dependsOn : [ logsBucketPolicy , logsBucketOwnershipControls ] ,
821- } ) ;
809+ // Configure CDN log delivery if cdnLogDeliverySourceName is set
810+ if ( config . cdnLogDeliverySourceName ) {
811+ // Reference the CloudFront-created log delivery source
812+ // Resource name in Pulumi state: cloudfront_logs
813+ const cdnLogDeliverySource = aws . cloudwatch . LogDeliverySource . get (
814+ config . cdnLogDeliverySourceName ,
815+ "cloudfront_logs"
816+ ) ;
822817
823- const cdnLogDelivery = new aws . cloudwatch . LogDelivery ( "cdn-log-delivery" , {
824- region : "us-east-1" ,
825- deliverySourceName : cdnLogDeliverySource . name ,
826- deliveryDestinationArn : cdnLogDeliveryDestination . arn ,
827- s3DeliveryConfigurations : [ {
828- suffixPath : pulumi . all ( [ aws . getCallerIdentity ( ) , cdn . id ] ) . apply ( ( [ caller , distributionId ] ) =>
829- `${ config . websiteDomain } /${ caller . accountId } /${ distributionId } /{yyyy}/{MM}/{dd}/{HH}`
830- ) ,
831- enableHiveCompatiblePath : false ,
832- } ] ,
833- } ) ;
818+ const cdnLogDeliveryDestination = new aws . cloudwatch . LogDeliveryDestination ( "cdn-log-delivery-destination" , {
819+ region : "us-east-1" ,
820+ name : "cdn-s3-destination" ,
821+ outputFormat : "parquet" ,
822+ deliveryDestinationConfiguration : {
823+ destinationResourceArn : websiteLogsBucket . arn ,
824+ } ,
825+ } , {
826+ dependsOn : [ logsBucketPolicy , logsBucketOwnershipControls ] ,
827+ } ) ;
828+
829+ const cdnLogDelivery = new aws . cloudwatch . LogDelivery ( "cdn-log-delivery" , {
830+ region : "us-east-1" ,
831+ deliverySourceName : cdnLogDeliverySource . name ,
832+ deliveryDestinationArn : cdnLogDeliveryDestination . arn ,
833+ s3DeliveryConfigurations : [ {
834+ suffixPath : pulumi . all ( [ aws . getCallerIdentity ( ) , cdn . id ] ) . apply ( ( [ caller , distributionId ] ) =>
835+ `${ config . websiteDomain } /${ caller . accountId } /${ distributionId } /{yyyy}/{MM}/{dd}/{HH}`
836+ ) ,
837+ enableHiveCompatiblePath : false ,
838+ } ] ,
839+ } ) ;
840+ }
834841
835842// Split a domain name into its subdomain and parent domain names.
836843// e.g. "www.example.com" => "www", "example.com".
0 commit comments