diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index 09070fb13c..a87c6da946 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -14,8 +14,9 @@ // Markus Tacker // Palmi Valgeirsson // Danilo Raisi +// Simon Buchan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 2.3 // API Gateway "event" request context export interface APIGatewayEventRequestContext { @@ -191,9 +192,10 @@ export interface S3EventRecord { }; } -export interface S3CreateEvent { +export interface S3Event { Records: S3EventRecord[]; } +export type S3CreateEvent = S3Event; // old name /** * Cognito User Pool event @@ -414,7 +416,7 @@ export interface ClientContextEnv { locale: string; } -export interface ProxyResult { +export interface APIGatewayProxyResult { statusCode: number; headers?: { [header: string]: boolean | number | string; @@ -422,16 +424,18 @@ export interface ProxyResult { body: string; isBase64Encoded?: boolean; } +export type ProxyResult = APIGatewayProxyResult; // Old name /** * API Gateway CustomAuthorizer AuthResponse. * http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output */ -export interface AuthResponse { +export interface CustomAuthorizerResult { principalId: string; policyDocument: PolicyDocument; context?: AuthResponseContext; } +export type AuthResponse = CustomAuthorizerResult; /** * API Gateway CustomAuthorizer AuthResponse.PolicyDocument. @@ -509,6 +513,15 @@ export interface CloudFrontRequestEvent { }>; } +// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses.html#lambda-generating-http-responses-object +export interface CloudFrontResult { + status: string; + statusDescription?: string; + headers?: CloudFrontHeaders; + bodyEncoding?: 'text' | 'base64'; + body?: string; +} + /** * AWS Lambda handler function. * http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html @@ -517,9 +530,7 @@ export interface CloudFrontRequestEvent { * @param context – runtime information of the Lambda function that is executing. * @param callback – optional callback to return information to the caller, otherwise return value is null. */ -export type Handler = (event: any, context: Context, callback?: Callback) => Promise | void; -export type ProxyHandler = (event: APIGatewayEvent, context: Context, callback?: ProxyCallback) => Promise | void; -export type CustomAuthorizerHandler = (event: CustomAuthorizerEvent, context: Context, callback?: CustomAuthorizerCallback) => Promise | void; +export type Handler = (event: TEvent, context: Context, callback: Callback) => void; /** * Optional callback parameter. @@ -528,8 +539,53 @@ export type CustomAuthorizerHandler = (event: CustomAuthorizerEvent, context: Co * @param error – an optional parameter that you can use to provide results of the failed Lambda function execution. * @param result – an optional parameter that you can use to provide the result of a successful function execution. The result provided must be JSON.stringify compatible. */ -export type Callback = (error?: Error | null, result?: object | boolean | number | string) => void; -export type ProxyCallback = (error?: Error | null, result?: ProxyResult) => void; -export type CustomAuthorizerCallback = (error?: Error | null, result?: AuthResponse) => void; +export type Callback = (error?: Error | null, result?: TResult) => void; + +// Begin defining Handler and Callback types for each API trigger type. +// Ordered by https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html +// though that list is incomplete. + +export type S3Handler = Handler; + +export type DynamoDBHandler = Handler; + +export type SNSHandler = Handler; + +// No SESHandler: SES event source is delivered as SNS notifications +// https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html#supported-event-source-ses + +export type CognitoUserPoolTriggerHandler = Handler; +// TODO: Different event triggers/response pairs? + +// TODO: CognitoSync + +export type CloudFormationCustomResourceHandler = Handler; + +// TODO: CloudWatchEvents + +export type CloudWatchLogsHandler = Handler; + +// TODO: CodeCommit + +export type ScheduledEventHandler = Handler; + +// TODO: AWS Config + +// TODO: Alexa + +export type APIGatewayProxyHandler = Handler; +export type ProxyHandler = APIGatewayProxyHandler; // Old name +export type APIGatewayProxyCallback = Callback; +export type ProxyCallback = APIGatewayProxyCallback; // Old name + +// TODO: IoT + +export type CloudFrontRequestHandler = Handler; +export type CloudFrontResponseHandler = Handler; + +// TODO: Kinesis (should be very close to DynamoDB stream?) + +export type CustomAuthorizerHandler = Handler; +export type CustomAuthorizerCallback = Callback; export as namespace AWSLambda;