Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/aws-cdk-lib/aws-lambda/lib/function-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,15 @@ class LatestVersion extends FunctionBase implements IVersion {

public get versionRef(): VersionReference {
return {
functionArn: this.functionRef.functionArn,
functionArn: this.functionArn,
};
}

public get functionRef() {
return this.lambda.functionRef;
public get functionRef(): FunctionReference {
return {
functionArn: this.functionArn,
functionName: this.functionName,
};
}

public get functionArn() {
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,24 @@ describe('alias', () => {
Qualifier: aliasName,
});
});

test('alias\' implementation of IFunctionRef should point to the alias', () => {
// GIVEN
const stack = new Stack();
const fn = new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('hello()'),
handler: 'index.hello',
runtime: lambda.Runtime.NODEJS_LATEST,
});
const aliasName = 'prod';

// WHEN
const alias = new lambda.Alias(stack, 'Alias', {
aliasName,
version: fn.currentVersion,
});

// THEN
expect(alias.functionRef.functionArn).toEqual(alias.functionArn);
});
});
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2764,6 +2764,21 @@ describe('function', () => {
expect(stack.resolve(version2.functionArn)).toEqual(expectedArn);
});

test('latestVersion functionRef ARN is the version ARN, not the plain ARN', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const fn = new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('hello()'),
handler: 'index.hello',
runtime: lambda.Runtime.NODEJS_LATEST,
});

// THEN
expect(fn.latestVersion.functionRef.functionArn).toEqual(fn.latestVersion.functionArn);
});

test('default function with kmsKeyArn, environmentEncryption passed as props', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
18 changes: 18 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,22 @@ describe('lambda version', () => {
version.addFunctionUrl();
}).toThrow(/FunctionUrl cannot be used with a Version/);
});

test('version\'s implementation of IFunctionRef should point to the version', () => {
// GIVEN
const stack = new cdk.Stack();
const fn = new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('hello()'),
handler: 'index.hello',
runtime: lambda.Runtime.NODEJS_LATEST,
});

// WHEN
const ver = new lambda.Version(stack, 'Version', {
lambda: fn,
});

// THEN
expect(ver.functionRef.functionArn).toEqual(ver.functionArn);
});
});
Loading