Function
The Function
declaration specifies a Lambda function for deployment. Each declaration is compiled and uploaded as part of the deployment process. The deployed Lambda function is prefixed with ${Deployment::TierPrefix}
to uniquely distinguish is from other functions.
Use the lash new app command to add the Function
declaration with a pre-configured project to your module.
Syntax
Function: String
Description: String
Scope: ScopeDefinition
If: String or Expression
Memory: Int
Timeout: Int
Project: String
Handler: String
Runtime: String
Language: String
Pragmas:
- PragmaDefinition
Environment:
String: String or Expression
Properties:
ResourceProperties
Sources:
- SourceDefinition
DependsOn:
- String
Properties
DependsOn
-
The
DependsOn
attribute identifies items that must be created prior. For additional information, see CloudFormation DependsOn Attribute.Type: List of String
Description
-
The
Description
attribute specifies the description of the Lambda function.Required: No
Type: String
Environment
-
The
Environment
sections specifies key-value pairs that correspond to custom Lambda environment variables which can be retrieved by the Lambda function during initialization. The attribute can be a plaintext value or a CloudFormation expression (e.g.!Ref MyResource
).Required: No
Type: Map of key-value pair Expressions
Function
-
The
Function
attribute specifies the item name for the Lambda function.Required: Yes
Type: String
Handler
-
The
Handler
attribute specifies the fully qualified method reference to the Lambda function handler.Required: Conditional. By default, the .NET Core method reference is expected to be
${Module::Name}.${FunctionName}::${Namespace}.Function::FunctionHandlerAsync
where${Namespace}
is determined by inspecting the<RootNamespace>
element of the .NET Core project file. If the Lambda function handler is not calledFunctionHandlerAsync
, or the class implemented it is not calledFunction
, or the<RootNamespace>
is not specified in the .NET Core project file, theHandler
attribute must be specified. Otherwise, it can be omitted. For javascript functions, theHandler
is set toindex.handler
by default.Type: String
If
-
The
If
attribute specifies a condition that must be met for the Lambda function to be included in the deployment. The condition can either the name of aCondition
item or a logical expression.Required: No.
Type: String or Expression
Memory
-
The
Memory
attribute specifies the memory limit for the lambda function. The value must be in the range of 128 MB up to 3008 MB, in 64 MB increments.Required: Yes
Type: Int
Pragmas
-
The
Pragmas
section specifies directives that change the default compiler behavior.Required: No
Type: List of Pragma Definition
Project
-
The
Project
attribute specifies the relative path of the function project file or its folder.Required: Conditional. By default, the .NET Core project file is expected to be located in a sub-folder of the module definition. The name of the sub-folder and project file are expected to match the function name. If that is not the case, then the
Project
attribute must be specified. Otherwise, it can be omitted.Type: String
Properties
-
The
Properties
section specifies additional options that can be specified for a Lambda function (seeAWS::Lambda::Function
CloudFormation type). This section is copied verbatim into the CloudFormation template and can use CloudFormation intrinsic functions (e.g.!Ref
,!Join
,!Sub
, etc.) for referencing other resources.Required: No
Type: Map
Runtime
-
The
Runtime
attribute specifies the Lambda runtime to use to run the function.Required: Conditional. By default, the runtime is determined by inspecting the function sub-folder. If the runtime cannot be determined automatically, then it must be specified. Otherwise, it can be omitted.
Type: String
Scope
-
The
Scope
attribute specifies which functions need to have access to this item. TheScope
attribute can be a comma-separated list or a YAML list of function names. If all functions need the item, thenall
can be used as a wildcard. In addition,public
can be used to export the item from the module. Alternatively,stack
can be used to make the item available only in a nested stack.Required: No
Type: Comma-delimited String or List of String
Sources
-
The
Sources
section specifies zero or more source definitions the Lambda function expects to be invoked by. Each source automatically grants the Lambda invocation permission to the invoking service.Required: No
Type: List of Source Definition
Timeout
-
The
Timeout
attribute specifies the execution time limit in seconds. The maximum value is 900 seconds (15 minutes).Required: Yes
Type: Int
Examples
A vanilla Lambda function
- Function: MyFunction
Memory: 128
Timeout: 15
A Lambda function with an SNS event source
- Function: MyFunction
Memory: 128
Timeout: 15
Sources:
- Topic: MySnsTopic
A conditional Lambda function
- Condition: IsFunctionWanted
Value: !Equals [ !Ref WantFunctionParameter, "yes" ]
- Function: MyFunction
If: IsFunctionWanted
Memory: 128
Timeout: 15
The above definitions can be expressed more concisely if the Condition
item never used by anywhere else.
- Function: MyFunction
If: !Equals [ !Ref WantFunctionParameter, "yes" ]
Memory: 128
Timeout: 15
A Lambda function with properties
- Function: MyFunction
Memory: 128
Timeout: 15
Properties:
ReservedConcurrentExecutions: 1
VpcConfig:
SecurityGroupIds: !Split [ ",", !Ref SecurityGroupIds ]
SubnetIds: !Split [ ",", !Ref SubnetIds ]