@@ -13,6 +13,10 @@ export type StaticSiteArgs = {
1313 * The ID of the hosted zone.
1414 */
1515 hostedZoneId ?: pulumi . Input < string > ;
16+ /**
17+ * ARN of the CloudFront viewer-request function.
18+ */
19+ viewerRequestFunctionArn ?: pulumi . Input < string > ;
1620 /**
1721 * A map of tags to assign to the resource.
1822 */
@@ -35,7 +39,7 @@ export class StaticSite extends pulumi.ComponentResource {
3539 super ( 'studion:StaticSite' , name , { } , opts ) ;
3640
3741 this . name = name ;
38- const { domain, hostedZoneId, tags } = args ;
42+ const { domain, hostedZoneId, viewerRequestFunctionArn , tags } = args ;
3943 const hasCustomDomain = domain && hostedZoneId ;
4044 if ( domain && ! hostedZoneId ) {
4145 throw new Error (
@@ -46,7 +50,11 @@ export class StaticSite extends pulumi.ComponentResource {
4650 this . certificate = this . createTlsCertificate ( { domain, hostedZoneId } ) ;
4751 }
4852 this . bucket = this . createPublicBucket ( { tags } ) ;
49- this . cloudfront = this . createCloudfrontDistribution ( { domain, tags } ) ;
53+ this . cloudfront = this . createCloudfrontDistribution ( {
54+ domain,
55+ viewerRequestFunctionArn,
56+ tags,
57+ } ) ;
5058 if ( hasCustomDomain ) {
5159 this . createDnsRecord ( { domain, hostedZoneId } ) ;
5260 }
@@ -123,8 +131,18 @@ export class StaticSite extends pulumi.ComponentResource {
123131
124132 private createCloudfrontDistribution ( {
125133 domain,
134+ viewerRequestFunctionArn,
126135 tags,
127- } : Pick < StaticSiteArgs , 'domain' | 'tags' > ) {
136+ } : Pick < StaticSiteArgs , 'domain' | 'viewerRequestFunctionArn' | 'tags' > ) {
137+ const functionAssociations = viewerRequestFunctionArn
138+ ? [
139+ {
140+ eventType : 'viewer-request' ,
141+ functionArn : viewerRequestFunctionArn ,
142+ } ,
143+ ]
144+ : [ ] ;
145+
128146 const cloudfront = new aws . cloudfront . Distribution (
129147 `${ this . name } -cloudfront` ,
130148 {
@@ -172,6 +190,7 @@ export class StaticSite extends pulumi.ComponentResource {
172190 cookies : { forward : 'none' } ,
173191 queryString : false ,
174192 } ,
193+ functionAssociations,
175194 } ,
176195 priceClass : 'PriceClass_100' ,
177196 restrictions : {
0 commit comments