Skip to content

Commit b9e7855

Browse files
authored
chore(lambda): resolve unable to reference AuthType from FunctionUrl (#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*
1 parent 7a4f865 commit b9e7855

File tree

9 files changed

+61
-48
lines changed

9 files changed

+61
-48
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/Stack1.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/Stack1.template.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
"Code": {
3838
"ZipFile": "def handler(event, context):\n return \"success\""
3939
},
40+
"Handler": "index.handler",
4041
"Role": {
4142
"Fn::GetAtt": [
4243
"IamAuthFunctionUrlsServiceRole35DF9DE0",
4344
"Arn"
4445
]
4546
},
46-
"Handler": "index.handler",
4747
"Runtime": "python3.10"
4848
},
4949
"DependsOn": [
@@ -99,13 +99,13 @@
9999
"Code": {
100100
"ZipFile": "def handler(event, context):\n return \"success\""
101101
},
102+
"Handler": "index.handler",
102103
"Role": {
103104
"Fn::GetAtt": [
104105
"NoAuthFunctionUrlsServiceRole7247E6F2",
105106
"Arn"
106107
]
107108
},
108-
"Handler": "index.handler",
109109
"Runtime": "python3.10"
110110
},
111111
"DependsOn": [
@@ -134,8 +134,8 @@
134134
"Arn"
135135
]
136136
},
137-
"Principal": "*",
138-
"FunctionUrlAuthType": "NONE"
137+
"FunctionUrlAuthType": "NONE",
138+
"Principal": "*"
139139
}
140140
},
141141
"CorsFunctionUrlsServiceRole6227B597": {
@@ -175,13 +175,13 @@
175175
"Code": {
176176
"ZipFile": "def handler(event, context):\n return \"success\""
177177
},
178+
"Handler": "index.handler",
178179
"Role": {
179180
"Fn::GetAtt": [
180181
"CorsFunctionUrlsServiceRole6227B597",
181182
"Arn"
182183
]
183184
},
184-
"Handler": "index.handler",
185185
"Runtime": "python3.10"
186186
},
187187
"DependsOn": [
@@ -192,19 +192,19 @@
192192
"Type": "AWS::Lambda::Url",
193193
"Properties": {
194194
"AuthType": "NONE",
195-
"TargetFunctionArn": {
196-
"Fn::GetAtt": [
197-
"CorsFunctionUrlsD81CF424",
198-
"Arn"
199-
]
200-
},
201195
"Cors": {
202196
"AllowMethods": [
203197
"*"
204198
],
205199
"AllowOrigins": [
206200
"https://example.com"
207201
]
202+
},
203+
"TargetFunctionArn": {
204+
"Fn::GetAtt": [
205+
"CorsFunctionUrlsD81CF424",
206+
"Arn"
207+
]
208208
}
209209
}
210210
},
@@ -218,8 +218,8 @@
218218
"Arn"
219219
]
220220
},
221-
"Principal": "*",
222-
"FunctionUrlAuthType": "NONE"
221+
"FunctionUrlAuthType": "NONE",
222+
"Principal": "*"
223223
}
224224
},
225225
"StreamFunctionUrlsServiceRoleAF76EC5D": {
@@ -259,13 +259,13 @@
259259
"Code": {
260260
"ZipFile": "def handler(event, context):\n return \"success\""
261261
},
262+
"Handler": "index.handler",
262263
"Role": {
263264
"Fn::GetAtt": [
264265
"StreamFunctionUrlsServiceRoleAF76EC5D",
265266
"Arn"
266267
]
267268
},
268-
"Handler": "index.handler",
269269
"Runtime": "python3.10"
270270
},
271271
"DependsOn": [
@@ -276,13 +276,13 @@
276276
"Type": "AWS::Lambda::Url",
277277
"Properties": {
278278
"AuthType": "NONE",
279+
"InvokeMode": "RESPONSE_STREAM",
279280
"TargetFunctionArn": {
280281
"Fn::GetAtt": [
281282
"StreamFunctionUrlsAAB55C9C",
282283
"Arn"
283284
]
284-
},
285-
"InvokeMode": "RESPONSE_STREAM"
285+
}
286286
}
287287
},
288288
"StreamFunctionUrlsinvokefunctionurl4FD8689D": {
@@ -295,8 +295,8 @@
295295
"Arn"
296296
]
297297
},
298-
"Principal": "*",
299-
"FunctionUrlAuthType": "NONE"
298+
"FunctionUrlAuthType": "NONE",
299+
"Principal": "*"
300300
}
301301
}
302302
},

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/manifest.json

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.function-url.js.snapshot/tree.json

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/aws-cdk-lib/aws-lambda/lib/function-url.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ export class FunctionUrl extends Resource implements IFunctionUrl {
202202
*/
203203
public readonly functionArn: string;
204204

205+
/**
206+
* The authentication type used for this Function URL
207+
*/
208+
public readonly authType: FunctionUrlAuthType;
209+
205210
private readonly function: IFunction;
206211

207212
constructor(scope: Construct, id: string, props: FunctionUrlProps) {
@@ -217,8 +222,10 @@ export class FunctionUrl extends Resource implements IFunctionUrl {
217222
? { targetFunction: props.function.version.lambda, alias: props.function }
218223
: { targetFunction: props.function, alias: undefined };
219224

225+
this.authType = props.authType ?? FunctionUrlAuthType.AWS_IAM;
226+
220227
const resource: CfnUrl = new CfnUrl(this, 'Resource', {
221-
authType: props.authType ?? FunctionUrlAuthType.AWS_IAM,
228+
authType: this.authType,
222229
cors: props.cors ? this.renderCors(props.cors) : undefined,
223230
invokeMode: props.invokeMode,
224231
targetFunctionArn: targetFunction.functionArn,

packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,13 @@ describe('FunctionUrl', () => {
231231
});
232232

233233
// WHEN
234-
fn.addFunctionUrl({
234+
const fnUrl = fn.addFunctionUrl({
235235
authType: lambda.FunctionUrlAuthType.NONE,
236236
invokeMode: lambda.InvokeMode.BUFFERED,
237237
});
238238

239+
expect(fnUrl.authType).toBe(lambda.FunctionUrlAuthType.NONE);
240+
239241
// THEN
240242
Template.fromStack(stack).hasResource('AWS::Lambda::Url', {
241243
Properties: {

0 commit comments

Comments
 (0)