Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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 Answer

0 votes
by (44.4k points)

When you specify the code inline, then the first part of the handler should always be index.

Check out this documentation for more information: AWS::Lambda::Function

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

It should be index.lambda_handler instead of lambda_function.lambda_handler.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...