Skip to content
v2.273.0

FunctionBase L2 construct ​

Initializer ​

ts
new FunctionBase(scope: Construct, id: string, props?: ResourceProps)
python
FunctionBase(scope: Construct, id: str, props: typing.Optional[ResourceProps] = None)
java
new FunctionBase(Construct scope, String id, ResourceProps props)
csharp
new FunctionBase(Construct scope, string id, ResourceProps? props = null)
go
NewFunctionBase(Scope Construct, Id *string, Props ResourceProps)

Construct Props ​

accountstringaccountstraccountStringAccountstringAccount*string= the resource is in the same acco…#
The AWS account ID this resource belongs to.
default

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

environmentFromArnstringenvironment_from_arnstrenvironmentFromArnStringEnvironmentFromArnstringEnvironmentFromArn*string= take environment from `account`,…#
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

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

physicalNamestringphysical_namestrphysicalNameStringPhysicalNamestringPhysicalName*string= The physical name will be alloca…#
The value passed in by users to the physical name prop of the resource.
notes · default
  • 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

regionstringregionstrregionStringRegionstringRegion*string= the resource is in the same regi…#
The AWS region this resource belongs to.
default

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

Properties ​

architectureArchitecturearchitectureArchitecturearchitectureArchitectureArchitectureArchitectureArchitectureArchitecturerequired#
The architecture of this Lambda Function.
connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#
Access the Connections object.

Will fail if not a VPC-enabled Lambda Function

The environment this resource belongs to.
notes

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.

functionArnstringfunction_arnstrfunctionArnStringFunctionArnstringFunctionArn*stringrequired#
The ARN fo the function.
functionNamestringfunction_namestrfunctionNameStringFunctionNamestringFunctionName*stringrequired#
The name of the function.
functionRefFunctionReferencefunction_refFunctionReferencefunctionRefFunctionReferenceFunctionRefFunctionReferenceFunctionRefFunctionReferencerequired#
A reference to a Function resource.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal this Lambda Function is running as.
isBoundToVpcbooleanis_bound_to_vpcboolisBoundToVpcBooleanIsBoundToVpcboolIsBoundToVpc*boolrequired#
Whether or not this Lambda function was bound to a VPC.

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

latestVersionIVersionlatest_versionIVersionlatestVersionIVersionLatestVersionIVersionLatestVersionIVersionrequired#
The `$LATEST` version of this function.
notes

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.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
permissionsNodeNodepermissions_nodeNodepermissionsNodeNodePermissionsNodeNodePermissionsNodeNoderequired#
The construct node where permissions are attached.
resourceArnsForGrantInvokestring[]resource_arns_for_grant_invoketyping.List[str]resourceArnsForGrantInvokeList<String>ResourceArnsForGrantInvokestring[]ResourceArnsForGrantInvoke*[]*stringrequired#
The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole#
The IAM role associated with this function.

Undefined if the function was imported without a role.

stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
tenancyConfigTenancyConfigtenancy_configTenancyConfigtenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfig#
The tenancy configuration for this function.

Methods ​

addEventSource(source: IEventSource): voiddef add_event_source(self, source: IEventSource) -> Nonepublic void addEventSource(IEventSource source)public void AddEventSource(IEventSource source)func AddEventSource(Source IEventSource)#
Adds an event source to this function.
notes

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): EventSourceMappingdef add_event_source_mapping(self, id: str, options: EventSourceMappingOptions) -> EventSourceMappingpublic EventSourceMapping addEventSourceMapping(String id, EventSourceMappingOptions options)public EventSourceMapping AddEventSourceMapping(string id, EventSourceMappingOptions options)func AddEventSourceMapping(Id *string, Options EventSourceMappingOptions) EventSourceMapping#
Adds an event source that maps to this AWS Lambda function.
addFunctionUrl(options?: FunctionUrlOptions): FunctionUrldef add_function_url(self, options: typing.Optional[FunctionUrlOptions] = None) -> FunctionUrlpublic FunctionUrl addFunctionUrl(FunctionUrlOptions options)public FunctionUrl AddFunctionUrl(FunctionUrlOptions? options = null)func AddFunctionUrl(Options FunctionUrlOptions) FunctionUrl#
Adds a url to this lambda function.
addPermission(id: string, permission: Permission): voiddef add_permission(self, id: str, permission: Permission) -> Nonepublic void addPermission(String id, Permission permission)public void AddPermission(string id, Permission permission)func AddPermission(Id *string, Permission Permission)#
Adds a permission to the Lambda resource policy.
2 parameters

