2

I am utterly confused by the docs in AWS.

What I tried

  1. Signed up an AWS account using the region us-west-2
  2. Created a Lambda function called helloworld

enter image description here

  1. Created a handler called hello_world inside.

enter image description here

  1. Selected Actions > Configure Test Event > Selected Common > Hello World

enter image description here

  1. Press Test and I get the following error messages:

    The area below shows the result returned by your function execution. { "errorMessage": "Syntax error in module 'helloworld'" }

enter image description here

and

START RequestId: f71b8c46-ecc8-11e5-91b6-c55c85fd12cb Version: $LATEST
Syntax error in module 'helloworld': invalid syntax (helloworld.py, line 1)

END RequestId: f71b8c46-ecc8-11e5-91b6-c55c85fd12cb
REPORT RequestId: f71b8c46-ecc8-11e5-91b6-c55c85fd12cb  Duration: 0.29 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 10 MB  

enter image description here

What I wanted

I just want to get a successful execution of a python hello world, so I know where I am supposed to observe the output and how to run the script.

Updates

I have changed the code to

def print_something(entry, second_entry):
    print str(entry)
    print str(second_entry)
    return str(second_entry)

And it is executed properly.

This is what I saw:

START RequestId: 33bf2a83-ecda-11e5-bdcd-2de843a18bed Version: $LATEST
{u'key3': u'value3', u'key2': u'value2', u'key1': u'value1'}
<__main__.LambdaContext object at 0x7f66d1848990>
END RequestId: 33bf2a83-ecda-11e5-bdcd-2de843a18bed

What on earth is that LamdaContext object that appears as the second param?

3 Answers 3

3

Two issues:

  1. the python function was wrongly defined

  2. the main handler for Lambda requires 2 arguments

Answer:

def hello_world(event_data, lambda_config):
    print "hello world"

For more information on the arguments for the main handler, read http://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html

Excerpt:

Use the following general syntax structure when creating a handler function in Python.

def handler_name(event, context): 
    ...
    return some_value

In the syntax, note the following:

  • event – AWS Lambda uses this parameter to pass in event data to the handler. This parameter is usually of the Python dict type. It can also be list, str, int, float, or NoneType type.
  • context – AWS Lambda uses this parameter to provide runtime information to your handler. This parameter is of the LambdaContext type.
  • Optionally, the handler can return a value. What happens to the returned value depends on the invocation type you use when invoking the Lambda function: If you use the RequestResponse invocation type (synchronous execution), AWS Lambda returns the result of the Python function call to the client invoking the Lambda function (in the HTTP response to the invocation request, serialized into JSON). For example, AWS Lambda console uses the RequestResponse invocation type, so when you test invoke the function using the console, the console will display the returned value. If the handler does not return anything, AWS Lambda returns null. If you use the Event invocation type (asynchronous execution), the value is discarded.
Sign up to request clarification or add additional context in comments.

Comments

1

change your python syntax into

def event_handler(event,context):
    message = "hello{0}".format(event['world'])
return mesaage 

here event always like dictionary type object and Context is lambda context

Comments

0

For python function:

def helloworld(): print "helloworld"

then, in the configuration you should use "helloworld" as lambda handler.

2 Comments

Your answer helped me get it sorta working. Now the issue is that my main handler needs to take in 2 parameters. Not sure why.
because lambda handler needs two arguments, such as def lambda_handler(event, context): ..... maybe you can read the document of aws lambda for more infomations.

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.