The API response
body: ReadableStream
bodyUsed: true
headers: Headers
__proto__: Headers
ok: false
redirected: false
status: 502
statusText: ""
type: "cors"
url: "correct-url"
__proto__: Response
But the Lambda's logs report that it's returning a valid response:
2019-05-16T20:40:54.113Z some-id-snipped { statusCode: 200,
correct headers and body...
Ending Lambda code:
s3.getSignedUrl('putObject', s3Params, (err, data) => {
if (err) {
localLogger.log(err);
callback(null, failure(err, localLogger));
} else {
const response = { url: data, fileName };
callback(null, success(response, localLogger));
}
});
And that success method:
export function success(body, logger = console) {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
},
body: JSON.stringify(body)
};
logger.log(response);
return response;
}
Serverless upload definition:
getUploadUrl:
handler: src/resourceImages.getUploadUrl
events:
- http:
path: resourceImages/getUploadUrl
method: get
cors: true
authorizer:
arn: ${self:provider.environment.USER_POOL_ARN}
Note that the browser is first sending an OPTIONS request, which returns a 200, then sending a GET which returns a 502.