diff --git a/overlays/nodejs/lambda/createFunction.ts b/overlays/nodejs/lambda/createFunction.ts index 8942f72389f..ced972d6f27 100644 --- a/overlays/nodejs/lambda/createFunction.ts +++ b/overlays/nodejs/lambda/createFunction.ts @@ -25,7 +25,7 @@ export interface Context { /** * Handler is the signature for a callback that be converted into an aws lambda entrypoint. */ -export type Handler = (event: any, context: Context, callback: (error: any, result: any) => void) => any; +export type Handler = (event: E, context: Context, callback: (error: any, result: R) => void) => any; /** * CallbackFunctionArgs specify the properties that can be passed in to configure the AWS Lambda @@ -38,9 +38,9 @@ export type CallbackFunctionArgs = utils.Omit boolean, opts?: pulumi.ResourceOptions): lambda.Function { +export function createFunction( + name: string, handler: Handler, args: CallbackFunctionArgs, + serialize?: (obj: any) => boolean, opts?: pulumi.ResourceOptions): lambda.Function { if (!name) { throw new Error("Missing required 'name'"); diff --git a/overlays/nodejs/lambda/typedFunction.ts b/overlays/nodejs/lambda/typedFunction.ts new file mode 100644 index 00000000000..3a2f1f35274 --- /dev/null +++ b/overlays/nodejs/lambda/typedFunction.ts @@ -0,0 +1,6 @@ +import * as func from "./function" + +declare module "./function" { + export interface Function { + } +} \ No newline at end of file diff --git a/overlays/nodejs/serverless/function.ts b/overlays/nodejs/serverless/function.ts index 243cf3888c0..ca3a24d2431 100644 --- a/overlays/nodejs/serverless/function.ts +++ b/overlays/nodejs/serverless/function.ts @@ -3,30 +3,8 @@ import * as crypto from "crypto"; import * as pulumi from "@pulumi/pulumi"; import { Role, RolePolicyAttachment } from "../iam"; -import * as lambda from "../lambda"; import { ARN } from "../arn"; - -/** - * Context is the shape of the context object passed to a Function callback. - */ -export interface Context { - callbackWaitsForEmptyEventLoop: boolean; - readonly functionName: string; - readonly functionVersion: string; - readonly invokedFunctionArn: string; - readonly memoryLimitInMB: string; - readonly awsRequestId: string; - readonly logGroupName: string; - readonly logStreamName: string; - readonly identity: any; - readonly clientContext: any; - getRemainingTimeInMillis(): string; -} - -/** - * Handler is the signature for a serverless function. - */ -export type Handler = (event: any, context: Context, callback: (error: any, result: any) => void) => any; +import * as lambda from "../lambda"; export interface FunctionOptions { policies: ARN[]; @@ -44,7 +22,7 @@ export interface FunctionOptions { * Function is a higher-level API for creating and managing AWS Lambda Function resources implemented * by a Lumi lambda expression and with a set of attached policies. */ -export class Function extends pulumi.ComponentResource { +export class Function extends pulumi.ComponentResource { public readonly options: FunctionOptions; public readonly lambda: lambda.Function; public readonly role: Role; @@ -52,7 +30,7 @@ export class Function extends pulumi.ComponentResource { constructor(name: string, options: FunctionOptions, - func: Handler, + func: lambda.Handler, opts?: pulumi.ResourceOptions, serialize?: (obj: any) => boolean) { if (!name) { diff --git a/resources.go b/resources.go index 7a460cdcccb..5dc77668cd9 100644 --- a/resources.go +++ b/resources.go @@ -1296,6 +1296,7 @@ func Provider() tfbridge.ProviderInfo { Files: []string{ "runtimes.ts", // a union type and constants for available Lambda runtimes. "createFunction.ts", // helper method to simply create a lambda function from an arrow function + "typedFunction.ts", // makes the exported 'Function' type generic. }, }, "serverless": {