UNPKG

5.07 kBTypeScriptView Raw
1import * as ec2 from '@aws-cdk/aws-ec2';
2import * as iam from '@aws-cdk/aws-iam';
3import * as logs from '@aws-cdk/aws-logs';
4import * as cdk from '@aws-cdk/core';
5import { Construct } from 'constructs';
6import { Architecture } from './architecture';
7import { Function as LambdaFunction, FunctionProps, EnvironmentOptions } from './function';
8import { FunctionBase } from './function-base';
9import { Version } from './lambda-version';
10import { ILayerVersion } from './layers';
11import { Permission } from './permission';
12import { Runtime } from './runtime';
13/**
14 * Properties for a newly created singleton Lambda
15 */
16export interface SingletonFunctionProps extends FunctionProps {
17 /**
18 * A unique identifier to identify this lambda
19 *
20 * The identifier should be unique across all custom resource providers.
21 * We recommend generating a UUID per provider.
22 */
23 readonly uuid: string;
24 /**
25 * A descriptive name for the purpose of this Lambda.
26 *
27 * If the Lambda does not have a physical name, this string will be
28 * reflected its generated name. The combination of lambdaPurpose
29 * and uuid must be unique.
30 *
31 * @default SingletonLambda
32 */
33 readonly lambdaPurpose?: string;
34}
35/**
36 * A Lambda that will only ever be added to a stack once.
37 *
38 * This construct is a way to guarantee that the lambda function will be guaranteed to be part of the stack,
39 * once and only once, irrespective of how many times the construct is declared to be part of the stack.
40 * This is guaranteed as long as the `uuid` property and the optional `lambdaPurpose` property stay the same
41 * whenever they're declared into the stack.
42 *
43 * @resource AWS::Lambda::Function
44 */
45export declare class SingletonFunction extends FunctionBase {
46 readonly grantPrincipal: iam.IPrincipal;
47 readonly functionName: string;
48 readonly functionArn: string;
49 readonly role?: iam.IRole;
50 readonly permissionsNode: cdk.ConstructNode;
51 readonly architecture: Architecture;
52 /**
53 * The runtime environment for the Lambda function.
54 */
55 readonly runtime: Runtime;
56 protected readonly canCreatePermissions: boolean;
57 private lambdaFunction;
58 constructor(scope: Construct, id: string, props: SingletonFunctionProps);
59 /**
60 * @inheritdoc
61 */
62 get isBoundToVpc(): boolean;
63 /**
64 * @inheritdoc
65 */
66 get connections(): ec2.Connections;
67 /**
68 * The LogGroup where the Lambda function's logs are made available.
69 *
70 * If either `logRetention` is set or this property is called, a CloudFormation custom resource is added to the stack that
71 * pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention
72 * period (never expire, by default).
73 *
74 * Further, if the log group already exists and the `logRetention` is not set, the custom resource will reset the log retention
75 * to never expire even if it was configured with a different value.
76 */
77 get logGroup(): logs.ILogGroup;
78 /**
79 * Returns a `lambda.Version` which represents the current version of this
80 * singleton Lambda function. A new version will be created every time the
81 * function's configuration changes.
82 *
83 * You can specify options for this version using the `currentVersionOptions`
84 * prop when initializing the `lambda.SingletonFunction`.
85 */
86 get currentVersion(): Version;
87 get resourceArnsForGrantInvoke(): string[];
88 /**
89 * Adds an environment variable to this Lambda function.
90 * If this is a ref to a Lambda function, this operation results in a no-op.
91 * @param key The environment variable key.
92 * @param value The environment variable's value.
93 * @param options Environment variable options.
94 */
95 addEnvironment(key: string, value: string, options?: EnvironmentOptions): LambdaFunction;
96 /**
97 * Adds one or more Lambda Layers to this Lambda function.
98 *
99 * @param layers the layers to be added.
100 *
101 * @throws if there are already 5 layers on this function, or the layer is incompatible with this function's runtime.
102 */
103 addLayers(...layers: ILayerVersion[]): void;
104 addPermission(name: string, permission: Permission): void;
105 /**
106 * Using node.addDependency() does not work on this method as the underlying lambda function is modeled
107 * as a singleton across the stack. Use this method instead to declare dependencies.
108 */
109 addDependency(...up: cdk.IDependable[]): void;
110 /**
111 * The SingletonFunction construct cannot be added as a dependency of another construct using
112 * node.addDependency(). Use this method instead to declare this as a dependency of another construct.
113 */
114 dependOn(down: cdk.IConstruct): void;
115 /** @internal */
116 _checkEdgeCompatibility(): void;
117 /**
118 * Returns the construct tree node that corresponds to the lambda function.
119 * @internal
120 */
121 protected _functionNode(): cdk.ConstructNode;
122 private ensureLambda;
123}