-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathfunction.ts
More file actions
3179 lines (3073 loc) · 90 KB
/
Copy pathfunction.ts
File metadata and controls
3179 lines (3073 loc) · 90 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import fs from "fs";
import path from "path";
import crypto from "crypto";
import archiver from "archiver";
import type { Loader } from "esbuild";
import type { EsbuildOptions } from "../esbuild.js";
import { glob } from "glob";
import {
all,
asset,
ComponentResourceOptions,
interpolate,
Output,
output,
secret,
unsecret,
rootStackResource,
} from "@pulumi/pulumi";
import { bootstrap } from "./helpers/bootstrap.js";
import {
Duration,
DurationDays,
DurationMinutes,
toDays,
toSeconds,
} from "../duration.js";
import { Size, toMBs } from "../size.js";
import { Component, Prettify, Transform, transform } from "../component.js";
import { Link } from "../link.js";
import { VisibleError } from "../error.js";
import type { Input } from "../input.js";
import { logicalName, physicalName } from "../naming.js";
import { RETENTION } from "./logging.js";
import {
cloudwatch,
ecr,
getCallerIdentityOutput,
getPartitionOutput,
getRegionOutput,
iam,
lambda,
s3,
types,
} from "@pulumi/aws";
import { Permission, permission } from "./permission.js";
import { Vpc } from "./vpc.js";
import { Image } from "@pulumi/docker-build";
import { rpc } from "../rpc/rpc.js";
import { parseRoleArn, splitQualifiedFunctionArn } from "./helpers/arn.js";
import { RandomBytes } from "@pulumi/random";
import { lazy } from "../../util/lazy.js";
import { Efs } from "./efs.js";
import { FunctionEnvironmentUpdate } from "./providers/function-environment-update.js";
import { warnOnce } from "../../util/warn.js";
import {
normalizeRouteArgs,
RouterRouteArgs,
RouterRouteArgsDeprecated,
} from "./router.js";
import { KvRoutesUpdate } from "./providers/kv-routes-update.js";
import { KvKeys } from "./providers/kv-keys.js";
/**
* Helper type to define function ARN type
*/
export type FunctionArn = `arn:${string}` & {};
export type FunctionPermissionArgs = {
/**
* Configures whether the permission is allowed or denied.
* @default `"allow"`
* @example
* ```ts
* {
* effect: "deny"
* }
* ```
*/
effect?: "allow" | "deny";
/**
* The [IAM actions](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html#actions_table) that can be performed.
* @example
* ```js
* {
* actions: ["s3:*"]
* }
* ```
*/
actions: string[];
/**
* The resourcess specified using the [IAM ARN format](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html).
* @example
* ```js
* {
* resources: ["arn:aws:s3:::my-bucket/*"]
* }
* ```
*/
resources: Input<Input<string>[]>;
/**
* Configure specific conditions for when the policy is in effect.
*
* @example
* ```js
* {
* conditions: [
* {
* test: "StringEquals",
* variable: "s3:x-amz-server-side-encryption",
* values: ["AES256"]
* },
* {
* test: "IpAddress",
* variable: "aws:SourceIp",
* values: ["10.0.0.0/16"]
* }
* ]
* }
* ```
*/
conditions?: Input<
Input<{
/**
* Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate.
*/
test: Input<string>;
/**
* Name of a [Context Variable](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#AvailableKeys) to apply the condition to. Context variables may either be standard AWS variables starting with `aws:` or service-specific variables prefixed with the service name.
*/
variable: Input<string>;
/**
* The values to evaluate the condition against. If multiple values are provided, the condition matches if at least one of them applies. That is, AWS evaluates multiple values as though using an "OR" boolean operation.
*/
values: Input<Input<string>[]>;
}>[]
>;
};
interface FunctionUrlCorsArgs {
/**
* Allow cookies or other credentials in requests to the function URL.
* @default `false`
* @example
* ```js
* {
* url: {
* cors: {
* allowCredentials: true
* }
* }
* }
* ```
*/
allowCredentials?: Input<boolean>;
/**
* The HTTP headers that origins can include in requests to the function URL.
* @default `["*"]`
* @example
* ```js
* {
* url: {
* cors: {
* allowHeaders: ["date", "keep-alive", "x-custom-header"]
* }
* }
* }
* ```
*/
allowHeaders?: Input<Input<string>[]>;
/**
* The origins that can access the function URL.
* @default `["*"]`
* @example
* ```js
* {
* url: {
* cors: {
* allowOrigins: ["https://www.example.com", "http://localhost:60905"]
* }
* }
* }
* ```
* Or the wildcard for all origins.
* ```js
* {
* url: {
* cors: {
* allowOrigins: ["*"]
* }
* }
* }
* ```
*/
allowOrigins?: Input<Input<string>[]>;
/**
* The HTTP methods that are allowed when calling the function URL.
* @default `["*"]`
* @example
* ```js
* {
* url: {
* cors: {
* allowMethods: ["GET", "POST", "DELETE"]
* }
* }
* }
* ```
* Or the wildcard for all methods.
* ```js
* {
* url: {
* cors: {
* allowMethods: ["*"]
* }
* }
* }
* ```
*/
allowMethods?: Input<
Input<
"*" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT"
>[]
>;
/**
* The HTTP headers you want to expose in your function to an origin that calls the function URL.
* @default `[]`
* @example
* ```js
* {
* url: {
* cors: {
* exposeHeaders: ["date", "keep-alive", "x-custom-header"]
* }
* }
* }
* ```
*/
exposeHeaders?: Input<Input<string>[]>;
/**
* The maximum amount of time the browser can cache results of a preflight request. By
* default the browser doesn't cache the results. The maximum value is `86400 seconds` or `1 day`.
* @default `"0 seconds"`
* @example
* ```js
* {
* url: {
* cors: {
* maxAge: "1 day"
* }
* }
* }
* ```
*/
maxAge?: Input<Duration>;
}
export interface FunctionArgs {
/**
* Disable running this function [Live](/docs/live/) in `sst dev`.
* @deprecated Use `dev` instead.
* @default `true`
* @example
* ```js
* {
* live: false
* }
* ```
*/
live?: Input<false>;
/**
* Disable running this function [_Live_](/docs/live/) in `sst dev`.
*
* By default, the functions in your app are run locally in `sst dev`. To do this, a _stub_
* version of your function is deployed, instead of the real function.
*
* :::note
* In `sst dev` a _stub_ version of your function is deployed.
* :::
*
* This shows under the **Functions** tab in the multiplexer sidebar where your invocations
* are logged. You can turn this off by setting `dev` to `false`.
*
* Read more about [Live](/docs/live/) and [`sst dev`](/docs/reference/cli/#dev).
*
* @default `true`
* @example
* ```js
* {
* dev: false
* }
* ```
*/
dev?: Input<false>;
/**
* Configure the maximum number of retry attempts for this function when invoked
* asynchronously.
*
* This only affects asynchronous invocations of the function, ie. when subscribed to
* Topics, EventBuses, or Buckets. And not when directly invoking the function.
*
* Valid values are between 0 and 2.
*
* @default `2`
* @example
* ```js
* {
* retries: 0
* }
* ```
*/
retries?: Input<number>;
/**
* The name for the function.
*
* By default, the name is generated from the app name, stage name, and component name. This
* is displayed in the AWS Console for this function.
*
* :::caution
* To avoid the name from thrashing, you want to make sure that it includes the app and stage
* name.
* :::
*
* If you are going to set the name, you need to make sure:
* 1. It's unique across your app.
* 2. Uses the app and stage name, so it doesn't thrash when you deploy to different stages.
*
* Also, changing the name after your've deployed it once will create a new function and delete
* the old one.
*
* @example
* ```js
* {
* name: `${$app.name}-${$app.stage}-my-function`
* }
* ```
*/
name?: Input<string>;
/**
* A description for the function. This is displayed in the AWS Console.
* @example
* ```js
* {
* description: "Handler function for my nightly cron job."
* }
* ```
*/
description?: Input<string>;
/**
* The language runtime for the function.
*
* Node.js and Golang are officially supported. While, Python and Rust are
* community supported. Support for other runtimes are on the roadmap.
*
* @default `"nodejs24.x"`
*
* @example
* ```js
* {
* runtime: "nodejs24.x"
* }
* ```
*/
runtime?: Input<
| "nodejs18.x"
| "nodejs20.x"
| "nodejs22.x"
| "nodejs24.x"
| "go"
| "rust"
| "provided.al2"
| "provided.al2023"
| "python3.9"
| "python3.10"
| "python3.11"
| "python3.12"
| "python3.13"
| "python3.14"
>;
/**
* Path to the source code directory for the function. By default, the handler is
* bundled with [esbuild](https://esbuild.github.io/). Use `bundle` to skip bundling.
*
* :::caution
* Use `bundle` only when you want to bundle the function yourself.
* :::
*
* If the `bundle` option is specified, the `handler` needs to be in the root of the bundle.
*
* @example
*
* Here, the entire `packages/functions/src` directory is zipped. And the handler is
* in the `src` directory.
*
* ```js
* {
* bundle: "packages/functions/src",
* handler: "index.handler"
* }
* ```
*/
bundle?: Input<string>;
/**
* Path to the handler for the function.
*
* - For Node.js this is in the format `{path}/{file}.{method}`.
* - For Python this is also `{path}/{file}.{method}`.
* - For Golang this is `{path}` to the Go module.
* - For Rust this is `{path}` to the Rust crate.
*
* @example
*
* ##### Node.js
*
* For example with Node.js you might have.
*
* ```js
* {
* handler: "packages/functions/src/main.handler"
* }
* ```
*
* Where `packages/functions/src` is the path. And `main` is the file, where you might have
* a `main.ts` or `main.js`. And `handler` is the method exported in that file.
*
* :::note
* You don't need to specify the file extension.
* :::
*
* If `bundle` is specified, the handler needs to be in the root of the bundle directory.
*
* ```js
* {
* bundle: "packages/functions/src",
* handler: "index.handler"
* }
* ```
*
* ##### Python
*
* SST uses [uv](https://docs.astral.sh/uv/) to package the function.
* You need to have it installed.
*
* :::note
* You need uv installed for Python functions.
* :::
*
* Your handler must live in a [uv workspace](https://docs.astral.sh/uv/concepts/projects/workspaces/)
* with a `pyproject.toml`. Match the Python version to your Lambda runtime.
*
* ```toml title="pyproject.toml"
* [project]
* name = "my-project"
* requires-python = "==3.11.*"
* ```
*
* Install your packages before starting `sst dev`:
*
* ```bash
* uv sync --all-packages
* ```
*
* Use absolute imports within your package.
*
* ```python
* from mypackage.utils import helper
* ```
*
* Avoid relative imports — they can fail in Lambda. Make sure package directories have `__init__.py`.
*
* Access static files relative to `__file__`.
*
* ```python
* from pathlib import Path
* config = Path(__file__).parent / "config.json"
* ```
*
* For large dependencies like numpy or pandas, deploy as a container. See [`python.container`](#python-container).
*
* For common project layouts, check out the [Python examples](https://github.com/sst/sst/tree/dev/examples/python-layouts).
*
* ##### Golang
*
* For Golang the handler looks like.
*
* ```js
* {
* handler: "packages/functions/go/some_module"
* }
* ```
*
* Where `packages/functions/go/some_module` is the path to the Go module. This
* includes the name of the module in your `go.mod`. So in this case your `go.mod`
* might be in `packages/functions/go` and `some_module` is the name of the
* module.
*
* You can refer to [this example of deploying a Go function](/docs/examples/#aws-lambda-go).
*
* ##### Rust
*
* For Rust, the handler looks like.
*
* ```js
* {
* handler: "crates/api"
* }
* ```
*
* Where `crates/api` is the path to the Rust crate. This means there is a
* `Cargo.toml` file in `crates/api`, and the main() function handles the lambda.
*/
handler: Input<string>;
/**
* The maximum amount of time the function can run. The minimum timeout is 1 second and the maximum is 900 seconds or 15 minutes.
*
* :::note
* If a function is connected to another service, the request will time out based on the service's limits.
* :::
*
* While the maximum timeout is 15 minutes, if a function is connected to other
* services, it'll time out based on those limits.
*
* - API Gateway has a timeout of 30 seconds. So even if the function has a
* timeout of 15 minutes, the API request will time out after 30 seconds.
* - CloudFront has a default timeout of 60 seconds. You can have this limit
* increased by [contacting AWS Support](https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase).
*
* @default `"20 seconds"`
* @example
* ```js
* {
* timeout: "900 seconds"
* }
* ```
*/
timeout?: Input<DurationMinutes>;
/**
* The amount of memory allocated for the function. Takes values between 128 MB
* and 10240 MB in 1 MB increments. The amount of memory affects the amount of
* virtual CPU available to the function.
*
* :::tip
* While functions with less memory are cheaper, larger functions can process faster.
* And might end up being more [cost effective](https://docs.aws.amazon.com/lambda/latest/operatorguide/computing-power.html).
* :::
*
* @default `"1024 MB"`
* @example
* ```js
* {
* memory: "10240 MB"
* }
* ```
*/
memory?: Input<Size>;
/**
* The amount of ephemeral storage allocated for the function. This sets the ephemeral
* storage of the lambda function (/tmp). Must be between "512 MB" and "10240 MB" ("10 GB")
* in 1 MB increments.
*
* @default `"512 MB"`
* @example
* ```js
* {
* storage: "5 GB"
* }
* ```
*/
storage?: Input<Size>;
/**
* Key-value pairs of values that are set as [Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html).
* The keys need to:
* - Start with a letter
* - Be at least 2 characters long
* - Contain only letters, numbers, or underscores
*
* They can be accessed in your function using `process.env.<key>`.
*
* :::note
* The total size of the environment variables cannot exceed 4 KB.
* :::
*
* @example
*
* ```js
* {
* environment: {
* DEBUG: "true"
* }
* }
* ```
*/
environment?: Input<Record<string, Input<string>>>;
/**
* Permissions and the resources that the function needs to access. These permissions are
* used to create the function's IAM role.
*
* :::tip
* If you `link` the function to a resource, the permissions to access it are
* automatically added.
* :::
*
* @example
* Allow the function to read and write to an S3 bucket called `my-bucket`.
* ```js
* {
* permissions: [
* {
* actions: ["s3:GetObject", "s3:PutObject"],
* resources: ["arn:aws:s3:::my-bucket/*"]
* }
* ]
* }
* ```
*
* Allow the function to perform all actions on an S3 bucket called `my-bucket`.
*
* ```js
* {
* permissions: [
* {
* actions: ["s3:*"],
* resources: ["arn:aws:s3:::my-bucket/*"]
* }
* ]
* }
* ```
*
* Granting the function permissions to access all resources.
*
* ```js
* {
* permissions: [
* {
* actions: ["*"],
* resources: ["*"]
* }
* ]
* }
* ```
*/
permissions?: Input<Prettify<FunctionPermissionArgs>[]>;
/**
* Policies to attach to the function. These policies will be added to the
* function's IAM role.
*
* Attaching policies lets you grant a set of predefined permissions to the
* function without having to specify the permissions in the `permissions` prop.
*
* @example
* For example, allow the function to have read-only access to all resources.
* ```js
* {
* policies: ["arn:aws:iam::aws:policy/ReadOnlyAccess"]
* }
* ```
*/
policies?: Input<string[]>;
/**
* [Link resources](/docs/linking/) to your function. This will:
*
* 1. Grant the permissions needed to access the resources.
* 2. Allow you to access it in your function using the [SDK](/docs/reference/sdk/).
*
* @example
*
* Takes a list of components to link to the function.
*
* ```js
* {
* link: [bucket, stripeKey]
* }
* ```
*/
link?: Input<any[]>;
/**
* Enable streaming for the function.
*
* Streaming is supported with both Function URLs and API Gateway REST API (V1). It is
* not supported with API Gateway HTTP API (V2).
*
* You'll also need to [wrap your handler](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html) with `awslambda.streamifyResponse` to enable streaming.
*
* Check out the [AWS Lambda streaming example](/docs/examples/#aws-lambda-streaming) for more
* details.
*
* @default `false`
* @example
* ```js
* {
* streaming: true
* }
* ```
*/
streaming?: Input<boolean>;
/**
* @internal
*/
injections?: Input<string[]>;
/**
* Configure the function logs in CloudWatch. Or pass in `false` to disable writing logs.
* @default `{retention: "1 month", format: "text"}`
* @example
* ```js
* {
* logging: false
* }
* ```
* When set to `false`, the function is not given permissions to write to CloudWatch.
* Logs.
*/
logging?: Input<
| false
| {
/**
* The duration the function logs are kept in CloudWatch.
*
* Not application when an existing log group is provided.
*
* @default `1 month`
* @example
* ```js
* {
* logging: {
* retention: "forever"
* }
* }
* ```
*/
retention?: Input<keyof typeof RETENTION>;
/**
* Assigns the given CloudWatch log group name to the function. This allows you to pass in a previously created log group.
*
* By default, the function creates a new log group when it's created.
*
* @default Creates a log group
* @example
* ```js
* {
* logging: {
* logGroup: "/existing/log-group"
* }
* }
* ```
*/
logGroup?: Input<string>;
/**
* The [log format](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-advanced.html)
* of the Lambda function.
* @default `"text"`
* @example
* ```js
* {
* logging: {
* format: "json"
* }
* }
* ```
*/
format?: Input<"text" | "json">;
}
>;
/**
* The [architecture](https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)
* of the Lambda function.
*
* @default `"x86_64"`
* @example
* ```js
* {
* architecture: "arm64"
* }
* ```
*/
architecture?: Input<"x86_64" | "arm64">;
/**
* Assigns the given IAM role ARN to the function. This allows you to pass in a previously created role.
*
* :::caution
* When you pass in a role, the function will not update it if you add `permissions` or `link` resources.
* :::
*
* By default, the function creates a new IAM role when it's created. It'll update this role if you add `permissions` or `link` resources.
*
* However, if you pass in a role, you'll need to update it manually if you add `permissions` or `link` resources.
*
* @default Creates a new role
* @example
* ```js
* {
* role: "arn:aws:iam::123456789012:role/my-role"
* }
* ```
*/
role?: Input<string>;
/**
* Enable [Lambda function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html).
* These are dedicated endpoints for your Lambda functions.
* @default `false`
* @example
* Enable it with the default options.
* ```js
* {
* url: true
* }
* ```
*
* Configure the authorization and CORS settings for the endpoint.
* ```js
* {
* url: {
* authorization: "iam",
* cors: {
* allowOrigins: ['https://example.com']
* }
* }
* }
* ```
*/
url?: Input<
| boolean
| {
/**
* @deprecated The `url.router` prop is now the recommended way to serve your
* function URL through a `Router` component.
*/
route?: Prettify<RouterRouteArgsDeprecated>;
/**
* Serve your function URL through a `Router` instead of a standalone Function URL.
*
* By default, this component creates a direct function URL endpoint. But you might
* want to serve it through the distribution of your `Router` as a:
*
* - A path like `/api/users`
* - A subdomain like `api.example.com`
* - Or a combined pattern like `dev.example.com/api`
*
* @example
*
* To serve your function **from a path**, you'll need to configure the root domain
* in your `Router` component.
*
* ```ts title="sst.config.ts" {2}
* const router = new sst.aws.Router("Router", {
* domain: "example.com"
* });
* ```
*
* Now set the `router` and the `path` in the `url` prop.
*
* ```ts {4,5}
* {
* url: {
* router: {
* instance: router,
* path: "/api/users"
* }
* }
* }
* ```
*
* To serve your function **from a subdomain**, you'll need to configure the
* domain in your `Router` component to match both the root and the subdomain.
*
* ```ts title="sst.config.ts" {3,4}
* const router = new sst.aws.Router("Router", {
* domain: {
* name: "example.com",
* aliases: ["*.example.com"]
* }
* });
* ```
*
* Now set the `domain` in the `router` prop.
*
* ```ts {5}
* {
* url: {
* router: {
* instance: router,
* domain: "api.example.com"
* }
* }
* }
* ```
*
* Finally, to serve your function **from a combined pattern** like
* `dev.example.com/api`, you'll need to configure the domain in your `Router` to
* match the subdomain.
*
* ```ts title="sst.config.ts" {3,4}
* const router = new sst.aws.Router("Router", {
* domain: {
* name: "example.com",
* aliases: ["*.example.com"]
* }
* });
* ```
*
* And set the `domain` and the `path`.
*
* ```ts {5,6}
* {
* url: {
* router: {
* instance: router,
* domain: "dev.example.com",
* path: "/api/users"
* }
* }
* }
* ```
*/
router?: Prettify<RouterRouteArgs>;
/**
* The authorization used for the function URL. Supports [IAM authorization](https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html).
* @default `"none"`
* @example
* ```js
* {
* url: {
* authorization: "iam"
* }
* }
* ```
*/
authorization?: Input<"none" | "iam">;
/**
* Customize the CORS (Cross-origin resource sharing) settings for the function URL.
* @default `true`
* @example
* Disable CORS.
* ```js
* {
* url: {
* cors: false
* }
* }
* ```
* Only enable the `GET` and `POST` methods for `https://example.com`.
* ```js
* {
* url: {
* cors: {
* allowMethods: ["GET", "POST"],
* allowOrigins: ["https://example.com"]
* }
* }
* }
* ```
*/
cors?: Input<boolean | Prettify<FunctionUrlCorsArgs>>;
}
>;
/**
* Configure how your function is bundled.
*
* By default, SST will bundle your function
* code using [esbuild](https://esbuild.github.io/). This tree shakes your code to
* only include what's used; reducing the size of your function package and improving
* cold starts.
*/
nodejs?: Input<{
/**
* @internal
* Point to a file that exports a list of esbuild plugins to use.
*
* @example
* ```js
* {
* nodejs: {
* plugins: "./plugins.mjs"
* }
* }
* ```
*
* The path is relative to the location of the `sst.config.ts`.
*
* ```js title="plugins.mjs"
* import { somePlugin } from "some-plugin";
*
* export default [
* somePlugin()
* ];
* ```
*
* You'll also need to install the npm package of the plugin.
*/
plugins?: Input<string>;
/**
* Configure additional esbuild loaders for other file extensions. This is useful
* when your code is importing non-JS files like `.png`, `.css`, etc.
*
* @example
* ```js
* {
* nodejs: {
* loader: {
* ".png": "file"
* }
* }