Parameters

  • ididididId — The id for the permission construct.
  • permissionpermissionpermissionpermissionPermission — The permission to grant to this Lambda function.
addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Adds a statement to the IAM role assumed by the instance.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

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

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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): voiddef configure_async_invoke(self, options: EventInvokeConfigOptions) -> Nonepublic void configureAsyncInvoke(EventInvokeConfigOptions options)public void ConfigureAsyncInvoke(EventInvokeConfigOptions options)func ConfigureAsyncInvoke(Options EventInvokeConfigOptions)#
Configures options for asynchronous invocation.
considerWarningOnInvokeFunctionPermissions(scope: Construct, action: string): voiddef consider_warning_on_invoke_function_permissions(self, scope: Construct, action: str) -> Nonepublic void considerWarningOnInvokeFunctionPermissions(Construct scope, String action)public void ConsiderWarningOnInvokeFunctionPermissions(Construct scope, string action)func ConsiderWarningOnInvokeFunctionPermissions(Scope Construct, Action *string)#
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): Grantdef grant_invoke(self, grantee: IGrantable) -> Grantpublic Grant grantInvoke(IGrantable grantee)public Grant GrantInvoke(IGrantable grantee)func GrantInvoke(Grantee IGrantable) Grant#
Grant the given identity permissions to invoke this Lambda.

[disable-awslint:no-grants]

grantInvokeCompositePrincipal(compositePrincipal: CompositePrincipal): Grant[]def grant_invoke_composite_principal(self, composite_principal: CompositePrincipal) -> typing.List[Grant]public List<Grant> grantInvokeCompositePrincipal(CompositePrincipal compositePrincipal)public Grant[] GrantInvokeCompositePrincipal(CompositePrincipal compositePrincipal)func GrantInvokeCompositePrincipal(CompositePrincipal CompositePrincipal) *[]Grant#
Grant multiple principals the ability to invoke this Lambda via CompositePrincipal.

[disable-awslint:no-grants]

grantInvokeLatestVersion(grantee: IGrantable): Grantdef grant_invoke_latest_version(self, grantee: IGrantable) -> Grantpublic Grant grantInvokeLatestVersion(IGrantable grantee)public Grant GrantInvokeLatestVersion(IGrantable grantee)func 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): Grantdef grant_invoke_url(self, grantee: IGrantable) -> Grantpublic Grant grantInvokeUrl(IGrantable grantee)public Grant GrantInvokeUrl(IGrantable grantee)func GrantInvokeUrl(Grantee IGrantable) Grant#
Grant the given identity permissions to invoke this Lambda Function URL.

[disable-awslint:no-grants]

grantInvokeVersion(grantee: IGrantable, version: IVersion): Grantdef grant_invoke_version(self, grantee: IGrantable, version: IVersion) -> Grantpublic Grant grantInvokeVersion(IGrantable grantee, IVersion version)public Grant GrantInvokeVersion(IGrantable grantee, IVersion version)func 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@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#
Return the given named metric for this Function.
metricDuration(props?: MetricOptions): Metricdef metric_duration(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricDuration(MetricOptions props)public Metric MetricDuration(MetricOptions? props = null)func MetricDuration(Props MetricOptions) Metric#
How long execution of this Lambda takes.

Average over 5 minutes

metricErrors(props?: MetricOptions): Metricdef metric_errors(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricErrors(MetricOptions props)public Metric MetricErrors(MetricOptions? props = null)func MetricErrors(Props MetricOptions) Metric#
How many invocations of this Lambda fail.

Sum over 5 minutes

metricInvocations(props?: MetricOptions): Metricdef metric_invocations(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricInvocations(MetricOptions props)public Metric MetricInvocations(MetricOptions? props = null)func MetricInvocations(Props MetricOptions) Metric#
How often this Lambda is invoked.

Sum over 5 minutes

metricThrottles(props?: MetricOptions): Metricdef metric_throttles(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricThrottles(MetricOptions props)public Metric MetricThrottles(MetricOptions? props = null)func MetricThrottles(Props MetricOptions) Metric#
How often this Lambda is throttled.

Sum over 5 minutes

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.