Recieving 403 error upon calling post request to api gateway

0

Hi, currently im trying to invoke an api gateway that invokes a lambda function. Im doing this all from a local development server, not sure if thats the problem but i think i should be able to do so eitherway let me know if not. But im using django for my apps backend and thats where im running into the issue. i recive the response itself but i also recieve a 403 code. the response is just null however. here is my code for my django view:

@api_view(['POST'])
def invoke_endpoint(request):
    #call lambda function in the cloud to invoke sagemaker endpoint for response generation
    input = request.data.get('query','')
    lambda_payload = {
        "queryStringParameters": input,
    }
    
    session = Session()
    credentials = session.get_credentials()
    aws_access_key = credentials.access_key
    aws_secret_key = credentials.secret_key
    region = session.region_name
    service = 'execute-api'
    endpoint = 'endpoint-link/generatearesposne'
    auth = AWS4Auth(aws_access_key, aws_secret_key, region, service)
    
    payload_bytes = json.dumps(lambda_payload).encode('utf-8')
    r = requests.post(endpoint, data=payload_bytes, auth=auth)
    response_payload = r.json()

    print(r)
    
    return JsonResponse({'response-payload': response_payload})

i am providing the auth to be able to call the function, i also have the aws cli setup and am configured to a user that has permissions to use lambda, sagemaker and api gateway. im not sure what else i need or if im making some sort of mistake here. fairly new user of AWS so im not sure.

my response looks like this: <Response [403]>

  • As mentioned in the article provided by @Didier_Durand, check the x-amzn-errortype response header to get more information about the root cause.

1 Answer
0

Hi,

An HTTP 403 response code means that a client is forbidden from accessing a valid URL. The server understands the request, but it can't fulfill the request because of client-side issues.

So, check out this article to learn how to fix all possible causes: https://repost.aws/knowledge-center/api-gateway-troubleshoot-403-forbidden

Best,

Didier

profile pictureAWS
EXPERT
answered 6 months ago
profile picture
EXPERT
reviewed 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions