/
types.d.ts
2116 lines (1889 loc) · 58.1 KB
/
types.d.ts
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
// deno-lint-ignore-file
// Type definitions for AWS Lambda 8.10
// Project: http://docs.aws.amazon.com/lambda
// Definitions by: James Darbyshire <https://github.com/darbio>
// Michael Skarum <https://github.com/skarum>
// Stef Heyenrath <https://github.com/StefH>
// Rich Buggy <https://github.com/buggy>
// Yoriki Yamaguchi <https://github.com/y13i>
// wwwy3y3 <https://github.com/wwwy3y3>
// Ishaan Malhi <https://github.com/OrthoDex>
// Michael Marner <https://github.com/MichaelMarner>
// Daniel Cottone <https://github.com/daniel-cottone>
// Kostya Misura <https://github.com/kostya-misura>
// Markus Tacker <https://github.com/coderbyheart>
// Palmi Valgeirsson <https://github.com/palmithor>
// Danilo Raisi <https://github.com/daniloraisi>
// Simon Buchan <https://github.com/simonbuchan>
// David Hayden <https://github.com/Haydabase>
// Chris Redekop <https://github.com/repl-chris>
// Aneil Mallavarapu <https://github.com/aneilbaboo>
// Jeremy Nagel <https://github.com/jeznag>
// Louis Larry <https://github.com/louislarry>
// Daniel Papukchiev <https://github.com/dpapukchiev>
// Oliver Hookins <https://github.com/ohookins>
// Trevor Leach <https://github.com/trevor-leach>
// James Gregory <https://github.com/jagregory>
// Erik Dalén <https://github.com/dalen>
// Loïk Gaonac'h <https://github.com/loikg>
// Roberto Zen <https://github.com/skyzenr>
// Grzegorz Redlicki <https://github.com/redlickigrzegorz>
// Juan Carbonel <https://github.com/juancarbonel>
// Peter McIntyre <https://github.com/pwmcintyre>
// Alex Bolenok <https://github.com/alex-bolenok-centralreach>
// Marian Zange <https://github.com/marianzange>
// Alexander Pepper <https://github.com/apepper>
// Alessandro Palumbo <https://github.com/apalumbo>
// Sachin Shekhar <https://github.com/SachinShekhar>
// Ivan Martos <https://github.com/ivanmartos>
// Zach Anthony <https://github.com/zach-anthony>
// Peter Savnik <https://github.com/savnik>
// Sven Milewski <https://github.com/svenmilewski>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TODO:
// ElastiCache section just describes using lambdas in an ElastiCache context (VPC issues, etc.)
// EC2 events are delivered using cloudwatch events...
export as namespace AWSLambda;
/**
* The interface that AWS Lambda will invoke your handler with.
* There are more specialized types for many cases where AWS services
* invoke your lambda, but you can directly use this type for when you are invoking
* your lambda directly.
*
* See tme {@link http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html AWS documentation}
* for more information about the runtime behavior, and the
* {@link https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/ AWS Blog post}
* introducing the async handler behavior in the 8.10 runtime.
*
* @example <caption>Defining a custom handler type</caption>
* import { Handler } from 'aws-lambda'
*
* interface NameEvent {
* fullName: string
* }
* interface NameResult {
* firstName: string
* middleNames: string
* lastName: string
* }
* type PersonHandler = Handler<NameEvent, NameResult>
*
* export const handler: PersonHandler = async (event) => {
* const names = event.fullName.split(' ')
* const firstName = names.shift()
* const lastName = names.pop()
* return { firstName, middleNames: names, lastName }
* }
*
* @example <caption>Logs the contents of the event object and returns the location of the logs</caption>
* import { Handler } from 'aws-lambda'
*
* export const handler: Handler = async (event, context) => {
* console.log("EVENT: \n" + JSON.stringify(event, null, 2))
* return context.logStreamName
* }
*
* @example <caption>AWS SDK with Async Function and Promises</caption>
* import { Handler } from 'aws-lambda'
* import AWS from 'aws-sdk'
*
* const s3 = new AWS.S3()
*
* export const handler: Handler = async (event) => {
* const response = await s3.listBuckets().promise()
* return response?.Buckets.map((bucket) => bucket.Name)
* }
*
* @example <caption>HTTP Request with Callback</caption>
* import { Handler } from 'aws-lambda'
* import https from 'https'
*
* let url = "https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"
*
* export const handler: Handler<void, number> = (event, context, callback) => {
* https.get(url, (res) => {
* callback(null, res.statusCode)
* }).on('error', (e) => {
* callback(Error(e))
* })
* }
*
* @param event
* Parsed JSON data in the lambda request payload. For an AWS service triggered
* lambda this should be in the format of a type ending in Event, for example the
* S3Handler receives an event of type S3Event.
* @param context
* Runtime contextual information of the current invocation, for example the caller
* identity, available memory and time remaining, legacy completion callbacks, and
* a mutable property controlling when the lambda execution completes.
* @param callback
* NodeJS-style completion callback that the AWS Lambda runtime will provide that can
* be used to provide the lambda result payload value, or any execution error. Can
* instead return a promise that resolves with the result payload value or rejects
* with the execution error.
* @return
* A promise that resolves with the lambda result payload value, or rejects with the
* execution error. Note that if you implement your handler as an async function,
* you will automatically return a promise that will resolve with a returned value,
* or reject with a thrown value.
*/
export type Handler<TEvent = any, TResult = any> = (
event: TEvent,
context: Context,
) => Promise<TResult>;
/**
* {@link Handler} context parameter.
* See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
*/
export interface Context {
callbackWaitsForEmptyEventLoop: boolean;
functionName: string;
functionVersion: string;
invokedFunctionArn: string;
memoryLimitInMB: string;
awsRequestId: string;
logGroupName: string;
logStreamName: string;
identity?: CognitoIdentity;
clientContext?: ClientContext;
getRemainingTimeInMillis(): number;
// Functions for compatibility with earlier Node.js Runtime v0.10.42
// No longer documented, so they are deprecated, but they still work
// as of the 12.x runtime, so they are not removed from the types.
/** @deprecated Use handler callback or promise result */
done(error?: Error, result?: any): void;
/** @deprecated Use handler callback with first argument or reject a promise result */
fail(error: Error | string): void;
/** @deprecated Use handler callback with second argument or resolve a promise result */
succeed(messageOrObject: any): void;
// Unclear what behavior this is supposed to have, I couldn't find any still extant reference,
// and it behaves like the above, ignoring the object parameter.
/** @deprecated Use handler callback or promise result */
succeed(message: string, object: any): void;
}
export interface CognitoIdentity {
cognitoIdentityId: string;
cognitoIdentityPoolId: string;
}
export interface ClientContext {
client: ClientContextClient;
Custom?: any;
env: ClientContextEnv;
}
export interface ClientContextClient {
installationId: string;
appTitle: string;
appVersionName: string;
appVersionCode: string;
appPackageName: string;
}
export interface ClientContextEnv {
platformVersion: string;
platform: string;
make: string;
model: string;
locale: string;
}
// Poorly documented, but API Gateway will just fail internally if
// the context type does not match this.
// Note that although non-string types will be accepted, they will be
// coerced to strings on the other side.
export interface APIGatewayAuthorizerResultContext {
[name: string]: string | number | boolean | null | undefined;
}
// Default authorizer type, prefer using a specific type with the "...WithAuthorizer..." variant types.
// Note that this doesn't have to be a context from a custom lambda outhorizer, AWS also has a cognito
// authorizer type and could add more, so the property won't always be a string.
export type APIGatewayEventDefaultAuthorizerContext = undefined | null | {
[name: string]: any;
};
export type APIGatewayEventRequestContext =
APIGatewayEventRequestContextWithAuthorizer<
APIGatewayEventDefaultAuthorizerContext
>;
// The requestContext property of both request authorizer and proxy integration events.
export interface APIGatewayEventRequestContextWithAuthorizer<
TAuthorizerContext,
> {
accountId: string;
apiId: string;
// This one is a bit confusing: it is not actually present in authorizer calls
// and proxy calls without an authorizer. We model this by allowing undefined in the type,
// since it ends up the same and avoids breaking users that are testing the property.
// This lets us allow parameterizing the authorizer for proxy events that know what authorizer
// context values they have.
authorizer: TAuthorizerContext;
connectedAt?: number;
connectionId?: string;
domainName?: string;
domainPrefix?: string;
eventType?: string;
extendedRequestId?: string;
protocol: string;
httpMethod: string;
identity: APIGatewayEventIdentity;
messageDirection?: string;
messageId?: string | null;
path: string;
stage: string;
requestId: string;
requestTime?: string;
requestTimeEpoch: number;
resourceId: string;
resourcePath: string;
routeKey?: string;
}
export interface APIGatewayEventIdentity {
accessKey: string | null;
accountId: string | null;
apiKey: string | null;
apiKeyId: string | null;
caller: string | null;
cognitoAuthenticationProvider: string | null;
cognitoAuthenticationType: string | null;
cognitoIdentityId: string | null;
cognitoIdentityPoolId: string | null;
principalOrgId: string | null;
sourceIp: string;
user: string | null;
userAgent: string | null;
userArn: string | null;
}
/**
* CloudFront events
* http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html
* Bear in mind that the "example" event structure in the page above includes
* both an S3 and a Custom origin, which is not strictly allowed. Only one
* of these per event may be present.
*/
export interface CloudFrontHeaders {
[name: string]: Array<{
key?: string;
value: string;
}>;
}
export type CloudFrontOrigin =
| { s3: CloudFrontS3Origin; custom?: never }
| { custom: CloudFrontCustomOrigin; s3?: never };
export interface CloudFrontCustomOrigin {
customHeaders: CloudFrontHeaders;
domainName: string;
keepaliveTimeout: number;
path: string;
port: number;
protocol: "http" | "https";
readTimeout: number;
sslProtocols: string[];
}
export interface CloudFrontS3Origin {
authMethod: "origin-access-identity" | "none";
customHeaders: CloudFrontHeaders;
domainName: string;
path: string;
region: string;
}
export interface CloudFrontResponse {
status: string;
statusDescription: string;
headers: CloudFrontHeaders;
}
export interface CloudFrontRequest {
body?: {
action: "read-only" | "replace";
data: string;
encoding: "base64" | "text";
readonly inputTruncated: boolean;
};
readonly clientIp: string;
readonly method: string;
uri: string;
querystring: string;
headers: CloudFrontHeaders;
origin?: CloudFrontOrigin;
}
export interface CloudFrontEvent {
config: {
readonly distributionDomainName: string;
readonly distributionId: string;
readonly eventType:
| "origin-request"
| "origin-response"
| "viewer-request"
| "viewer-response";
readonly requestId: string;
};
}
/**
* Generated HTTP response in viewer request event or origin request event
*
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses-in-requests.html#lambda-generating-http-responses-object
*/
export interface CloudFrontResultResponse {
status: string;
statusDescription?: string;
headers?: CloudFrontHeaders;
bodyEncoding?: "text" | "base64";
body?: string;
}
export type ALBHandler = Handler<ALBEvent, ALBResult>;
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
export interface ALBEventRequestContext {
elb: {
targetGroupArn: string;
};
}
export interface ALBEventQueryStringParameters {
[name: string]: string | undefined;
}
export interface ALBEventHeaders {
[name: string]: string | undefined;
}
export interface ALBEventMultiValueHeaders {
[name: string]: string[] | undefined;
}
export interface ALBEventMultiValueQueryStringParameters {
[name: string]: string[] | undefined;
}
export interface ALBEvent {
requestContext: ALBEventRequestContext;
httpMethod: string;
path: string;
queryStringParameters?: ALBEventQueryStringParameters; // URL encoded
headers?: ALBEventHeaders;
multiValueQueryStringParameters?: ALBEventMultiValueQueryStringParameters; // URL encoded
multiValueHeaders?: ALBEventMultiValueHeaders;
body: string | null;
isBase64Encoded: boolean;
}
export interface ALBResult {
statusCode: number;
statusDescription?: string;
headers?: { [header: string]: boolean | number | string };
multiValueHeaders?: { [header: string]: Array<boolean | number | string> };
body?: string;
isBase64Encoded?: boolean;
}
export type APIGatewayAuthorizerHandler = Handler<
APIGatewayAuthorizerEvent,
APIGatewayAuthorizerResult
>;
export type APIGatewayAuthorizerWithContextHandler<
TAuthorizerContext extends APIGatewayAuthorizerResultContext,
> = Handler<
APIGatewayAuthorizerEvent,
APIGatewayAuthorizerWithContextResult<TAuthorizerContext>
>;
export type APIGatewayTokenAuthorizerHandler = Handler<
APIGatewayTokenAuthorizerEvent,
APIGatewayAuthorizerResult
>;
export type APIGatewayTokenAuthorizerWithContextHandler<
TAuthorizerContext extends APIGatewayAuthorizerResultContext,
> = Handler<
APIGatewayTokenAuthorizerEvent,
APIGatewayAuthorizerWithContextResult<TAuthorizerContext>
>;
export type APIGatewayRequestAuthorizerHandler = Handler<
APIGatewayRequestAuthorizerEvent,
APIGatewayAuthorizerResult
>;
export type APIGatewayRequestAuthorizerWithContextHandler<
TAuthorizerContext extends APIGatewayAuthorizerResultContext,
> = Handler<
APIGatewayRequestAuthorizerEvent,
APIGatewayAuthorizerWithContextResult<TAuthorizerContext>
>;
export type APIGatewayAuthorizerEvent =
| APIGatewayTokenAuthorizerEvent
| APIGatewayRequestAuthorizerEvent;
export interface APIGatewayTokenAuthorizerEvent {
type: "TOKEN";
methodArn: string;
authorizationToken: string;
}
export interface APIGatewayRequestAuthorizerEventHeaders {
[name: string]: string | undefined;
}
export interface APIGatewayRequestAuthorizerEventMultiValueHeaders {
[name: string]: string[] | undefined;
}
export interface APIGatewayRequestAuthorizerEventPathParameters {
[name: string]: string | undefined;
}
export interface APIGatewayRequestAuthorizerEventQueryStringParameters {
[name: string]: string | undefined;
}
export interface APIGatewayRequestAuthorizerEventMultiValueQueryStringParameters {
[name: string]: string[] | undefined;
}
export interface APIGatewayRequestAuthorizerEventStageVariables {
[name: string]: string | undefined;
}
// Note, when invoked by the tester in the AWS web console, the map values can be null,
// but they will be empty objects in the real object.
// Worse, it will include "body" and "isBase64Encoded" properties, unlike the real call!
// See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html for the
// formal definition.
export interface APIGatewayRequestAuthorizerEvent {
type: "REQUEST";
methodArn: string;
resource: string;
path: string;
httpMethod: string;
headers: APIGatewayRequestAuthorizerEventHeaders | null;
multiValueHeaders: APIGatewayRequestAuthorizerEventMultiValueHeaders | null;
pathParameters: APIGatewayRequestAuthorizerEventPathParameters | null;
queryStringParameters:
| APIGatewayRequestAuthorizerEventQueryStringParameters
| null;
multiValueQueryStringParameters:
| APIGatewayRequestAuthorizerEventMultiValueQueryStringParameters
| null;
stageVariables: APIGatewayRequestAuthorizerEventStageVariables | null;
requestContext: APIGatewayEventRequestContextWithAuthorizer<undefined>;
}
export interface APIGatewayAuthorizerResult {
principalId: string;
policyDocument: PolicyDocument;
context?: APIGatewayAuthorizerResultContext | null;
usageIdentifierKey?: string | null;
}
// Separate type so the context property is required, without pulling complex type magic.
export interface APIGatewayAuthorizerWithContextResult<
TAuthorizerContext extends APIGatewayAuthorizerResultContext,
> {
principalId: string;
policyDocument: PolicyDocument;
context: TAuthorizerContext;
usageIdentifierKey?: string | null;
}
/** @deprecated Use APIGatewayAuthorizerHandler or a subtype */
export type CustomAuthorizerHandler = Handler<
CustomAuthorizerEvent,
APIGatewayAuthorizerResult
>;
/** @deprecated Use APIGatewayAuthorizerEvent or a subtype */
export interface CustomAuthorizerEvent {
type: string;
methodArn: string;
authorizationToken?: string;
resource?: string;
path?: string;
httpMethod?: string;
headers?: { [name: string]: string };
multiValueHeaders?: { [name: string]: string[] };
pathParameters?: { [name: string]: string } | null;
queryStringParameters?: { [name: string]: string } | null;
multiValueQueryStringParameters?: { [name: string]: string[] } | null;
stageVariables?: { [name: string]: string };
requestContext?: APIGatewayEventRequestContextWithAuthorizer<
APIGatewayEventDefaultAuthorizerContext
>;
domainName?: string;
apiId?: string;
}
export type CustomAuthorizerResult = APIGatewayAuthorizerResult;
export type AuthResponse = APIGatewayAuthorizerResult;
export type AuthResponseContext = APIGatewayAuthorizerResultContext;
/**
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.
* https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
* https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition
*/
export interface PolicyDocument {
Version: string;
Id?: string;
Statement: Statement[];
}
/**
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.Condition.
* https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-policy-language-overview.html
* https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html
*/
export interface ConditionBlock {
[condition: string]: Condition | Condition[];
}
export interface Condition {
[key: string]: string | string[];
}
/**
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.Statement.
* https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-policy-language-overview.html
* https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html
*/
export type Statement =
& BaseStatement
& StatementAction
& (StatementResource | StatementPrincipal);
export interface BaseStatement {
Effect: string;
Sid?: string;
Condition?: ConditionBlock;
}
export type PrincipalValue =
| { [key: string]: string | string[] }
| string
| string[];
export interface MaybeStatementPrincipal {
Principal?: PrincipalValue;
NotPrincipal?: PrincipalValue;
}
export interface MaybeStatementResource {
Resource?: string | string[];
NotResource?: string | string[];
}
export type StatementAction = { Action: string | string[] } | {
NotAction: string | string[];
};
export type StatementResource =
& MaybeStatementPrincipal
& ({ Resource: string | string[] } | { NotResource: string | string[] });
export type StatementPrincipal =
& MaybeStatementResource
& ({ Principal: PrincipalValue } | { NotPrincipal: PrincipalValue });
/**
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export type APIGatewayProxyHandler = Handler<
APIGatewayProxyEvent,
APIGatewayProxyResult
>;
/**
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
/**
* Works with HTTP API integration Payload Format version 2.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export type APIGatewayProxyHandlerV2<T = never> = Handler<
APIGatewayProxyEventV2,
APIGatewayProxyResultV2<T>
>;
/**
* Works with HTTP API integration Payload Format version 2.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
/**
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export type APIGatewayProxyEvent = APIGatewayProxyEventBase<
APIGatewayEventDefaultAuthorizerContext
>;
export type APIGatewayProxyWithLambdaAuthorizerHandler<TAuthorizerContext> =
Handler<
APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext>,
APIGatewayProxyResult
>;
export type APIGatewayProxyWithCognitoAuthorizerHandler = Handler<
APIGatewayProxyWithCognitoAuthorizerEvent,
APIGatewayProxyResult
>;
export type APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext> =
APIGatewayProxyEventBase<
APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>
>;
export type APIGatewayProxyWithLambdaAuthorizerEventRequestContext<
TAuthorizerContext,
> = APIGatewayEventRequestContextWithAuthorizer<
APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>
>;
// API Gateway proxy integration mangles the context from a custom authorizer,
// converting all number or boolean properties to string, and adding some extra properties.
export type APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext> =
& {
[P in keyof TAuthorizerContext]: TAuthorizerContext[P] extends null ? null
: string;
}
& {
principalId: string;
integrationLatency: number;
};
export type APIGatewayProxyWithCognitoAuthorizerEvent =
APIGatewayProxyEventBase<APIGatewayProxyCognitoAuthorizer>;
// All claims are coerced into strings.
export interface APIGatewayProxyCognitoAuthorizer {
claims: {
[name: string]: string;
};
}
export interface APIGatewayProxyEventHeaders {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventMultiValueHeaders {
[name: string]: string[] | undefined;
}
export interface APIGatewayProxyEventPathParameters {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventQueryStringParameters {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventMultiValueQueryStringParameters {
[name: string]: string[] | undefined;
}
export interface APIGatewayProxyEventStageVariables {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventBase<TAuthorizerContext> {
body: string | null;
headers: APIGatewayProxyEventHeaders;
multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
httpMethod: string;
isBase64Encoded: boolean;
path: string;
pathParameters: APIGatewayProxyEventPathParameters | null;
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
multiValueQueryStringParameters:
| APIGatewayProxyEventMultiValueQueryStringParameters
| null;
stageVariables: APIGatewayProxyEventStageVariables | null;
requestContext: APIGatewayEventRequestContextWithAuthorizer<
TAuthorizerContext
>;
resource: string;
}
/**
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export interface APIGatewayProxyResult {
statusCode: number;
headers?: {
[header: string]: boolean | number | string;
};
multiValueHeaders?: {
[header: string]: Array<boolean | number | string>;
};
body: string;
isBase64Encoded?: boolean;
}
/**
* Works with HTTP API integration Payload Format version 2.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export interface APIGatewayProxyEventV2 {
version: string;
routeKey: string;
rawPath: string;
rawQueryString: string;
cookies?: string[];
headers: APIGatewayProxyEventHeaders;
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
requestContext: {
accountId: string;
apiId: string;
authorizer?: {
jwt: {
claims: { [name: string]: string | number | boolean | string[] };
scopes: string[];
};
};
domainName: string;
domainPrefix: string;
http: {
method: string;
path: string;
protocol: string;
sourceIp: string;
userAgent: string;
};
requestId: string;
routeKey: string;
stage: string;
time: string;
timeEpoch: number;
};
body?: string;
pathParameters?: APIGatewayProxyEventPathParameters;
isBase64Encoded: boolean;
stageVariables?: APIGatewayProxyEventStageVariables;
}
/**
* Works with HTTP API integration Payload Format version 2.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export type APIGatewayProxyResultV2<T = never> =
| APIGatewayProxyStructuredResultV2
| string
| T;
/**
* Interface for structured response with `statusCode` and`headers`
* Works with HTTP API integration Payload Format version 2.0
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
*/
export interface APIGatewayProxyStructuredResultV2 {
statusCode?: number;
headers?: {
[header: string]: boolean | number | string;
};
body?: string;
isBase64Encoded?: boolean;
cookies?: string[];
}
// Legacy names
export type ProxyHandler = APIGatewayProxyHandler;
export type APIGatewayEvent = APIGatewayProxyEvent;
export type ProxyResult = APIGatewayProxyResult;
export type AppSyncResolverHandler<T, V> = Handler<
AppSyncResolverEvent<T>,
V | V[]
>;
export interface AppSyncResolverEventHeaders {
[name: string]: string | undefined;
}
/**
* See https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
*
* @param T type of the arguments
*/
export interface AppSyncResolverEvent<T> {
arguments: T;
identity?: AppSyncIdentityIAM | AppSyncIdentityCognito;
source: { [key: string]: any } | null;
request: {
headers: AppSyncResolverEventHeaders;
};
info: {
selectionSetList: string[];
selectionSetGraphQL: string;
parentTypeName: string;
fieldName: string;
variables: { [key: string]: any };
};
prev: { result: { [key: string]: any } } | null;
stash: { [key: string]: any };
}
export interface AppSyncIdentityIAM {
accountId: string;
cognitoIdentityPoolId: string;
cognitoIdentityId: string;
sourceIp: string[];
username: string;
userArn: string;
cognitoIdentityAuthType: string;
cognitoIdentityAuthProvider: string;
}
export interface AppSyncIdentityCognito {
sub: string;
issuer: string;
username: string;
claims: any;
sourceIp: string[];
defaultAuthStrategy: string;
groups: string[] | null;
}
// Note, responses are *not* lambda results, they are sent to the event ResponseURL.
export type CloudFormationCustomResourceHandler = Handler<
CloudFormationCustomResourceEvent,
void
>;
export type CloudFormationCustomResourceEvent =
| CloudFormationCustomResourceCreateEvent
| CloudFormationCustomResourceUpdateEvent
| CloudFormationCustomResourceDeleteEvent;
export type CloudFormationCustomResourceResponse =
| CloudFormationCustomResourceSuccessResponse
| CloudFormationCustomResourceFailedResponse;
/**
* CloudFormation Custom Resource event and response
* http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref.html
*/
export interface CloudFormationCustomResourceEventCommon {
ServiceToken: string;
ResponseURL: string;
StackId: string;
RequestId: string;
LogicalResourceId: string;
ResourceType: string;
ResourceProperties: {
ServiceToken: string;
[Key: string]: any;
};
}
export interface CloudFormationCustomResourceCreateEvent
extends CloudFormationCustomResourceEventCommon {
RequestType: "Create";
}
export interface CloudFormationCustomResourceUpdateEvent
extends CloudFormationCustomResourceEventCommon {
RequestType: "Update";
PhysicalResourceId: string;
OldResourceProperties: {
[Key: string]: any;
};
}
export interface CloudFormationCustomResourceDeleteEvent
extends CloudFormationCustomResourceEventCommon {
RequestType: "Delete";
PhysicalResourceId: string;
}
export interface CloudFormationCustomResourceResponseCommon {
PhysicalResourceId: string;
StackId: string;
RequestId: string;
LogicalResourceId: string;
Data?: {
[Key: string]: any;
};
NoEcho?: boolean;
}
export interface CloudFormationCustomResourceSuccessResponse
extends CloudFormationCustomResourceResponseCommon {
Status: "SUCCESS";
Reason?: string;
}
export interface CloudFormationCustomResourceFailedResponse
extends CloudFormationCustomResourceResponseCommon {
Status: "FAILED";
Reason: string;
}
export type CloudFrontRequestHandler = Handler<
CloudFrontRequestEvent,
CloudFrontRequestResult
>;
/**
* CloudFront viewer request or origin request event
*
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-request
*/
export interface CloudFrontRequestEvent {
Records: Array<{
cf: CloudFrontEvent & {
request: CloudFrontRequest;
};
}>;
}
export type CloudFrontRequestResult =
| undefined
| null
| CloudFrontResultResponse
| CloudFrontRequest;
export type CloudFrontResponseHandler = Handler<
CloudFrontResponseEvent,
CloudFrontResponseResult
>;
/**
* CloudFront viewer response or origin response event
*
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response
*/
export interface CloudFrontResponseEvent {
Records: Array<{
cf: CloudFrontEvent & {
readonly request: Pick<
CloudFrontRequest,
Exclude<keyof CloudFrontRequest, "body">
>;
response: CloudFrontResponse;
};
}>;
}
export type CloudFrontResponseResult =
| undefined
| null
| CloudFrontResultResponse;
export type ScheduledHandler<TDetail = any> = EventBridgeHandler<
"Scheduled Event",
TDetail,
void
>;
/**
* https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html
*/
export interface ScheduledEvent<TDetail = any>
extends EventBridgeEvent<"Scheduled Event", TDetail> {}
export type CloudWatchLogsHandler = Handler<CloudWatchLogsEvent, void>;