AWS Lambda with Single CloudFormation Template


This is just a quick snippet of CloudFormation template to deploy a Python 3.7 Lambda function embedded in the template. The source code inside ZipFile can contain up to 4KB.

# CloudFormation template
AWSTemplateFormatVersion: 2010-09-09
Resources:
LambdaCode:
Type: AWS::Lambda::Function
DependsOn:
- LambdaRole
- LambdaPolicy
Properties:
Code:
ZipFile: |
import boto3
def handler(event, context):
...
Role: !GetAtt LambdaRole.Arn
Runtime: python3.7
Handler: index.handler

Note: the depending LambdaRole is not included, but can be found easily here .

🙂