Monday, May 15, 2017

errorMessage: Bad handler

When trying to create an AWS Lambda function if you get this error message:

errorMessage: Bad handler 

Make sure when specifying the handler you use the format [file name].[function name].

For example if you have the function configure_firebox and the python file name is fireboxconfig.py then specify the handler as fireboxconfig.configure_firebox

If you are specifying the name correctly and still getting the error, take a look at your zip file and make sure the python file you are referencing is at the root of the zip file, not in any folders when the code is unzipped.

If you are trying to use the zip function to zip a file into the archive without the directories use the -j switch:

zip -j ./resources/firebox-lambda/fireboxconfig.zip ./resources/firebox-lambda/python/fireboxconfig.py 


Also check for any spelling errors in your file or handler name.

In CloudFormation:

FireboxConfigurationLambda:
    Type: "AWS::Lambda::Function"
    Properties: 
      Code:
        S3Bucket: !ImportValue FireboxPrivateBucket
        S3Key: fireboxconfig.zip
      Description: Firebox Lambda to Execute CLI Commands
      Environment:
        Variables:
          Test: Value
      FunctionName: ConfigureFirebox
      Handler: fireboxconfig.configure_firebox
      KmsKeyArn: !ImportValue FireboxKmsKeyArn
      MemorySize: 128
      Role: !ImportValue FireboxLambdaCLIRoleArn
      Runtime: python3.6
      Timeout: 3
      VpcConfig:
        SecurityGroupIds:
          - !ImportValue FireboxManagementSecurityGroup
        SubnetIds:
          - !ImportValue FireboxCLISubnet

More:

http://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html

https://github.com/tradichel/FireboxCloudAutomation/blob/master/code/resources/firebox-lambda/lambda.yaml