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

Questions tagged with Amazon API Gateway

Sort by most recent

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

Lambda in private subnet cannot reach DynamoDB

Hi! We are working on a POC related to hardening network security & resources. We used as model the reference of Building Basic Web Application, link: [https://aws.amazon.com/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/](), where a Lambda invoke from API Gateway post data in to a DynamoDB table. Here are the changes made: * The lambda was set to be inside the VPC and within a private subnet. * A NAT Gateway was added for internet access and linked to the route table of the private subnet. * A VPC Gateway endpoint was also added so the communication between the lambda and DynamoDB can be done thru the endpoint instead over routes. This endpoint has also been added to the route table of the private subnet. If we take out the lambda out of the VPC and configure it as "NONE" in the VPC settings, it works fine, just as it suppose to work from the reference previously shared. We created another lambda, using the "Hello World" template, we added it to the same VPC and it works fine. The problem here is wih the Lambda that post data in to a DynamoDB table. Error message from Lambda: Task timed out. It seems that the issue is between the communication from Lambda to DynamoDB, since the other Lambda works fine inside the VPC. Any advice? Kinldy/please help! Thank you! ![Reference Architecture](https://repost.aws/media/postImages/original/IMig5QmJK6Re-eqxLh5LLYvQ)
1
answers
0
votes
81
views
asked 2 months ago

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: e.target[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
3
answers
0
votes
78
views
asked 2 months ago