AWS Lambda function API end point - 403 and 415 error
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:
I have a GET method ('Options' appeared after I enabled CORS):
Here's what happens when I click 'Enable CORS':
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:
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:
And after I enabled CORS:
amazon-web-services aws-lambda aws-api-gateway
add a comment |
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:
I have a GET method ('Options' appeared after I enabled CORS):
Here's what happens when I click 'Enable CORS':
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:
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:
And after I enabled CORS:
amazon-web-services aws-lambda aws-api-gateway
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
add a comment |
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:
I have a GET method ('Options' appeared after I enabled CORS):
Here's what happens when I click 'Enable CORS':
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:
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:
And after I enabled CORS:
amazon-web-services aws-lambda aws-api-gateway
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:
I have a GET method ('Options' appeared after I enabled CORS):
Here's what happens when I click 'Enable CORS':
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:
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:
And after I enabled CORS:
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
amazon-web-services aws-lambda aws-api-gateway
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
Thanks for the tip! Option to disable on the root was disabled for some reason.
– Kira Pilot
Jan 3 at 0:12
add a comment |
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)
});
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Thanks for the tip! Option to disable on the root was disabled for some reason.
– Kira Pilot
Jan 3 at 0:12
add a comment |
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.
Thanks for the tip! Option to disable on the root was disabled for some reason.
– Kira Pilot
Jan 3 at 0:12
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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)
});
}
add a comment |
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)
});
}
add a comment |
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)
});
}
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)
});
}
answered Jan 3 at 0:18


Kira PilotKira Pilot
19014
19014
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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