Lambda Code Property Does Not Support String Value.
In the below "AWS::Lambda::Function" definition, for the "Code" property, I can just add a String value that is path to my lambda code. A common pattern is to use the aws package command before deployment. This command zips the code in the directory given (e.g. /src/lib), pushes the zip file to S3, and then modifies your cloudformation file for you to update the bucket name and location.
Troposphere does not currently support the ability to provide a string value for the Code property on the AWS::Lambda::Function type.
Resources:
ServicePromotionsConsumer:
Type: AWS::Lambda::Function
Properties:
FunctionName: my-function
Description: "Does stuff"
Handler: "File.lambda_handler"
Role: my-role
Code: /src/lib
Runtime: python3.6
Timeout: 60
MemorySize: 128
In lieu of Troposphere supporting this properly, we get around it by doing the following:
class PackageableFunction(Function):
def __init__(self, title, template=None, validation=True, **kwargs):
self.props['Code'] = (basestring, True)
super(PackageableFunction, self).__init__(title, template, validation, **kwargs)
support both with
self.props['Code'] = ((troposphere.awslambda.Code, str), True)
Question is whether AWS::Lambda::Function should just be changed to:
'Code': ((Code, basestring), True),
Or do something similar to the above and FunctionForPackaging located in serverless.py.