2

I have a simple lambda function which accepts an argument and prints it.

import json def lambda_handler(event, context): temp = event["temp"] return { 'statuscode': 200, 'body': json.dumps(f'Hello from {temp}!') } 

I've enabled function url in lambda and set authorization as None. Without any arguments, curl https://xxxx.lambda-url.us-east-1.on.aws works.

Using Test through the console, I get the correct output, but not through a curl call.

curl -X POST https://xxxx.lambda-url.us-east-1.on.aws \ -H 'content-type: application/json' \ --data '{"temp":"Hello World"}' \ > Internal Server Error% 
2
  • 1
    It's worth getting familiar with debugging Lambda functions via CloudWatch Logs. Commented Nov 5, 2022 at 22:54
  • True, it was right there haha Commented Nov 6, 2022 at 13:42

1 Answer 1

3

You forgot a step in your code. You have to extract the body first from the event, and then you can extract the temp attribute from the body, for example like this:

def lambda_handler(event, context): body = json.loads(event['body']) temp = body['temp'] return { 'statuscode': 200, 'body': json.dumps(f'Hello from {temp}!') } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, that worked like a charm. I got confused with how I used to do with google cloud functions. Should start looking at cloudwatch logs, dumb of me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.