11

I have a static web site which makes requests to an API server. I'm hosting this static pages with S3 and I'd like to use CloudFront to redirect the api calls to the api server. Api calls can be distinguished by a path prefix of api:

domain.com/index.html         s3/index.html
domain.com/js/index.js        s3/js/index.html
domain.com/api/request        api_server/api/request
domain.com/api/other/request  api_server/api/other/request

I currently have two origins set up - one S3 origin for my S3 bucket (which is working) and another custom origin for my api server (which is not working).

The custom origin settings are as follows:

Origin Domain Name: api_elb
Origin path: /

and the behavior settings are as follows:

Precedence: 0
Path pattern: /api/*
Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
Forward Headers: all
Forward Query Strings: yes

Here's the full response:

> GET /api/logout HTTP/1.1
> Host: a0000aaaaaaaaa.cloudfront.net
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 502 Bad Gateway
< Content-Type: text/html
< Content-Length: 587
< Connection: keep-alive
< Server: CloudFront
< Date: Mon, 06 Jun 2016 19:37:45 GMT
< X-Cache: Error from cloudfront
< Via: 1.1 86f2bbfea57d6217ce2d279b84ca3743.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: A18vpnPPr0cWn5VuVirvvKc-wocC9OcXjNDHZm-PyvD3ONGcPmqmmg==
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
CloudFront wasn't able to connect to the origin.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: -u68y2nD9tuaxL_2MjSk3udA1r64v-K3xoGitKFYvd9Z48gB8ntnwg==
</PRE>
<ADDRESS>
</ADDRESS>

What is wrong with this configuration? How can I get CloudFront to forward these requests to the API? It is currently returning 502 (Bad gateway) responses for all API requests.

cscan
  • 3,684
  • 9
  • 45
  • 83

1 Answers1

0

It looks like this was sorta answered here:

https://stackoverflow.com/a/23599450/2542922

I added api_server.company.com to Alternate Domain Names.

Community
  • 1
  • 1
cscan
  • 3,684
  • 9
  • 45
  • 83