By using AWS re:Post, you agree to the Terms of Use

Questions tagged with Security Identity & Compliance

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

request from static webside on s3 to API Gateway to Lambda, blocked by CORS, tried everything

I have a workflow Postman -> APIGateway -> Lambda ->Amazon translate And it works perfect when I send request from postman. From static website (tried local and deployed to s3) I am getting CORS error ``` Access to fetch at 'myapigatawaylink' from origin 'myStaticWebsiteDeployedFromS3' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. ``` I read amazon articles, and i either don´t understand something or something is missing, tried to fix this CORS policy everywhere: 1.Frontend: ``` const response = await fetch("mygatawayapilink/dev/trialrsrc", { // mode: 'no-cors', commented out, It doesn´t give error if i discomment it but i get no response (200 empty) method: "POST", body: JSON.stringify({ text:[0].value }), headers: { "Content-type": "application/json", 'Access-Control-Allow-Origin': "*", } }) .then(res => res.json()) ``` 2.Lambda Itself: ``` exports.handler = async (event) => { const AWS = require("aws-sdk"); AWS.config.update({region: "eu-west-1"}); const translate = new AWS.Translate(); let params = { SourceLanguageCode: 'auto', TargetLanguageCode: 'es', Text: event.text }; const translated = await translate.translateText(params).promise(); return { statusCode:200, headers: { "Access-Control-Allow-Origin": '*', "Access-Control-Allow-Headers" : "Content-Type", "Access-Control-Allow-Methods": "OPTIONS,POST,GET" }, body: translated } }; ``` 3.API Gateway: I have GET POST AND OPTIONS METHODS, all of them I have done Actions ->Enable CORS Is it possible to fix it, or i have to use other service like cloudfront or proxy
asked 2 months ago