You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function URL is a dedicated HTTP(S) endpoint for your Lambda function. When you create a function URL, Lambda automatically generates a unique URL endpoint for you. Function URLs can be created for the latest version Lambda Functions, or Function Aliases (but not for Versions).
345
+
346
+
Function URLs are dual stack-enabled, supporting IPv4 and IPv6, and cross-origin resource sharing (CORS) configuration. After you configure a function URL for your function, you can invoke your function through its HTTP(S) endpoint via a web browser, curl, Postman, or any HTTP client. To invoke a function using IAM authentication your HTTP client must support SigV4 signing.
347
+
348
+
See the [Invoking Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html) section of the AWS Lambda Developer Guide
349
+
for more information on the input and output payloads of Functions invoked in this way.
350
+
351
+
### IAM-authenticated Function URLs
352
+
353
+
To create a Function URL which can be called by an IAM identity, call `addFunctionUrl()`, followed by `grantInvokeFunctionUrl()`:
354
+
355
+
```ts
356
+
// Can be a Function or an Alias
357
+
declareconst fn:lambda.Function;
358
+
declareconst myRole:iam.Role;
359
+
360
+
const fnUrl =fn.addFunctionUrl();
361
+
fnUrl.grantInvokeUrl(myRole);
362
+
363
+
newCfnOutput(this, 'TheUrl', {
364
+
// The .url attributes will return the unique Function URL
365
+
value: fnUrl.url,
366
+
});
367
+
```
368
+
369
+
Calls to this URL need to be signed with SigV4.
370
+
371
+
### Anonymous Function URLs
372
+
373
+
To create a Function URL which can be called anonymously, pass `authType: FunctionUrlAuthType.NONE` to `addFunctionUrl()`:
374
+
375
+
```ts
376
+
// Can be a Function or an Alias
377
+
declareconst fn:lambda.Function;
378
+
379
+
const fnUrl =fn.addFunctionUrl({
380
+
authType: lambda.FunctionUrlAuthType.NONE,
381
+
});
382
+
383
+
newCfnOutput(this, 'TheUrl', {
384
+
value: fnUrl.url,
385
+
});
386
+
```
387
+
388
+
### CORS configuration for Function URLs
389
+
390
+
If you want your Function URLs to be invokable from a web page in browser, you
391
+
will need to configure cross-origin resource sharing to allow the call (if you do
392
+
not do this, your browser will refuse to make the call):
393
+
394
+
```ts
395
+
declareconst fn:lambda.Function;
396
+
397
+
fn.addFunctionUrl({
398
+
authType: lambda.FunctionUrlAuthType.NONE,
399
+
cors: {
400
+
// Allow this to be called from websites on https://example.com.
401
+
// Can also be ['*'] to allow all domain.
402
+
allowedOrigins: ['https://example.com'],
403
+
404
+
// More options are possible here, see the documentation for FunctionUrlCorsOptions
405
+
},
406
+
});
407
+
```
408
+
342
409
## Layers
343
410
344
411
The `lambda.LayerVersion` class can be used to define Lambda layers and manage
thrownewError('Cannot modify permission to lambda function. Function is either imported or $LATEST version.\n'
422
-
+'If the function is imported from the same account use `fromFunctionAttributes()` API with the `sameEnvironment` flag.\n'
423
-
+'If the function is imported from a different account and already has the correct permissions use `fromFunctionAttributes()` API with the `skipPermissions` flag.');
thrownewError('Cannot modify permission to lambda function. Function is either imported or $LATEST version.\n'
523
+
+'If the function is imported from the same account use `fromFunctionAttributes()` API with the `sameEnvironment` flag.\n'
524
+
+'If the function is imported from a different account and already has the correct permissions use `fromFunctionAttributes()` API with the `skipPermissions` flag.');
0 commit comments