Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lambda): resolve unable to reference AuthType from FunctionUrl #31590

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion packages/aws-cdk-lib/aws-lambda/lib/function-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ export class FunctionUrl extends Resource implements IFunctionUrl {

private readonly function: IFunction;

public readonly authType: FunctionUrlAuthType;

constructor(scope: Construct, id: string, props: FunctionUrlProps) {
super(scope, id);

Expand All @@ -217,8 +219,10 @@ export class FunctionUrl extends Resource implements IFunctionUrl {
? { targetFunction: props.function.version.lambda, alias: props.function }
: { targetFunction: props.function, alias: undefined };

this.authType = props.authType ?? FunctionUrlAuthType.AWS_IAM;

const resource: CfnUrl = new CfnUrl(this, 'Resource', {
authType: props.authType ?? FunctionUrlAuthType.AWS_IAM,
authType: this.authType,
cors: props.cors ? this.renderCors(props.cors) : undefined,
invokeMode: props.invokeMode,
targetFunctionArn: targetFunction.functionArn,
Expand Down
8 changes: 7 additions & 1 deletion packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@ describe('FunctionUrl', () => {
});

// WHEN
fn.addFunctionUrl({
const fnUrl = fn.addFunctionUrl({
authType: lambda.FunctionUrlAuthType.NONE,
invokeMode: lambda.InvokeMode.BUFFERED,
});

if (fnUrl.authType === lambda.FunctionUrlAuthType.NONE) {
; // ok
} else {
throw new Error('AuthType must be NONE');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use jest expect().

Suggested change
if (fnUrl.authType === lambda.FunctionUrlAuthType.NONE) {
; // ok
} else {
throw new Error('AuthType must be NONE');
}
expect(fnUrl.authType).toBe(lambda.FunctionUrlAuthType.NONE);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Also, I believe this PR should be a fix not a chore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no change in the resource being created, I don't think this fix needs an integ test, but if the maintainer thinks it does, I'll change it to a fix.


// THEN
Template.fromStack(stack).hasResource('AWS::Lambda::Url', {
Properties: {
Expand Down
Loading