aws-api-gateway

How to return gzipped content with AWS API Gateway

試著忘記壹切 提交于 2019-11-26 23:14:33
问题 We have developed an application that offers serveral rest services and supports Accept-Encoding header to return compressed content through Content-Encoding:gzip header value. This application is deployed on ec2 instances on aws and when we send a request with Accept-Encoding value set the response is correctly built. We want to expose this api by using api gateway but it is just working for not compressing requests. When we send a request asking for gzipped content the Content-Encoding

Setting http response header from AWS lambda

[亡魂溺海] 提交于 2019-11-26 23:13:22
问题 My API Gateway/Lamdba setup returns an http response header: Lamdba uses callback function to return the value as part of a json and the Integration Response maps it into a header (using integration.response.body) With this solution, the values are sent back both in the body and the header. How can I map headers from the Lambda response without duplicating the values in the response body? 回答1: If you have Lambda proxy integration enabled, you can set the response headers as part of Lambda

AWS lambda api gateway error “Malformed Lambda proxy response”

廉价感情. 提交于 2019-11-26 22:19:28
I am trying to set up a hello world example with AWS lambda and serving it through api gateway. I clicked the "Create a Lambda Function", which set up the api gatway and selected the Blank Function option. I added the lambda function found on AWS gateway getting started guide : exports.handler = function(event, context, callback) { callback(null, {"Hello":"World"}); // SUCCESS with message }; The issue is that when I make a GET request to it, it's returning back a 502 response { "message": "Internal server error" } . And the logs say "Execution failed due to configuration error: Malformed

Enable CORS for API Gateway in Cloudformation template

会有一股神秘感。 提交于 2019-11-26 20:23:40
问题 I'm creating AWS Cloudformation template for my environment and I can't find a way to enable CORS for API Gateway method. I can configure it using AWS console (here is the official doc), but how can I do it in the Cloudformation template? 回答1: After some trial and error, I found that the following CloudFormation template snippet will produce an equivalent OPTIONS method when compared to the CORS console wizard: OptionsMethod: Type: AWS::ApiGateway::Method Properties: AuthorizationType: NONE

AWS API Gateway - CORS + POST not working

泪湿孤枕 提交于 2019-11-26 20:12:26
问题 CORS is really driving me crazy and I'm really out of ideas as of what to try to make it work. I have created a simple APIG Api with 1 resource called 'abc' and added 2 methods GET and POST both with Authorization set to NONE and API Key Required set to false , everything deployed to a stage called 'dev'. Of course I enabled CORS on both methods and I see the 3 headers Access-Control-Allow-Origin , Access-Control-Allow-Headers and Access-Control-Allow-Methods added to the OPTIONS method and

AWS API Gateway No 'Access-Control-Allow-Origin' header is present

大城市里の小女人 提交于 2019-11-26 20:00:22
问题 I'm stuck on an issue with API gateway and I've gone through all the other SO answers on this, AWS forums and have been through their docs but still no joy. I am trying to setup an API using AWS API gateway which calls a Lambda function which reads/writes to a table in DynamoDB. The Lambda function to DynamoDB is working. I have created an API in AWS, and created a GET and OPTIONS methods for it. I read AWS does not enforce the OPTIONS for only GET/POST but i was getting a preflight error in

getting message: forbidden reply from AWS API gateway

倾然丶 夕夏残阳落幕 提交于 2019-11-26 16:21:00
问题 [solved] New to AWS (and StackOverflow). I am trying to create a lambda service on AWS and have it accessed from outside via the API gateway with no authentication or restriction required. To make things easy I set the gateway for now to be a Mock. On the Get method of the API, the Authorization is set to None and the API Key is not required . When I try this, I get {"message":"Forbidden"} (same message if i connect it to the actual lambda service). Any advice on how to make it accessible?

Is there a way to change the http status codes returned by Amazon API Gateway?

孤者浪人 提交于 2019-11-26 11:40:54
For instance if I want to return a specific 400 error for invalid parameters or perhaps a 201 when the lambda function call resulted in a create. I'd like to have different http status codes but it looks like api gateway always returns a 200 status code even if the lambda function is returning an error. Update per 20-9-2016 Amazon finally made this easy using the Lambda Proxy integration . This allows your Lambda function to return proper HTTP codes and headers: let response = { statusCode: '400', body: JSON.stringify({ error: 'you messed up!' }), headers: { 'Content-Type': 'application/json',

Can an AWS Lambda function call another

泪湿孤枕 提交于 2019-11-26 11:02:01
I have 2 Lambda functions - one that produces a quote and one that turns a quote into an order. I'd like the Order lambda function to call the Quote function to regenerate the quote, rather than just receive it from an untrusted client. I've looked everywhere I can think of - but can't see how I'd go about chaining or calling the functions...surely this exists! I found a way using the aws-sdk . var aws = require('aws-sdk'); var lambda = new aws.Lambda({ region: 'us-west-2' //change to your region }); lambda.invoke({ FunctionName: 'name_of_your_lambda_function', Payload: JSON.stringify(event,

How to access HTTP headers for request to AWS API Gateway using Lambda?

感情迁移 提交于 2019-11-26 10:25:00
问题 I see in the API Gateway FAQ that it is possible to access the request headers sent to the API Gateway... If you already utilize OAuth tokens or any other authorization mechanism, you can easily setup API Gateway not to require signed API calls and simply forward the token headers to your backend for verification. However, I can find no example of how to do so in the documentation and it is unclear how to access this data using Lambda. I am able to set up an open API and gain access to the