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
DependsOnattribute identifies items that must be created prior. For additional information, see CloudFormation DependsOn Attribute.Type: List of String
Description-
The
Descriptionattribute specifies the description of the Lambda function.Required: No
Type: String
Environment-
The
Environmentsections 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
Functionattribute specifies the item name for the Lambda function.Required: Yes
Type: String
Handler-
The
Handlerattribute 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::FunctionHandlerAsyncwhere${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, theHandlerattribute must be specified. Otherwise, it can be omitted. For javascript functions, theHandleris set toindex.handlerby default.Type: String
If-
The
Ifattribute specifies a condition that must be met for the Lambda function to be included in the deployment. The condition can either the name of aConditionitem or a logical expression.Required: No.
Type: String or Expression
Memory-
The
Memoryattribute 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
Pragmassection specifies directives that change the default compiler behavior.Required: No
Type: List of Pragma Definition
Project-
The
Projectattribute 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
Projectattribute must be specified. Otherwise, it can be omitted.Type: String
Properties-
The
Propertiessection specifies additional options that can be specified for a Lambda function (seeAWS::Lambda::FunctionCloudFormation 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
Runtimeattribute 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
Scopeattribute specifies which functions need to have access to this item. TheScopeattribute can be a comma-separated list or a YAML list of function names. If all functions need the item, thenallcan be used as a wildcard. In addition,publiccan be used to export the item from the module. Alternatively,stackcan be used to make the item available only in a nested stack.Required: No
Type: Comma-delimited String or List of String
Sources-
The
Sourcessection 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
Timeoutattribute 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 ]