1

...created an IAM role called XYZ with the following policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": "*"
        }
    ]
}

...updated the trust relationship XYZ role to include both lambda and API gateway

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "lambda.amazonaws.com",
          "apigateway.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

...created a Lambda function and attached role XYZ. I can execute the Lambda function successfully.

from __future__ import print_function

import json
import datetime

def lambda_handler(event, context):
    ts = datetime.datetime.now().timestamp()
    print (ts)
    print ("Hello")
    #raise Exception('Something went wrong')

...attached an API gateway to the Lambda function. I specified XYZ as the execution role of the method.

I get "null" when invoking the API

Any suggestions as to why?

1 Answer 1

1

Your lambda_handler isn't returning anything. Try:

def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': 'Hello'
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Bingo! Yep, that fixed it. Thank you!

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.