title: How to fix 504 ERROR with route 53, cloudfront distribution and elastic beanstalk
body: <p>I'm not able to get my nodejs api working using elastic beanstalk, cloudfront distribution and route 53.  I need my api to be running behind an SSL, this is why I'm using cloudfront distribution.  I have the following setup.  </p>
  
  <p>When I visit my api <code>https://api.mydomain.com</code> I get a 504 with the error message below.  </p>
  
  <p>The actual url my api is running on (successfully, using nodejs elastic with beanstalk) is <code>http://dummy-env.n1eijsdai.eu-west-1.elasticbeanstalk.com</code>.  I just want to mask that url as <code>api.mydomain.com</code> together with an SSL.</p>
  
  <p>Is there something I've got wrong/ can you suggest anything to try? </p>
  
  <p>Looking through the configuration for cloudfront this looks strange, the picture shows the setting prefixed with S3 but this api is not on an S3 (at least directly) it is hosted by elastic beanstalk.</p>
  
  <p><a href="https://i.stack.imgur.com/sY7vs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sY7vs.png" alt="cloudfront setting that mentions S3 in the value, it&#39;s in beanstalk (not S3)"></a></p>
  
  <p>Thanks,</p>
  
  <p><strong>Error message</strong></p>
  
  <pre><code>504 ERROR
  The request could not be satisfied.
  CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection. 
  If you received this error while trying to use an app or access a website, please contact the provider or website owner for assistance. 
  </code></pre>
  
  <p><strong>Route 53</strong></p>
  
  <ul>
  <li>name = api.mydomain.com</li>
  <li>Type = (A) Alias target = wqsdn31817</li>
  </ul>
  
  <p><strong>CloudFront Distributions</strong></p>
  
  <ul>
  <li><p>domain name = wqsdn31817</p></li>
  <li><p>origin = dummy-env.n1eijsdai.eu-west-1.elasticbeanstalk.com (if I visit this url I see my api running)</p></li>
  <li><p>SSL certificate = api.mydomain.com</p></li>
  <li><p>status = deployed</p></li>
  <li><p>Origin Settings/ Origin Domain Name = <a href="http://dummy-env.n1eijsdai.eu-west-1.elasticbeanstalk.com" rel="nofollow noreferrer">http://dummy-env.n1eijsdai.eu-west-1.elasticbeanstalk.com</a></p></li>
  <li><p>Origin Settings/ Origin Protocol Policy = HTTPS Only</p></li>
  </ul>
  
  <p><strong>Elastic Beanstalk</strong></p>
  
  <ul>
  <li><p>Nodejs api (using express) </p></li>
  <li><p>In beanstalk Environment ID: e-1nasn4, URL: dummy-env.n1eijsdai.eu-west-1.elasticbeanstalk.com</p></li>
  </ul>