# FunctionBase

Extends: Construct › Resource › FunctionBase
Implements: IResource, IClientVpnConnectionHandler, IConnectable, IGrantable, IFunction, IEnvironmentAware, IFunctionRef, IConstruct, IDependable
Superclass of: GoFunction, PythonFunction, Alias, DockerImageFunction, Function, QualifiedFunctionBase, SingletonFunction, Version, NodejsFunction, TriggerFunction

- Source: [`aws-lambda/lib/function-base.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-lambda/lib/function-base.ts#L262)
- Type last changed: v2.226.0 · 20 Nov 2025

## Initializer

```ts
new FunctionBase(scope: Construct, id: string, props?: ResourceProps)
```

## Construct Props

- `account`: string = the resource is in the same account as the stack it belongs to — The AWS account ID this resource belongs to.

  **Default:** the resource is in the same account as the stack it belongs to

- `environmentFromArn`: string = take environment from `account`, `region` parameters, or use Stack environment. — ARN to deduce region and account from.

  The ARN is parsed and the account and region are taken from the ARN.
  This should be used for imported resources.

  Cannot be supplied together with either `account` or `region`.

  **Default:** take environment from `account`, `region` parameters, or use Stack environment.

- `physicalName`: string = The physical name will be allocated by CloudFormation at deployment time — The value passed in by users to the physical name prop of the resource.

  - `undefined` implies that a physical name will be allocated by
    CloudFormation during deployment.
  - a concrete value implies a specific physical name
  - `PhysicalName.GENERATE_IF_NEEDED` is a marker that indicates that a physical will only be generated
    by the CDK if it is needed for cross-environment references. Otherwise, it will be allocated by CloudFormation.

  **Default:** The physical name will be allocated by CloudFormation at deployment time

- `region`: string = the resource is in the same region as the stack it belongs to — The AWS region this resource belongs to.

  **Default:** the resource is in the same region as the stack it belongs to

## Properties

- `architecture`: [Architecture](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Architecture.html) (required) — The architecture of this Lambda Function.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) (required) — Access the Connections object.

  Will fail if not a VPC-enabled Lambda Function

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `functionArn`: string (required) — The ARN fo the function.

- `functionName`: string (required) — The name of the function.

- `functionRef`: [FunctionReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_lambda.FunctionReference.html) (required) — A reference to a Function resource.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) (required) — The principal this Lambda Function is running as.

- `isBoundToVpc`: boolean (required) — Whether or not this Lambda function was bound to a VPC.

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

- `latestVersion`: [IVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IVersion.html) (required) — 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.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `permissionsNode`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The construct node where permissions are attached.

- `resourceArnsForGrantInvoke`: string[] (required) — The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role associated with this function.

  Undefined if the function was imported without a role.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

- `tenancyConfig`: [TenancyConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.TenancyConfig.html) — The tenancy configuration for this function.

## Methods

- `addEventSource(source: IEventSource): void` — Adds an event source to this function.

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

  The following example adds an SQS Queue as an event source:
  ```
  import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
  myFunction.addEventSource(new SqsEventSource(myQueue));
  ```

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

- `addFunctionUrl(options?: FunctionUrlOptions): FunctionUrl` — Adds a url to this lambda function.

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

  **Parameters**

  - `id` — The id for the permission construct.
  - `permission` — The permission to grant to this Lambda function.

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

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `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.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `configureAsyncInvoke(options: EventInvokeConfigOptions): void` — Configures options for asynchronous invocation.

- `considerWarningOnInvokeFunctionPermissions(scope: Construct, action: string): void` — A warning will be added to functions under the following conditions: - permissions that include `lambda:InvokeFunction` are added to the unqualified function.

  - function.currentVersion is invoked before or after the permission is created.

  This applies only to permissions on Lambda functions, not versions or aliases.
  This function is overridden as a noOp for QualifiedFunctionBase.

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

  [disable-awslint:no-grants]

- `grantInvokeCompositePrincipal(compositePrincipal: CompositePrincipal): Grant[]` — Grant multiple principals the ability to invoke this Lambda via CompositePrincipal.

  [disable-awslint:no-grants]

- `grantInvokeLatestVersion(grantee: IGrantable): Grant` — Grant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda.

  [disable-awslint:no-grants]

- `grantInvokeUrl(grantee: IGrantable): Grant` — Grant the given identity permissions to invoke this Lambda Function URL.

  [disable-awslint:no-grants]

- `grantInvokeVersion(grantee: IGrantable, version: IVersion): Grant` — Grant the given identity permissions to invoke the given version of this Lambda.

  [disable-awslint:no-grants]

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

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

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

  Average over 5 minutes

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

  Sum over 5 minutes

- `metricInvocations(props?: MetricOptions): Metric` — How often this Lambda is invoked.

  Sum over 5 minutes

- `metricThrottles(props?: MetricOptions): Metric` — How often this Lambda is throttled.

  Sum over 5 minutes

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
