AWS Lambda function API end point - 403 and 415 error












1















I have an AWS Lambda function that I've set up and am attempting to hit from the front end. It works fine in browser, and returns the response I expect. When I try to hit it from localhost, I get a 403. I have tried to follow the steps outlined here and here (short of blowing away my entire API as some commenters mentioned), to no avail. I redeploy after all changes. After enabling CORS, I cease to get a 403, and instead get a 415. Unsure what to do next as there's nothing in the Cloudwatch logs.



Some more detail: I am using a Lambda:



enter image description here



I have a GET method ('Options' appeared after I enabled CORS):



enter image description here



Here's what happens when I click 'Enable CORS':



enter image description here



Because it's cut off in the screenshot, here is the complete list of headers: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'



Here's my Method Response:
enter image description here



Here's how I call my lambda on the front end:






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}





Here are the errors I'm getting. The first error, before I enable CORS:
enter image description here



And after I enabled CORS:
enter image description here










share|improve this question




















  • 1





    Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

    – varnit
    Jan 2 at 19:24











  • Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

    – varnit
    Jan 2 at 19:25











  • Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

    – Kira Pilot
    Jan 2 at 19:26











  • I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

    – varnit
    Jan 2 at 19:28
















1















I have an AWS Lambda function that I've set up and am attempting to hit from the front end. It works fine in browser, and returns the response I expect. When I try to hit it from localhost, I get a 403. I have tried to follow the steps outlined here and here (short of blowing away my entire API as some commenters mentioned), to no avail. I redeploy after all changes. After enabling CORS, I cease to get a 403, and instead get a 415. Unsure what to do next as there's nothing in the Cloudwatch logs.



Some more detail: I am using a Lambda:



enter image description here



I have a GET method ('Options' appeared after I enabled CORS):



enter image description here



Here's what happens when I click 'Enable CORS':



enter image description here



Because it's cut off in the screenshot, here is the complete list of headers: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'



Here's my Method Response:
enter image description here



Here's how I call my lambda on the front end:






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}





Here are the errors I'm getting. The first error, before I enable CORS:
enter image description here



And after I enabled CORS:
enter image description here










share|improve this question




















  • 1





    Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

    – varnit
    Jan 2 at 19:24











  • Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

    – varnit
    Jan 2 at 19:25











  • Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

    – Kira Pilot
    Jan 2 at 19:26











  • I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

    – varnit
    Jan 2 at 19:28














1












1








1








I have an AWS Lambda function that I've set up and am attempting to hit from the front end. It works fine in browser, and returns the response I expect. When I try to hit it from localhost, I get a 403. I have tried to follow the steps outlined here and here (short of blowing away my entire API as some commenters mentioned), to no avail. I redeploy after all changes. After enabling CORS, I cease to get a 403, and instead get a 415. Unsure what to do next as there's nothing in the Cloudwatch logs.



Some more detail: I am using a Lambda:



enter image description here



I have a GET method ('Options' appeared after I enabled CORS):



enter image description here



Here's what happens when I click 'Enable CORS':



enter image description here



Because it's cut off in the screenshot, here is the complete list of headers: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'



Here's my Method Response:
enter image description here



Here's how I call my lambda on the front end:






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}





Here are the errors I'm getting. The first error, before I enable CORS:
enter image description here



And after I enabled CORS:
enter image description here










share|improve this question
















I have an AWS Lambda function that I've set up and am attempting to hit from the front end. It works fine in browser, and returns the response I expect. When I try to hit it from localhost, I get a 403. I have tried to follow the steps outlined here and here (short of blowing away my entire API as some commenters mentioned), to no avail. I redeploy after all changes. After enabling CORS, I cease to get a 403, and instead get a 415. Unsure what to do next as there's nothing in the Cloudwatch logs.



Some more detail: I am using a Lambda:



enter image description here



I have a GET method ('Options' appeared after I enabled CORS):



enter image description here



Here's what happens when I click 'Enable CORS':



enter image description here



Because it's cut off in the screenshot, here is the complete list of headers: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'



Here's my Method Response:
enter image description here



Here's how I call my lambda on the front end:






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}





Here are the errors I'm getting. The first error, before I enable CORS:
enter image description here



And after I enabled CORS:
enter image description here






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}





sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data
}).then((response) => {
console.log('response', response)
});
}






amazon-web-services aws-lambda aws-api-gateway






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 19:46







Kira Pilot

















asked Jan 2 at 19:02









Kira PilotKira Pilot

19014




19014








  • 1





    Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

    – varnit
    Jan 2 at 19:24











  • Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

    – varnit
    Jan 2 at 19:25











  • Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

    – Kira Pilot
    Jan 2 at 19:26











  • I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

    – varnit
    Jan 2 at 19:28














  • 1





    Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

    – varnit
    Jan 2 at 19:24











  • Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

    – varnit
    Jan 2 at 19:25











  • Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

    – Kira Pilot
    Jan 2 at 19:26











  • I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

    – varnit
    Jan 2 at 19:28








1




1





Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

– varnit
Jan 2 at 19:24





Possible duplicate of API Gateway CORS: no 'Access-Control-Allow-Origin' header

– varnit
Jan 2 at 19:24













Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

– varnit
Jan 2 at 19:25





Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer

– varnit
Jan 2 at 19:25













Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

– Kira Pilot
Jan 2 at 19:26





Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda.

– Kira Pilot
Jan 2 at 19:26













I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

– varnit
Jan 2 at 19:28





I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well

– varnit
Jan 2 at 19:28












2 Answers
2






active

oldest

votes


















1














CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.






share|improve this answer
























  • Thanks for the tip! Option to disable on the root was disabled for some reason.

    – Kira Pilot
    Jan 3 at 0:12



















