Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JetKitLambdaFunction

Lambda function with agreeable defaults.

Hierarchy

Index

Constructors

constructor

Properties

Protected Optional _connections

_connections?: Connections

Actual connections object for this Lambda

May be unset, in which case this Lambda is not configured use in a VPC.

internal

Protected _invocationGrants

_invocationGrants: Record<string, Grant>

Mapping of invocation principals to grants. Used to de-dupe grantInvoke() calls.

internal

Optional bundling

bundling?: BundlingOptions

Protected Readonly canCreatePermissions

canCreatePermissions: true = true

Whether the addPermission() call adds any permissions.

True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.

stability

stable

Optional Readonly deadLetterQueue

deadLetterQueue?: IQueue

The DLQ associated with this Lambda Function (this is an optional attribute).

stability

stable

Readonly env

env: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

stability

stable

Readonly functionArn

functionArn: string

ARN of this function.

stability

stable

Readonly functionName

functionName: string

Name of this function.

stability

stable

Readonly grantPrincipal

grantPrincipal: IPrincipal

The principal this Lambda Function is running as.

stability

stable

Protected Optional metadataTarget

metadataTarget?: WeakRef<MetadataTarget>

Optional name

name?: string

Readonly node

node: ConstructNode

The construct tree node associated with this construct.

stability

stable

Readonly permissionsNode

permissionsNode: ConstructNode

The construct node where permissions are attached.

stability

stable

Protected Readonly physicalName

physicalName: string

Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.

This value will resolve to one of the following:

  • a concrete value (e.g. "my-awesome-bucket")
  • undefined, when a name should be generated by CloudFormation
  • a concrete name generated automatically during synthesis, in cross-environment scenarios.
stability

stable

Optional Readonly role

role?: IRole

Execution role associated with this function.

stability

stable

Readonly runtime

runtime: Runtime

The runtime configured for this lambda.

stability

stable

Readonly stack

stack: Stack

The stack in which this resource is defined.

stability

stable

Static _VER_PROPS

_VER_PROPS: {}
internal

Type declaration

  • [key: string]: boolean

Accessors

connections

  • get connections(): Connections
  • Access the Connections object.

    Will fail if not a VPC-enabled Lambda Function

    stability

    stable

    Returns Connections

currentVersion

  • get currentVersion(): Version
  • Returns a lambda.Version which represents the current version of this Lambda function. A new version will be created every time the function's configuration changes.

    You can specify options for this version using the currentVersionOptions prop when initializing the lambda.Function.

    stability

    stable

    Returns Version

isBoundToVpc

  • get isBoundToVpc(): boolean
  • Whether or not this Lambda function was bound to a VPC.

    If this is is false, trying to access the connections object will fail.

    stability

    stable

    Returns boolean

latestVersion

  • get latestVersion(): IVersion
  • The $LATEST version of this function.

    Note that this is reference to a non-specific AWS Lambda version, which means the function this version refers to can return different results in different invocations.

    To obtain a reference to an explicit version which references the current function configuration, use lambdaFunction.currentVersion instead.

    stability

    stable

    Returns IVersion

logGroup

  • get logGroup(): ILogGroup
  • The LogGroup where the Lambda function's logs are made available.

    If either logRetention is set or this property is called, a CloudFormation custom resource is added to the stack that pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention period (never expire, by default).

    Further, if the log group already exists and the logRetention is not set, the custom resource will reset the log retention to never expire even if it was configured with a different value.

    stability

    stable

    Returns ILogGroup

Methods

_checkEdgeCompatibility

  • _checkEdgeCompatibility(): void
  • internal

    Returns void

_enableCrossEnvironment

  • _enableCrossEnvironment(): void
  • Called when this resource is referenced across environments (account/region) to order to request that a physical name will be generated for this resource during synthesis, so the resource can be referenced through it's absolute name/arn.

    internal

    Returns void

Protected _functionNode

  • _functionNode(): ConstructNode
  • Returns the construct tree node that corresponds to the lambda function. For use internally for constructs, when the tree is set up in non-standard ways. Ex: SingletonFunction.

    internal

    Returns ConstructNode

Protected _isStackAccount

  • _isStackAccount(): boolean
  • Given the function arn, check if the account id matches this account

    Function ARNs look like this:

    arn:aws:lambda:region:account-id:function:function-name

    ..which means that in order to extract the account-id component from the ARN, we can split the ARN using ":" and select the component in index 4.

    internal

    Returns boolean

    true if account id of function matches the account specified on the stack, false otherwise.

addEnvironment

  • Adds an environment variable to this Lambda function.

    If this is a ref to a Lambda function, this operation results in a no-op.

    stability

    stable

    Parameters

    • key: string

      The environment variable key.

    • value: string

      The environment variable's value.

    • Optional options: EnvironmentOptions

      Environment variable options.

    Returns JetKitLambdaFunction

