skip to Main Content

I am trying to allow requests to my Lambda Function URL only from my specific URL and only for POST methods.

Here is my Lambda Function URL configuration:

Lambda Function URL configuration

Here is the Lambda function content:

import json

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

Problems:

  1. When I go to the function URL on my browser I see "Hello from
    Lambda!!". Considering it is a GET call I shouldn’t see the result
    right?
  2. When I call the function URL with HTTP POST method from my Angular App (origin: localhost:4200), I am getting CORS error "No ‘Access-Control-Allow-Origin’ header is present on the requested resource." But I added that header to my request as shown in the screenshot below:

Angular request screenshot

I tried ‘Access-Control-Allow-Origin’: ‘*’ as well but it didn’t work.

What am I doing wrong here?

2

Answers


  1. Chosen as BEST ANSWER

    After some trial and error, I found the solution.

    As seen in the screenshot below, I added the same headers to Expose Headers in Lambda Function URL config. This way, "No 'Access-Control-Allow-Origin' header is present on the requested resource." error is gone, since they are now exposed to the requester.

    Lambda Function URL config

    I'm still open to suggestions about whether I should change those allowed and exposed headers, if all is not required.

    Thanks.


  2. It’s answered over in: API Gateway CORS: no 'Access-Control-Allow-Origin' header – you need to return the CORS headers also in the lambda response OR add an OPTIONS call to have the CORS response.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search