Skip to content

Commit

Permalink
chore(lambda): resolve unable to reference AuthType from FunctionUrl (#…
Browse files Browse the repository at this point in the history
…31590)

### Reason for this change

I will resolve this issue: #31339 (comment). In the current FunctionURL implementation, there is no way to access AuthType, and therefore, when writing logic that depends on AuthType, there is no method to reference it.

### Description of changes

I will fix the construct to allow access to functionurl.AuthType

### Description of how you validated changes

adding unittest and integ-test re-run.

### Reason for Exemption:
The fix introduces no changes to the resources being created.

### Clarification Request:
This fix only makes the internal property authType of the L2 Construct publicly accessible, and does not introduce any differences in the created resources.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
watany-dev authored Oct 3, 2024
1 parent 7a4f865 commit b9e7855
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 48 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"IamAuthFunctionUrlsServiceRole35DF9DE0",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "python3.10"
},
"DependsOn": [
Expand Down Expand Up @@ -99,13 +99,13 @@
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"NoAuthFunctionUrlsServiceRole7247E6F2",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "python3.10"
},
"DependsOn": [
Expand Down Expand Up @@ -134,8 +134,8 @@
"Arn"
]
},
"Principal": "*",
"FunctionUrlAuthType": "NONE"
"FunctionUrlAuthType": "NONE",
"Principal": "*"
}
},
"CorsFunctionUrlsServiceRole6227B597": {
Expand Down Expand Up @@ -175,13 +175,13 @@
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"CorsFunctionUrlsServiceRole6227B597",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "python3.10"
},
"DependsOn": [
Expand All @@ -192,19 +192,19 @@
"Type": "AWS::Lambda::Url",
"Properties": {
"AuthType": "NONE",
"TargetFunctionArn": {
"Fn::GetAtt": [
"CorsFunctionUrlsD81CF424",
"Arn"
]
},
"Cors": {
"AllowMethods": [
"*"
],
"AllowOrigins": [
"https://example.com"
]
},
"TargetFunctionArn": {
"Fn::GetAtt": [
"CorsFunctionUrlsD81CF424",
"Arn"
]
}
}
},
Expand All @@ -218,8 +218,8 @@
"Arn"
]
},
"Principal": "*",
"FunctionUrlAuthType": "NONE"
"FunctionUrlAuthType": "NONE",
"Principal": "*"
}
},
"StreamFunctionUrlsServiceRoleAF76EC5D": {
Expand Down Expand Up @@ -259,13 +259,13 @@
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"StreamFunctionUrlsServiceRoleAF76EC5D",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "python3.10"
},
"DependsOn": [
Expand All @@ -276,13 +276,13 @@
"Type": "AWS::Lambda::Url",
"Properties": {
"AuthType": "NONE",
"InvokeMode": "RESPONSE_STREAM",
"TargetFunctionArn": {
"Fn::GetAtt": [
"StreamFunctionUrlsAAB55C9C",
"Arn"
]
},
"InvokeMode": "RESPONSE_STREAM"
}
}
},
"StreamFunctionUrlsinvokefunctionurl4FD8689D": {
Expand All @@ -295,8 +295,8 @@
"Arn"
]
},
"Principal": "*",
"FunctionUrlAuthType": "NONE"
"FunctionUrlAuthType": "NONE",
"Principal": "*"
}
}
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 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 @@ -202,6 +202,11 @@ export class FunctionUrl extends Resource implements IFunctionUrl {
*/
public readonly functionArn: string;

/**
* The authentication type used for this Function URL
*/
public readonly authType: FunctionUrlAuthType;

private readonly function: IFunction;

constructor(scope: Construct, id: string, props: FunctionUrlProps) {
Expand All @@ -217,8 +222,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
4 changes: 3 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,13 @@ describe('FunctionUrl', () => {
});

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

expect(fnUrl.authType).toBe(lambda.FunctionUrlAuthType.NONE);

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

0 comments on commit b9e7855

Please sign in to comment.