I am using aws-serverless-express module for using lambda function with express js.
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
exports.handler = function (event, context, callback) {
awsServerlessExpress.proxy(server, event, context);
}
After that i have create AWS api gateway API with resource and method POST.
when I login , getting error- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9005' is therefore not allowed access. The response had HTTP status code 403.
Try specifying * in the swagger instead of example.com
On Thu, Aug 17, 2017, 2:40 AM webistan notifications@github.com wrote:
I am using aws-serverless-express module for using lambda function with
express js.const server = awsServerlessExpress.createServer(app, null,
binaryMimeTypes)
exports.handler = function (event, context, callback) {
awsServerlessExpress.proxy(server, event, context);
}After that i have create AWS api gateway API with resource and method POST.
when I login , getting error- No 'Access-Control-Allow-Origin' header is
present on the requested resource. Origin 'http://localhost:9005' is
therefore not allowed access. The response had HTTP status code 403.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-serverless-express/issues/90, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABy6l-I_3TIVVhB50fpUkQPrT3gMkQ5Kks5sZAptgaJpZM4O6BC5
.
where do I excactly find the swagger file ?
This was assuming you were using the example - swagger can be found here https://github.com/awslabs/aws-serverless-express/blob/master/example/simple-proxy-api.yaml. You can either configure OPTIONS at the API Gateway layer, or configure it at the Lambda layer (simpler) by using the cors middleware, see https://github.com/awslabs/aws-serverless-express/blob/master/example/app.js#L4.
I'm actually not using the example, so I got confused a little, the lambda layer would be more appropriate in my case, but I'm using the cors middleware in the app.js and still getting the same error ...
Verify your OPTIONS is going through to Lambda and is returning that
allowed origin.
On Thu, Aug 17, 2017, 12:33 PM sami karakoese notifications@github.com
wrote:
I'm actually not using the example, so I got confused a little, the lambda
layer would be more appropriate in my case, but I'm using the cors
middleware in the app.js and still getting the same error ...—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-serverless-express/issues/90#issuecomment-323171991,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABy6l1SPnypsJAjMlLxSQihi9OOsViFQks5sZJWAgaJpZM4O6BC5
.
I can actually catch the OPTIONS request and I'm setting "Access-Control-Allow-Origin" : "*" on the response, but the It seems like the next incomming POST request does give me the 502 error.
here is my console log:
POST https://[awsdomain]/dev/[route]/ 502 ()
confirm:1 XMLHttpRequest cannot load https://[awsdomain]/dev/[route]/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://[unkown aws domain]' is therefore not allowed access. The response had HTTP status code 50
I am actually communication with another lambda express backend (cors enabled) on the POST request, but this other backend has not the same domain like the unkown one ... Does lambda itself communicate with any other server under any circumstance ? I hope these are just some missconfigurations of my express app
Does lambda itself communicate with any other server under any circumstance
No.
I hope these are just some missconfigurations of my express app
This seems to be the case. It just occurred to me that "No 'Access-Control-Allow-Origin'" error is sometimes a red herring when an error occurred before API Gateway could handle it, and the error response does not include CORS configuration. It sounds like your second lambda express backend has some error.
when hit POST request by POSTMAN so working fine but in my angularjs code POST request convert to OPTIONS request in browser so it can't be reach server geetting same error 500 mention above.
how can we solve this issue.
$http({
url: API,
method: "POST",
data: {"name":"abc"},
dataType: 'json',
async: false,
headers: {"content-type": "application/json"}
}).success(function(data, status) {
console.log(data);
})
.error(function (error){
console.log(error);
});
can we create multiple function with proxy AWS API GATEWAY when using aws-serverless-express in AWS lambda function?
Yes, you just need to configure additional Resources on your API
On Wed, Aug 23, 2017, 6:11 AM webistan notifications@github.com wrote:
can we create multiple function with proxy AWS API GATEWAY when using
aws-serverless-express in AWS lambda function?—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-serverless-express/issues/90#issuecomment-324325892,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABy6l8naTquUm5quQU4Odv3Oeiv0Pacrks5sbCUbgaJpZM4O6BC5
.
only proxy resource work fine if we create custom resource with method and used than getting error:
missing authentication.
How is it possible for custom resource used in aws-serverless-express in lambda function?
solved issue by create resources with new proxy resources.
like this:
/login
/{proxy}
/dashboard
/{proxy}
This mechanism solved issue for allowed to different resources communicate different lambda function.
Access to XMLHttpRequest at 'https://pwyv0x4l7l.execute-api.us-west-2.amazonaws.com/dev/login' from origin 'http://34.215.214.199:3000' has been blocked by CORS policy: Request header field sessionid is not allowed by Access-Control-Allow-Headers in preflight response.
login:
handler: controller/usercontroller.login
events:
- http:
path: /login
method: post
cors:
origin: 'http://34.215.214.199:3000'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Access-Control-Allow-Headers
allowCredentials: false
function response(statusCode, message) {
return {
statusCode: statusCode,
headers: {
'Access-Control-Allow-Origin': 'http://34.215.214.199:3000' // Or use wildard * for testing
},
body: JSON.stringify(message)
};
}
can someone help me now why i am getting this error
Most helpful comment
Access to XMLHttpRequest at 'https://pwyv0x4l7l.execute-api.us-west-2.amazonaws.com/dev/login' from origin 'http://34.215.214.199:3000' has been blocked by CORS policy: Request header field sessionid is not allowed by Access-Control-Allow-Headers in preflight response.
login:
handler: controller/usercontroller.login
events:
- http:
path: /login
method: post
cors:
origin: 'http://34.215.214.199:3000'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Access-Control-Allow-Headers
allowCredentials: false
function response(statusCode, message) {
return {
statusCode: statusCode,
headers: {
'Access-Control-Allow-Origin': 'http://34.215.214.199:3000' // Or use wildard * for testing
},
body: JSON.stringify(message)
};
}
can someone help me now why i am getting this error