addEventSource

  • addEventSource(source: IEventSource): void
  • Adds an event source to this function.

    Event sources are implemented in the @aws-cdk/aws-lambda-event-sources module.

    The following example adds an SQS Queue as an event source:

    import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources';
    myFunction.addEventSource(new SqsEventSource(myQueue));
    stability

    stable

    Parameters

    • source: IEventSource

    Returns void

addEventSourceMapping

  • addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMapping
  • Adds an event source that maps to this AWS Lambda function.

    stability

    stable

    Parameters

    • id: string
    • options: EventSourceMappingOptions

    Returns EventSourceMapping

addLayers

  • addLayers(...layers: ILayerVersion[]): void
  • Adds one or more Lambda Layers to this Lambda function.

    stability

    stable

    throws

    if there are already 5 layers on this function, or the layer is incompatible with this function's runtime.

    Parameters

    • Rest ...layers: ILayerVersion[]

      the layers to be added.

    Returns void

addPermission

  • addPermission(id: string, permission: Permission): void
  • Adds a permission to the Lambda resource policy.

    see

    Permission for details.

    stability

    stable

    Parameters

    • id: string

      The id for the permission construct.

    • permission: Permission

      The permission to grant to this Lambda function.

    Returns void

addToRolePolicy

  • addToRolePolicy(statement: PolicyStatement): void
  • Adds a statement to the IAM role assumed by the instance.

    stability

    stable

    Parameters

    • statement: PolicyStatement

    Returns void

addVersion

  • addVersion(name: string, codeSha256?: string, description?: string, provisionedExecutions?: number, asyncInvokeConfig?: EventInvokeConfigOptions): Version
  • (deprecated) Add a new version for this Lambda.

    If you want to deploy through CloudFormation and use aliases, you need to add a new version (with a new name) to your Lambda every time you want to deploy an update. An alias can then refer to the newly created Version.

    All versions should have distinct names, and you should not delete versions as long as your Alias needs to refer to them.

    deprecated

    This method will create an AWS::Lambda::Version resource which snapshots the AWS Lambda function at the time of its creation and it won't get updated when the function changes. Instead, use this.currentVersion to obtain a reference to a version resource that gets automatically recreated when the function configuration (or code) changes.

    Parameters

    • name: string

      A unique name for this version.

    • Optional codeSha256: string

      The SHA-256 hash of the most recently deployed Lambda source code, or omit to skip validation.

    • Optional description: string

      A description for this version.

    • Optional provisionedExecutions: number

      A provisioned concurrency configuration for a function's version.

    • Optional asyncInvokeConfig: EventInvokeConfigOptions

      configuration for this version when it is invoked asynchronously.

    Returns Version

    A new Version object.

applyRemovalPolicy

  • applyRemovalPolicy(policy: RemovalPolicy): void
  • Apply the given removal policy to this resource.

    The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

    The resource can be deleted (RemovalPolicy.DELETE), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

    stability

    stable

    Parameters

    • policy: RemovalPolicy

    Returns void

configureAsyncInvoke

  • configureAsyncInvoke(options: EventInvokeConfigOptions): void
  • Configures options for asynchronous invocation.

    stability

    stable

    Parameters

    • options: EventInvokeConfigOptions

    Returns void

Protected generatePhysicalName

  • generatePhysicalName(): string
  • stability

    stable

    Returns string

getMetadataTarget

  • getMetadataTarget(): undefined | MetadataTarget

Protected getResourceArnAttribute

  • getResourceArnAttribute(arnAttr: string, arnComponents: ArnComponents): string
  • Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn).

    Normally, this token will resolve to arnAttr, but if the resource is referenced across environments, arnComponents will be used to synthesize a concrete ARN with the resource's physical name. Make sure to reference this.physicalName in arnComponents.

    stability

    stable

    Parameters

    • arnAttr: string

      The CFN attribute which resolves to the ARN of the resource.

    • arnComponents: ArnComponents

      The format of the ARN of this resource.

    Returns string

Protected getResourceNameAttribute

  • getResourceNameAttribute(nameAttr: string): string
  • Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName).

    Normally, this token will resolve to nameAttr, but if the resource is referenced across environments, it will be resolved to this.physicalName, which will be a concrete name.

    stability

    stable

    Parameters

    • nameAttr: string

      The CFN attribute which resolves to the resource's name.

    Returns string

grantInvoke

  • grantInvoke(grantee: IGrantable): Grant
  • Grant the given identity permissions to invoke this Lambda.

    stability

    stable

    Parameters

    • grantee: IGrantable

    Returns Grant

metric

  • metric(metricName: string, props?: MetricOptions): Metric
  • Return the given named metric for this Function.

    stability

    stable

    Parameters

    • metricName: string
    • Optional props: MetricOptions

    Returns Metric

metricDuration

  • metricDuration(props?: MetricOptions): Metric
  • How long execution of this Lambda takes.

    Average over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

