@@ -16,6 +16,7 @@ class ServerlessLambdaEdgePreExistingCloudFront {
1616 if ( functionObj . events ) {
1717 functionObj . events . forEach ( async ( event ) => {
1818 if ( event . preExistingCloudFront ) {
19+ const functionArn = await this . getlatestVersionLambdaArn ( functionObj . name )
1920 const config = await this . provider . request ( 'CloudFront' , 'getDistribution' , {
2021 Id : event . preExistingCloudFront . distributionId
2122 } )
@@ -24,13 +25,15 @@ class ServerlessLambdaEdgePreExistingCloudFront {
2425 config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations = await this . associateFunction (
2526 config . DistributionConfig . DefaultCacheBehavior . LambdaFunctionAssociations ,
2627 event ,
27- functionObj . name
28+ functionObj . name ,
29+ functionArn
2830 )
2931 } else {
3032 config . DistributionConfig . CacheBehaviors = await this . associateNonDefaultCacheBehaviors (
3133 config . DistributionConfig . CacheBehaviors ,
3234 event ,
33- functionObj . name
35+ functionObj . name ,
36+ functionArn
3437 )
3538 }
3639
@@ -39,6 +42,9 @@ class ServerlessLambdaEdgePreExistingCloudFront {
3942 IfMatch : config . ETag ,
4043 DistributionConfig : config . DistributionConfig
4144 } )
45+ this . serverless . cli . consoleLog (
46+ `${ functionArn } is associating to ${ event . preExistingCloudFront . distributionId } CloudFront Distribution. waiting for deployed status.`
47+ )
4248 }
4349 } )
4450 }
@@ -47,26 +53,27 @@ class ServerlessLambdaEdgePreExistingCloudFront {
4753 }
4854 }
4955
50- async associateNonDefaultCacheBehaviors ( cacheBehaviors , event , functionName ) {
56+ async associateNonDefaultCacheBehaviors ( cacheBehaviors , event , functionName , functionArn ) {
5157 for ( let i = 0 ; i < cacheBehaviors . Items . length ; i ++ ) {
5258 if ( event . preExistingCloudFront . pathPattern === cacheBehaviors . Items [ i ] . PathPattern ) {
5359 cacheBehaviors . Items [ i ] . LambdaFunctionAssociations = await this . associateFunction (
5460 cacheBehaviors . Items [ i ] . LambdaFunctionAssociations ,
5561 event ,
56- functionName
62+ functionName ,
63+ functionArn
5764 )
5865 }
5966 }
6067 return cacheBehaviors
6168 }
6269
63- async associateFunction ( lambdaFunctionAssociations , event , functionName ) {
70+ async associateFunction ( lambdaFunctionAssociations , event , functionName , functionArn ) {
6471 const originals = lambdaFunctionAssociations . Items . filter (
6572 ( x ) => x . EventType !== event . preExistingCloudFront . eventType
6673 )
6774 lambdaFunctionAssociations . Items = originals
6875 lambdaFunctionAssociations . Items . push ( {
69- LambdaFunctionARN : await this . getlatestVersionLambdaArn ( functionName ) ,
76+ LambdaFunctionARN : functionArn ,
7077 IncludeBody : event . preExistingCloudFront . includeBody ,
7178 EventType : event . preExistingCloudFront . eventType
7279 } )
0 commit comments