aws-api-gateway

How do you add CloudFront in front of API Gateway

天涯浪子 提交于 2019-11-28 15:44:27
API Gateway (APIG), while it uses CloudFront (CF) it does not support CDN edge caching. When I configured a CF distribution to use APIG as the custom origin, I get a permission denied error. How do I configure CF to fix this? Until API Gateway (APIG) supports edge caching via its internal use of CloudFormation (CF), I have come up with a workaround. You can indeed put CF dist in front of APIG, the trick is to force HTTPS only "Viewer Protocol Policy" AND to NOT forward the HOST header because APIG needs SNI. I setup my CF "Default Cache Behavior Settings" to not forward any headers, and forced

Get object from S3 in AWS Lambda function and send to Api Gateway

前提是你 提交于 2019-11-28 13:46:12
I am trying to get a .jpg file from a bucket and send it back to api gateway. I believe I have the setup correct as I see stuff being logged. It grabs the file from s3 fine, and gm is the graphicsmagick library. Not sure if I am using it right though. In the lambda function I do this (alot of the code comes from the aws example): async.waterfall([ function download(next) { console.log(srcKey); console.log(srcBucket); // Download the image from S3 into a buffer. s3.getObject({ Bucket: srcBucket, Key: srcKey }, next); }, function transform(response, next) { console.log(response); next(null,

Configure CORS response headers on AWS Lambda?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 13:27:30
I'm trying to create a new service using AWS API Gateway, but I found out the browser automatically calls OPTIONS method in order to obtain CORS information. The problem is that AWS API Gateway does not offer a native way to configure CORS headers. Is it possible to create a Lambda Script in order to respond to OPTIONS method? If you're using {proxy+} endpoint, you must handle CORS HTTP requests in the Lambda function. The implementation depends on the framework you're using. For Express, the easiest solution is to simply use Express CORS middleware . If you don't want to handle CORS requests

AWS API Gateway ERR_CONTENT_DECODING_FAILED in browser

半城伤御伤魂 提交于 2019-11-28 12:39:28
问题 In my use case, API Gateway serves as an HTTP proxy, using default settings following official tutorial. It's tested working in test console or via curl. But if I access the link in browser or make an AJAX call, I'll get ERR_CONTENT_DECODING_FAILED . It seems that API Gateway corrupt the content. Related issue. Is there a way to forbid API Gateway changing my content? I set Content Handling to passthrough , but clearly it's changing my content. 回答1: Add a static integration request header

AWS API Gateway Header and Body Mappings in Integration Response

China☆狼群 提交于 2019-11-28 12:07:29
问题 I am trying to properly setup Body Mapping and Header Mapping in the Integration Response for an API Gateway endpoint. In our Lambda we have if (response.statusCode == 200) { context.succeed(output); } else if (response.statusCode == 206) { var paginationObject = { errorType : "PartialContent", errorCode : 206, detailedMessage : "PartialContent Returned", stackTrace : [], data : { output } }; context.fail(JSON.stringify(paginationObject)); } I then handle fetching this in the Integration

How to return gzipped content with AWS API Gateway

泄露秘密 提交于 2019-11-28 09:52:43
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 header is set correctly but the response content is corrupt. Do we have to set some special parameter or

Signature expired: is now earlier than error : InvalidSignatureException

夙愿已清 提交于 2019-11-28 09:02:26
I am trying a small example with AWS API Gateway and IAM authorization. The AWS API Gateway generated the below Endpoint : https://xyz1234.execute-api.us-east-2.amazonaws.com/Users/users with POST action and no parameters. Initially I had turned off the IAM for this POST Method and I verified results using Postman it works. Then I created a new IAM User and attached AmazonAPIGatewayInvokeFullAccess Policy to the user thereby giving permission to invoke any API's. Enabled the IAM for the POST Method. I then went to Postman - and added Authorization with AccessKey, Secret Key, AWS Region as us

Posting form-data and binary data through AWS API Gateway

烂漫一生 提交于 2019-11-28 08:31:47
I'm trying to POST "mutlipart\form-data" to my EC2 instance through AWS API Gateway, but I couldn't find a way to this. There is a way to post data using "application/x-www-form-urlencoded" and Mapping Tamplate to convert it to JSON but still posting a binary data like an image file is missing I guess. Is there anything I'm missing ? EDIT: I have found another way: I convert the image to base64 string then POST it as with content type "application/x-www-form-urlencoded". By this way I'm sending whole image as string. After I got the message I can convert it back to image in PHP. Only down side

Enable CORS for API Gateway in Cloudformation template

泄露秘密 提交于 2019-11-28 08:19:38
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? dannymac 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 RestApiId: Ref: MyApi ResourceId: Ref: MyResourceOnWhichToEnableCORS HttpMethod: OPTIONS

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

天涯浪子 提交于 2019-11-28 06:21:18
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 my ajax call when there was no OPTIONS method so I added one. For now just to make progress I am not