troposphere icon indicating copy to clipboard operation
troposphere copied to clipboard

Lambda Code Property Does Not Support String Value.

Open corybill opened this issue 7 years ago • 3 comments

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

corybill avatar Jun 13 '18 20:06 corybill

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)

haylix-edward avatar Jun 27 '18 01:06 haylix-edward

support both with

self.props['Code'] = ((troposphere.awslambda.Code, str), True)

avoidik avatar Mar 07 '19 13:03 avoidik

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.

markpeek avatar Mar 07 '19 15:03 markpeek