AWS::Serverless::Function

The AWS::Serverless::Function resource type is used to define and create Lambda functions and it's associated event source mappings which trigger the function.

Consider the flowing example snippet for creating a simple Lambda function using SAM:

Handler: index.js 
Runtime: nodejs4.3 
CodeUri: 's3://myS3Bucket/function.zip' 
Description: A simple function for demonstrating SAM 
MemorySize: 128 
Timeout: 15 
Policies: 
 - LambdaFunctionExecutePolicy  
 - Version: '2012-10-17'  
   Statement: 
     - Effect: Allow 
       Action: 
         - s3:GetObject 
         - s3:GetObjectACL 
       Resource: 'arn:aws:s3:::myS3Bucket/*' 
Environment: 
  Variables: 
    key1: Hello 
    key2: World 

From the following snippet, most of the properties should be well known by now, including the Handler, Runtime, MemorySize, Timeout, and so on. The CodeUri refers to the S3 URI or any other valid location from where SAM will obtain the Lambda function for deployment. It's important to note, however, that this has to be a packaged Lambda function (.zip) even if it contains just a single index.js file.

The Policies section contains the names of either the AWS managed IAM policies or IAM policy documents that this function will require for execution; and finally we have the Environment section that can be used to set the function's environment variables as well.