File tree Expand file tree Collapse file tree 4 files changed +59
-3
lines changed
packages/aws-cdk-lib/aws-lambda Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -866,12 +866,15 @@ class LatestVersion extends FunctionBase implements IVersion {
866866
867867 public get versionRef ( ) : VersionReference {
868868 return {
869- functionArn : this . functionRef . functionArn ,
869+ functionArn : this . functionArn ,
870870 } ;
871871 }
872872
873- public get functionRef ( ) {
874- return this . lambda . functionRef ;
873+ public get functionRef ( ) : FunctionReference {
874+ return {
875+ functionArn : this . functionArn ,
876+ functionName : this . functionName ,
877+ } ;
875878 }
876879
877880 public get functionArn ( ) {
Original file line number Diff line number Diff line change @@ -657,4 +657,24 @@ describe('alias', () => {
657657 Qualifier : aliasName ,
658658 } ) ;
659659 } ) ;
660+
661+ test ( 'alias\' implementation of IFunctionRef should point to the alias' , ( ) => {
662+ // GIVEN
663+ const stack = new Stack ( ) ;
664+ const fn = new lambda . Function ( stack , 'MyLambda' , {
665+ code : new lambda . InlineCode ( 'hello()' ) ,
666+ handler : 'index.hello' ,
667+ runtime : lambda . Runtime . NODEJS_LATEST ,
668+ } ) ;
669+ const aliasName = 'prod' ;
670+
671+ // WHEN
672+ const alias = new lambda . Alias ( stack , 'Alias' , {
673+ aliasName,
674+ version : fn . currentVersion ,
675+ } ) ;
676+
677+ // THEN
678+ expect ( alias . functionRef . functionArn ) . toEqual ( alias . functionArn ) ;
679+ } ) ;
660680} ) ;
Original file line number Diff line number Diff line change @@ -2764,6 +2764,21 @@ describe('function', () => {
27642764 expect ( stack . resolve ( version2 . functionArn ) ) . toEqual ( expectedArn ) ;
27652765 } ) ;
27662766
2767+ test ( 'latestVersion functionRef ARN is the version ARN, not the plain ARN' , ( ) => {
2768+ // GIVEN
2769+ const stack = new cdk . Stack ( ) ;
2770+
2771+ // WHEN
2772+ const fn = new lambda . Function ( stack , 'MyLambda' , {
2773+ code : new lambda . InlineCode ( 'hello()' ) ,
2774+ handler : 'index.hello' ,
2775+ runtime : lambda . Runtime . NODEJS_LATEST ,
2776+ } ) ;
2777+
2778+ // THEN
2779+ expect ( fn . latestVersion . functionRef . functionArn ) . toEqual ( fn . latestVersion . functionArn ) ;
2780+ } ) ;
2781+
27672782 test ( 'default function with kmsKeyArn, environmentEncryption passed as props' , ( ) => {
27682783 // GIVEN
27692784 const stack = new cdk . Stack ( ) ;
Original file line number Diff line number Diff line change @@ -229,4 +229,22 @@ describe('lambda version', () => {
229229 version . addFunctionUrl ( ) ;
230230 } ) . toThrow ( / F u n c t i o n U r l c a n n o t b e u s e d w i t h a V e r s i o n / ) ;
231231 } ) ;
232+
233+ test ( 'version\'s implementation of IFunctionRef should point to the version' , ( ) => {
234+ // GIVEN
235+ const stack = new cdk . Stack ( ) ;
236+ const fn = new lambda . Function ( stack , 'MyLambda' , {
237+ code : new lambda . InlineCode ( 'hello()' ) ,
238+ handler : 'index.hello' ,
239+ runtime : lambda . Runtime . NODEJS_LATEST ,
240+ } ) ;
241+
242+ // WHEN
243+ const ver = new lambda . Version ( stack , 'Version' , {
244+ lambda : fn ,
245+ } ) ;
246+
247+ // THEN
248+ expect ( ver . functionRef . functionArn ) . toEqual ( ver . functionArn ) ;
249+ } ) ;
232250} ) ;
You can’t perform that action at this time.
0 commit comments