Skip to content

Commit 8a19a42

Browse files
authored
Add CDN Log Delivery source (#16299)
I tried using Pulumi import but it'd not get the properties and then it'd fail - Using lookup pulumi is able to reference the resource anyway without bringing it into state.
1 parent 8949e3a commit 8a19a42

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

infrastructure/Pulumi.www-production.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ config:
1515
www.pulumi.com:websiteDomain: www.pulumi.com
1616
www.pulumi.com:websiteLogsBucketName: www-prod.pulumi.com-website-logs
1717
www.pulumi.com:answersStack: "pulumi/answers/production"
18+
www.pulumi.com:cdnLogDeliverySourceName: "CreatedByCloudFront-E3PRSXO1BZJEEY"

infrastructure/index.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6872
const 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

Comments
 (0)