0














So ended up figuring this out finally. The Content-Type of the request I was making on the front end was not Application/JSON, yet my Integration Request Mapping Template was. I solved this by adding the following to my request on the front end:






sendVerificationCode() {
let data = {
paramOne: x,
paramTwo: 'string',
paramThree: 'string'
}

return this.get('ajax').request(
'https://something.execute-api.us-east-1.amazonaws.com/beta/',
{
host: 'https://something.execute-api.us-east-1.amazonaws.com',
method: 'GET',
data: data,
contentType: 'application/json; charset=utf-8',
}
).then((response) => {
console.log('response', response)
});

}








share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011799%2faws-lambda-function-api-end-point-403-and-415-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.






    share|improve this answer
























    • Thanks for the tip! Option to disable on the root was disabled for some reason.

      – Kira Pilot
      Jan 3 at 0:12
















    1














    CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.






    share|improve this answer
























    • Thanks for the tip! Option to disable on the root was disabled for some reason.

      – Kira Pilot
      Jan 3 at 0:12














    1












    1








    1







    CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.






    share|improve this answer













    CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 at 20:14









    Nicki KleinNicki Klein

    515




    515













    • Thanks for the tip! Option to disable on the root was disabled for some reason.

      – Kira Pilot
      Jan 3 at 0:12



















    • Thanks for the tip! Option to disable on the root was disabled for some reason.

      – Kira Pilot
      Jan 3 at 0:12

















    Thanks for the tip! Option to disable on the root was disabled for some reason.

    – Kira Pilot
    Jan 3 at 0:12





    Thanks for the tip! Option to disable on the root was disabled for some reason.

    – Kira Pilot
    Jan 3 at 0:12













    0














    So ended up figuring this out finally. The Content-Type of the request I was making on the front end was not Application/JSON, yet my Integration Request Mapping Template was. I solved this by adding the following to my request on the front end:






    sendVerificationCode() {
    let data = {
    paramOne: x,
    paramTwo: 'string',
    paramThree: 'string'
    }

    return this.get('ajax').request(
    'https://something.execute-api.us-east-1.amazonaws.com/beta/',
    {
    host: 'https://something.execute-api.us-east-1.amazonaws.com',
    method: 'GET',
    data: data,
    contentType: 'application/json; charset=utf-8',
    }
    ).then((response) => {
    console.log('response', response)
    });

    }








    share|improve this answer




























      0














      So ended up figuring this out finally. The Content-Type of the request I was making on the front end was not Application/JSON, yet my Integration Request Mapping Template was. I solved this by adding the following to my request on the front end:






      sendVerificationCode() {
      let data = {
      paramOne: x,
      paramTwo: 'string',
      paramThree: 'string'
      }

      return this.get('ajax').request(
      'https://something.execute-api.us-east-1.amazonaws.com/beta/',
      {
      host: 'https://something.execute-api.us-east-1.amazonaws.com',
      method: 'GET',
      data: data,
      contentType: 'application/json; charset=utf-8',
      }
      ).then((response) => {
      console.log('response', response)
      });

      }








      share|improve this answer


























        0












        0








        0







        So ended up figuring this out finally. The Content-Type of the request I was making on the front end was not Application/JSON, yet my Integration Request Mapping Template was. I solved this by adding the following to my request on the front end:






        sendVerificationCode() {
        let data = {
        paramOne: x,
        paramTwo: 'string',
        paramThree: 'string'
        }

        return this.get('ajax').request(
        'https://something.execute-api.us-east-1.amazonaws.com/beta/',
        {
        host: 'https://something.execute-api.us-east-1.amazonaws.com',
        method: 'GET',
        data: data,
        contentType: 'application/json; charset=utf-8',
        }
        ).then((response) => {
        console.log('response', response)
        });

        }








        share|improve this answer













        So ended up figuring this out finally. The Content-Type of the request I was making on the front end was not Application/JSON, yet my Integration Request Mapping Template was. I solved this by adding the following to my request on the front end:






        sendVerificationCode() {
        let data = {
        paramOne: x,
        paramTwo: 'string',
        paramThree: 'string'
        }

        return this.get('ajax').request(
        'https://something.execute-api.us-east-1.amazonaws.com/beta/',
        {
        host: 'https://something.execute-api.us-east-1.amazonaws.com',
        method: 'GET',
        data: data,
        contentType: 'application/json; charset=utf-8',
        }
        ).then((response) => {
        console.log('response', response)
        });

        }








        sendVerificationCode() {
        let data = {
        paramOne: x,
        paramTwo: 'string',
        paramThree: 'string'
        }

        return this.get('ajax').request(
        'https://something.execute-api.us-east-1.amazonaws.com/beta/',
        {
        host: 'https://something.execute-api.us-east-1.amazonaws.com',
        method: 'GET',
        data: data,
        contentType: 'application/json; charset=utf-8',
        }
        ).then((response) => {
        console.log('response', response)
        });

        }





        sendVerificationCode() {
        let data = {
        paramOne: x,
        paramTwo: 'string',
        paramThree: 'string'
        }

        return this.get('ajax').request(
        'https://something.execute-api.us-east-1.amazonaws.com/beta/',
        {
        host: 'https://something.execute-api.us-east-1.amazonaws.com',
        method: 'GET',
        data: data,
        contentType: 'application/json; charset=utf-8',
        }
        ).then((response) => {
        console.log('response', response)
        });

        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 0:18









        Kira PilotKira Pilot

        19014




        19014






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011799%2faws-lambda-function-api-end-point-403-and-415-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory