UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

254 lines (253 loc) • 12.3 kB
import * as pulumi from "@pulumi/pulumi"; import * as iam from "../iam"; import * as utils from "../utils"; import { Function as LambdaFunction, FunctionArgs } from "./function"; import * as permission from "./permission"; import { Runtime } from "."; /** * Context is the shape of the context object passed to a Function callback. For more information, * see: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html */ export interface Context { /** * The default value is true. This property is useful only to modify the default behavior of the * callback. By default, the callback will wait until the event loop is empty before freezing * the process and returning the results to the caller. You can set this property to false to * request AWS Lambda to freeze the process soon after the callback is called, even if there are * events in the event loop. AWS Lambda will freeze the process, any state data and the events * in the event loop (any remaining events in the event loop processed when the Lambda function * is called next and if AWS Lambda chooses to use the frozen process). */ callbackWaitsForEmptyEventLoop: boolean; /** * Name of the Lambda function that is executing. */ functionName: string; /** * The Lambda function version that is executing. If an alias is used to invoke the function, * then function_version will be the version the alias points to. */ functionVersion: string; /** * The ARN used to invoke this function. It can be a function ARN or an alias ARN. An * unqualified ARN executes the $LATEST version and aliases execute the function version it is * pointing to. */ invokedFunctionArn: string; /** * Memory limit, in MB, you configured for the Lambda function. You set the memory limit at the * time you create a Lambda function and you can change it later. */ memoryLimitInMB: string; /** * AWS request ID associated with the request. This is the ID returned to the client that called * the invoke method. * * If AWS Lambda retries the invocation (for example, in a situation where the Lambda function * that is processing Kinesis records throws an exception), the request ID remains the same. */ awsRequestId: string; /** * The name of the CloudWatch log group where you can find logs written by your Lambda function. */ logGroupName: string; /** * The name of the CloudWatch log group where you can find logs written by your Lambda function. * The log stream may or may not change for each invocation of the Lambda function. * * The value is null if your Lambda function is unable to create a log stream, which can happen * if the execution role that grants necessary permissions to the Lambda function does not * include permissions for the CloudWatch actions. */ logStreamName: string; /** * Information about the Amazon Cognito identity provider when invoked through the AWS Mobile * SDK. It can be null. */ identity?: any; /** * Information about the client application and device when invoked through the AWS Mobile SDK. * It can be null. */ clientContext?: any; /** * Returns the approximate remaining execution time (before timeout occurs) of the Lambda * function that is currently executing. The timeout is one of the Lambda function * configuration. When the timeout reaches, AWS Lambda terminates your Lambda function. * * You can use this method to check the remaining time during your function execution and take * appropriate corrective action at run time. */ getRemainingTimeInMillis(): number; /** @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; /** @deprecated Use handler callback or promise result */ succeed(message: string, object: any): void; } /** * Callback is the signature for an AWS Lambda function entrypoint. * * [event] is the data passed in by specific services calling the Lambda (like s3, or kinesis). The * shape of it will be specific to individual services. * * [context] AWS Lambda uses this parameter to provide details of your Lambda function's execution. * For more information, see * https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html * * [callback] See https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-prog-model-handler-callback * for details. * * This function can be synchronous or asynchronous function, though async is only supported with an * AWS Lambda runtime of 8.10 or higher. On those runtimes a Promise can be returned, 'callback' * parameter can be ignored, and AWS will appropriately handle things. For AWS lambda pre-8.10, a * synchronous function must be provided. The synchronous function should return nothing, and * should instead invoke 'callback' when complete. */ export type Callback<E, R> = (event: E, context: Context, callback: (error?: Error | string | null, result?: R) => void) => Promise<R> | void; /** * CallbackFactory is the signature for a function that will be called once to produce the * entrypoint function that AWS Lambda will invoke. It can be used to initialize expensive state * once that can then be used across all invocations of the Lambda (as long as the Lambda is using * the same warm node instance). */ export type CallbackFactory<E, R> = () => Callback<E, R>; /** * An EventHandler is either a JavaScript callback or an aws.lambda.Function that can be used to * handle an event triggered by some resource. If just a JavaScript callback is provided the AWS * Lambda will be created by calling [createCallbackFunction] on it. If more control over the * resultant AWS Lambda is required, clients can call [createCallbackFunction] directly and pass the * result of that to any code that needs an EventHandler. */ export type EventHandler<E, R> = Callback<E, R> | LambdaFunction; /** * BaseCallbackFunctionArgs provides configuration options for the serverless Function. It is * effectively equivalent to [aws.lambda.FunctionArgs] except with a few important differences * documented at the property level. For example, [role] is an actual iam.Role instance, and not an * ARN. Properties like [runtime] are now optional. And some properties (like [code]) are entirely * disallowed. */ export type BaseCallbackFunctionArgs = utils.Overwrite<FunctionArgs, { /** * Not allowed when creating an aws.serverless.Function. The [code] will be generated from the * passed in JavaScript callback. */ code?: never; /** * Not allowed when creating an aws.serverless.Function. The [code] will be generated from the * passed in JavaScript callback. */ handler?: never; /** * A pre-created role to use for the Function. If not provided, [policies] will be used. */ role?: iam.Role | pulumi.Input<string>; /** * A list of IAM policy ARNs to attach to the Function. Will be used if [role] is not provide. * If neither [role] nor [policies] is provided, a default policy of [iam.AWSLambda_FullAccess] * will be used instead. * * This can be either an array of ARNs or an object whose values are ARNs. In the latter case, the * keys of the object are the names of the policies. These names are used to uniquely identify the * policy attachment to create a URN. This object format can be useful when you have lifted policy ARNs that you * want to attach. It doesn't matter what the keys are, as long as they are unique for each CallbackFunction. * * Example for object notation: * * ```typescript * const lambda = new aws.lambda.CallbackFunction("my-function", { * // ... other arguments ... * policies: { * "my-policy": myPolicy.arn, * "other-policy": otherPolicy.arn, * } * }); * ``` * * Example for array notation: * * (this will not work if the policy ARNs are lifted, or an output from another resource) * * ```typescript * const lambda = new aws.lambda.CallbackFunction("my-function", { * // ... other arguments ... * policies: [aws.iam.managedPolicies.S3FullAccess, aws.iam.managedPolicies.IAMFullAccess], * }); * ``` */ policies?: Record<string, pulumi.Input<string>> | string[]; /** * The Lambda runtime to use. If not provided, will default to [aws.lambda.Runtime.NodeJS20dX]. */ runtime?: Runtime | string; /** * Options to control which paths/packages should be included or excluded in the zip file containing * the code for the AWS lambda. */ codePathOptions?: pulumi.runtime.CodePathOptions; }>; /** * CallbackFunctionArgs provides configuration options for the serverless Function. It is * effectively equivalent to [aws.lambda.FunctionArgs] except with a few important differences * documented at the property level. For example, [role] is an actual iam.Role instance, and not an * ARN. Properties like [runtime] are now optional. And some properties (like [code]) are entirely * disallowed. */ export interface CallbackFunctionArgs<E, R> extends BaseCallbackFunctionArgs { /** * The Javascript callback to use as the entrypoint for the AWS Lambda out of. Either * [callback] or [callbackFactory] must be provided. */ callback?: Callback<E, R>; /** * The Javascript function instance that will be called to produce the callback function that is * the entrypoint for the AWS Lambda. Either [callback] or [callbackFactory] must be * provided. * * This form is useful when there is expensive initialization work that should only be executed * once. The factory-function will be invoked once when the final AWS Lambda module is loaded. * It can run whatever code it needs, and will end by returning the actual function that Lambda * will call into each time the Lambda is invoked. */ callbackFactory?: CallbackFactory<E, R>; } /** * Base type for all subscription types. An event subscription represents a connection between some * AWS resource and an AWS lambda that will be triggered when something happens to that resource. */ export declare class EventSubscription extends pulumi.ComponentResource { permission: permission.Permission; func: LambdaFunction; constructor(type: string, name: string, opts?: pulumi.ComponentResourceOptions); } export declare function isEventHandler(obj: any): obj is EventHandler<any, any>; export declare function createFunctionFromEventHandler<E, R>(name: string, handler: EventHandler<E, R>, opts?: pulumi.ResourceOptions): LambdaFunction; /** * A CallbackFunction is a special type of aws.lambda.Function that can be created out of an actual * JavaScript function instance. The function instance will be analyzed and packaged up (including * dependencies) into a form that can be used by AWS Lambda. See * https://www.pulumi.com/docs/concepts/inputs-outputs/function-serialization/ for additional * details on this process. * If no IAM Role is specified, CallbackFunction will automatically use the following managed policies: * `AWSLambda_FullAccess` * `CloudWatchFullAccessV2` * `CloudWatchEventsFullAccess` * `AmazonS3FullAccess` * `AmazonDynamoDBFullAccess` * `AmazonSQSFullAccess` * `AmazonKinesisFullAccess` * `AWSCloudFormationReadOnlyAccess` * `AmazonCognitoPowerUser` * `AWSXrayWriteOnlyAccess` */ export declare class CallbackFunction<E, R> extends LambdaFunction { /** * Actual Role instance value for this Function. Will only be set if this function was * created from [createFunction] */ readonly roleInstance?: iam.Role; constructor(name: string, args: CallbackFunctionArgs<E, R>, opts?: pulumi.CustomResourceOptions); }