8

So I just started learning AWS Lambda today and tried to create a simple Hello World function in Python. The sample code which AWS generates looks like this:

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Running this code gives the following output:

Response
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

But now when I try to modify this code and run it I get the exact same output as the sample code. I modified it to this:

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello!')
    }

But I still get this as output:

Response
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

Things I've tried:

  1. Deleting the function and creating a new one.
  2. Using a different test event.

Neither worked. I also watched videos on YouTube where people are doing exactly what I was and their code change seemed to work. Can someone please help me with what I am missing?

5
  • 2
    How do you run your script? Looks to me like you accidentally run an older script (file). Commented Sep 30, 2020 at 21:57
  • are you editing the code in the AWS Console directly? how are you running/testing the function? Commented Oct 1, 2020 at 0:44
  • I run my script by clicking "Test" directly from the console. I am making changes to the sample script and not creating a new file. So I am not sure how the old version of script may get executed. And yes, I'm editing the code directly in the AWS console. Commented Oct 1, 2020 at 6:20
  • @Utkarsh, note that besides pressing CTRL S in the consule, you also has a Save box at the top of the editor which really deploys the Lambda. Commented Oct 1, 2020 at 8:27
  • 5
    It finally worked. Changes to the code only reflected when I click on "Deploy" first and then "Test". Commented Oct 1, 2020 at 11:51

2 Answers 2

15

Clicking on "Deploy" first and then "Test" worked for me.

Sign up to request clarification or add additional context in comments.

2 Comments

This should be a comment and not an answer.
I am unable to leave comments yet as I don't have 50 reputation but I wanted to give the solution that worked for me in order to help others.
0

Check If you have selected the correct runtime while creating the lamda function

1 Comment

This should rather be a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.