Cannot add code to AWS Lambda function using CloudFormation

懵懂的女人 提交于 2019-12-22 04:19:17

问题


I'm trying to create the Cloud Formation Stack. The Stack was deployed correctly. Lambda function was created, but the code is not getting added as inline to the function.

It says

Your Lambda function "lambda_function" cannot be edited inline since the file name specified in the handler does not match a file name in your deployment package.

Cloud Formation Code:

  LambdaFunction:
    Type: "AWS::Lambda::Function"
    Properties:
      Code:
        ZipFile: !Sub |
          import json

          def lambda_handler(event,context):
              #Creating delete request
              ...

      Description: Lambda function.
      FunctionName: lambda_function
      Handler: lambda_function.lambda_handler
      Role : !GetAtt LambdaExecutionRole.Arn
      Runtime: python2.7
      Timeout: 5

回答1:


The first part of the handler should always be index if you specify the code inline.

If you specify your source code as inline text by specifying the ZipFile property within the Code property, specify index.function_name as the handler. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

So just use this:

LambdaFunction:
    Type: "AWS::Lambda::Function"
    Properties:
      Code:
        ZipFile: !Sub |
          import json

          def lambda_handler(event,context):
              #Creating delete request
              ...

      Description: Lambda function.
      FunctionName: lambda_function
      Handler: index.lambda_handler
      Role : !GetAtt LambdaExecutionRole.Arn
      Runtime: python2.7
      Timeout: 5

Notice index.lambda_handler instead of lambda_function.lambda_handler.



来源:https://stackoverflow.com/questions/43634640/cannot-add-code-to-aws-lambda-function-using-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!