metricErrors

  • metricErrors(props?: MetricOptions): Metric
  • How many invocations of this Lambda fail.

    Sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

metricInvocations

  • metricInvocations(props?: MetricOptions): Metric
  • How often this Lambda is invoked.

    Sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

metricThrottles

  • metricThrottles(props?: MetricOptions): Metric
  • How often this Lambda is throttled.

    Sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Protected onPrepare

  • onPrepare(): void
  • Perform final modifications before synthesis.

    This method can be implemented by derived constructs in order to perform final changes before synthesis. prepare() will be called after child constructs have been prepared.

    This is an advanced framework feature. Only use this if you understand the implications.

    stability

    stable

    Returns void

Protected onSynthesize

  • onSynthesize(session: ISynthesisSession): void
  • Allows this construct to emit artifacts into the cloud assembly during synthesis.

    This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

    stability

    stable

    Parameters

    • session: ISynthesisSession

      The synthesis session.

    Returns void

Protected onValidate

  • onValidate(): string[]
  • Validate the current construct.

    This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

    stability

    stable

    Returns string[]

    An array of validation error messages, or an empty array if the construct is valid.

Protected prepare

  • prepare(): void
  • Perform final modifications before synthesis.

    This method can be implemented by derived constructs in order to perform final changes before synthesis. prepare() will be called after child constructs have been prepared.

    This is an advanced framework feature. Only use this if you understand the implications.

    stability

    stable

    Returns void

Protected synthesize

  • synthesize(session: ISynthesisSession): void
  • Allows this construct to emit artifacts into the cloud assembly during synthesis.

    This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

    stability

    stable

    Parameters

    • session: ISynthesisSession

      The synthesis session.

    Returns void

toString

  • toString(): string
  • Returns a string representation of this construct.

    stability

    stable

    Returns string

Protected validate

  • validate(): string[]
  • Validate the current construct.

    This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

    stability

    stable

    Returns string[]

    An array of validation error messages, or an empty array if the construct is valid.

Static classifyVersionProperty

  • classifyVersionProperty(propertyName: string, locked: boolean): void
  • Record whether specific properties in the AWS::Lambda::Function resource should also be associated to the Version resource.

    See 'currentVersion' section in the module README for more details.

    stability

    stable

    Parameters

    • propertyName: string

      The property to classify.

    • locked: boolean

      whether the property should be associated to the version or not.

    Returns void

Static fromFunctionArn

  • fromFunctionArn(scope: Construct, id: string, functionArn: string): IFunction
  • Import a lambda function into the CDK using its ARN.

    stability

    stable

    Parameters

    • scope: Construct
    • id: string
    • functionArn: string

    Returns IFunction

Static fromFunctionAttributes

  • fromFunctionAttributes(scope: Construct, id: string, attrs: FunctionAttributes): IFunction
  • Creates a Lambda function object which represents a function not defined within this stack.

    stability

    stable

    Parameters

    • scope: Construct

      The parent construct.

    • id: string

      The name of the lambda construct.

    • attrs: FunctionAttributes

      the attributes of the function to import.

    Returns IFunction

Static isConstruct

  • isConstruct(x: any): x is Construct
  • Return whether the given object is a Construct.

    stability

    stable

    Parameters

    • x: any

    Returns x is Construct

Static isResource

  • isResource(construct: IConstruct): construct is CfnResource
  • Check whether the given construct is a Resource.

    stability

    stable

    Parameters

    • construct: IConstruct

    Returns construct is CfnResource

Static metricAll

  • metricAll(metricName: string, props?: MetricOptions): Metric
  • Return the given named metric for this Lambda.

    stability

    stable

    Parameters

    • metricName: string
    • Optional props: MetricOptions

    Returns Metric

Static metricAllConcurrentExecutions

  • metricAllConcurrentExecutions(props?: MetricOptions): Metric
  • Metric for the number of concurrent executions across all Lambdas.

    default

    max over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Static metricAllDuration

  • metricAllDuration(props?: MetricOptions): Metric
  • Metric for the Duration executing all Lambdas.

    default

    average over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Static metricAllErrors

  • metricAllErrors(props?: MetricOptions): Metric
  • Metric for the number of Errors executing all Lambdas.

    default

    sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Static metricAllInvocations

  • metricAllInvocations(props?: MetricOptions): Metric
  • Metric for the number of invocations of all Lambdas.

    default

    sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Static metricAllThrottles

  • metricAllThrottles(props?: MetricOptions): Metric
  • Metric for the number of throttled invocations of all Lambdas.

    default

    sum over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Static metricAllUnreservedConcurrentExecutions

  • metricAllUnreservedConcurrentExecutions(props?: MetricOptions): Metric
  • Metric for the number of unreserved concurrent executions across all Lambdas.

    default

    max over 5 minutes

    stability

    stable

    Parameters

    • Optional props: MetricOptions

    Returns Metric

Generated using TypeDoc