@@ -16,6 +16,7 @@ class ServerlessLambdaEdgePreExistingCloudFront {
16
16
if ( functionObj . events ) {
17
17
functionObj . events . forEach ( async ( event ) => {
18
18
if ( event . preExistingCloudFront ) {
19
+ const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
19
20
const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
20
21
Id : event . preExistingCloudFront . distributionId
21
22
} )
@@ -24,13 +25,15 @@ class ServerlessLambdaEdgePreExistingCloudFront {
24
25
config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations = await this . associateFunction (
25
26
config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations ,
26
27
event ,
27
- functionObj . name
28
+ functionObj . name ,
29
+ functionArn
28
30
)
29
31
} else {
30
32
config . DistributionConfig . CacheBehaviors = await this . associateNonDefaultCacheBehaviors (
31
33
config . DistributionConfig . CacheBehaviors ,
32
34
event ,
33
- functionObj . name
35
+ functionObj . name ,
36
+ functionArn
34
37
)
35
38
}
36
39
@@ -39,6 +42,9 @@ class ServerlessLambdaEdgePreExistingCloudFront {
39
42
IfMatch : config . ETag ,
40
43
DistributionConfig : config . DistributionConfig
41
44
} )
45
+ this . serverless . cli . consoleLog (
46
+ `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
47
+ )
42
48
}
43
49
} )
44
50
}
@@ -47,26 +53,27 @@ class ServerlessLambdaEdgePreExistingCloudFront {
47
53
}
48
54
}
49
55
50
- async associateNonDefaultCacheBehaviors ( cacheBehaviors , event , functionName ) {
56
+ async associateNonDefaultCacheBehaviors ( cacheBehaviors , event , functionName , functionArn ) {
51
57
for ( let i = 0 ; i < cacheBehaviors . Items . length ; i ++ ) {
52
58
if ( event . preExistingCloudFront . pathPattern === cacheBehaviors . Items [ i ] . PathPattern ) {
53
59
cacheBehaviors . Items [ i ] . LambdaFunctionAssociations = await this . associateFunction (
54
60
cacheBehaviors . Items [ i ] . LambdaFunctionAssociations ,
55
61
event ,
56
- functionName
62
+ functionName ,
63
+ functionArn
57
64
)
58
65
}
59
66
}
60
67
return cacheBehaviors
61
68
}
62
69
63
- async associateFunction ( lambdaFunctionAssociations , event , functionName ) {
70
+ async associateFunction ( lambdaFunctionAssociations , event , functionName , functionArn ) {
64
71
const originals = lambdaFunctionAssociations . Items . filter (
65
72
( x ) => x . EventType !== event . preExistingCloudFront . eventType
66
73
)
67
74
lambdaFunctionAssociations . Items = originals
68
75
lambdaFunctionAssociations . Items . push ( {
69
- LambdaFunctionARN : await this . getlatestVersionLambdaArn ( functionName ) ,
76
+ LambdaFunctionARN : functionArn ,
70
77
IncludeBody : event . preExistingCloudFront . includeBody ,
71
78
EventType : event . preExistingCloudFront . eventType
72
79
} )
0 commit comments