# S3 and Cloudfront - Setup Not Working

**URL:** https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332
**Category:** Self-hosting
**Tags:** s3
**Created:** [November 3, 2023, 1:48pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332 "2023-11-03T13:48:33Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 1:48pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/1 "2023-11-03T13:48:33Z")

</div>

Hello all!

I followed [this guide](https://meta.discourse.org/t/set-up-file-and-image-uploads-to-s3/7229) to setup s3.

The only option I couldn’t find is " make sure the “ **Programmatic access** ” checkbox is checked"

I couldn’t find any option like that.

But S3 is not working.

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/7/9/179b64fefff6900a0a8d22d79ead90295e90a3ed.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/a/a/7aa4da8cb86436e09584fd656d4f1279021d644a.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/2/5/52570075492a8aabb2252e68f3c2a1b2fb3c382a.png)

Notes: CDN is via CloudFront (s3 is the source of CloudFront)

Thanks

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 3, 2023, 2:19pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/2 "2023-11-03T14:19:03Z")

</div>

The rake task you’re running insists the specified values are in environment variables, it will not use the ones in the site settings.

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 2:21pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/3 "2023-11-03T14:21:51Z")

</div>

Thanks for the response.

I used rake, thinking that image urls would be replaced with CDN link.

But the S3 setting itself is not working.

Did I miss anything in the S3 configuration?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 3, 2023, 2:23pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/4 "2023-11-03T14:23:15Z")

</div>

Yes, you need to set the environment variables to run the rake task to migrate to S3.

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 2:29pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/5 "2023-11-03T14:29:20Z")

</div>

I’m not getting. Hope you reviewed my discourse settings.

Any extra steps needed apart from this guide? [Set up file and image uploads to S3](https://meta.discourse.org/t/set-up-file-and-image-uploads-to-s3/7229)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [November 3, 2023, 2:30pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/6 "2023-11-03T14:30:17Z")

</div>

> [@Set up file and image uploads to S3](https://meta.discourse.org/t/set-up-file-and-image-uploads-to-s3/7229/1):
>
> ## Discourse configuration
> 
> Now that you’ve properly set up S3, the final step is to configure your Discourse forum. These instructions should work, but **the preferred method is to use environment variables and a CDN** as described in [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916).

~~I believe you can get an overview of what environment variables you need here:  
 [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916)~~

EDIT: In the context of a rake command, see the answer below 👇

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 3, 2023, 2:34pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/7 "2023-11-03T14:34:18Z")

</div>

> [@Arkshine](#):
>
> an overview of what environment variables you need here

or from the error:

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/6/c/76c58360b467b8d0d14bcad99cb84c1c89f47dbe.png)

They must be set in the environment, not in site settings.

You can provide them at the time the rake task is run by doing e.g.:

```plaintext
DISCOURSE_S3_BUCKET=foo DISCOURSE_S3_REGION=us-east-1 DISCOURSE_S3_USE_IAM_PROFILE=true rake uploads:migrate_to_s3

```

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 2:35pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/8 "2023-11-03T14:35:51Z")

</div>

oh okay!

So, I’ll add this to app.yml

Example:

```plaintext
DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: us-west-1
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: falcoland-files
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3

```

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [November 3, 2023, 2:37pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/9 "2023-11-03T14:37:39Z")

</div>

Please read Michael’s answer instead!

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 2:42pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/10 "2023-11-03T14:42:06Z")

</div>

Since my installation is fresh!

My only concern is new images. Rake, I did because the article suggested.

I thought just adding S3 settings via discource admin was enough to serve new images from S3!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 3, 2023, 3:05pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/11 "2023-11-03T15:05:13Z")

</div>

See [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916)

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 3:16pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/12 "2023-11-03T15:16:06Z")

</div>

Yeah, since my setup is S3 and Cloudfront, I added the S3 code as following.

 ![image](https://global.discourse-cdn.com/meta/original/4X/e/b/4/eb4b2e2679fe753359a278ffd161f0b6d5494ad8.png)

Now rebuilding. I hope S3 will work!

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 3:31pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/13 "2023-11-03T15:31:59Z")

</div>

Didn’t work! I think something is missing related to S3 permissions!

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/a/d/4ad663b59de863e6394a1e5113abe4f03c4a6548.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/f/a/afae4f717ae62fb2657dfa2f61d5c33d81904a53.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/f/a/9fad6d89503fb53148e295fd1f0db99ad4f1865c.png)

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 3, 2023, 4:36pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/14 "2023-11-03T16:36:52Z")

</div>

Any suggestions?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 3, 2023, 5:16pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/15 "2023-11-03T17:16:19Z")

</div>

There’s 3 parts here:

- can Discourse read/write/etc. on the bucket?
- can anonymous users read from the bucket?
- can the CDN read from the bucket?

Looks like it’s the second part not working?

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 4, 2023, 9:34am UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/17 "2023-11-04T09:34:02Z")

</div>

Please review my setup and kindly let me know if I missed anything: S3 and CloudFront CDN

Based on [this Guide](https://meta.discourse.org/t/set-up-file-and-image-uploads-to-s3/7229)

**Created two buckets:**

One for CDN (Enabled ACL also)  
One for Backups  
Created policy by adding two buckets, attached with IAM user, and generated the access keys.

**Created two CloudFront distributions:**

1. [cdn.mysite.com](http://cdn.mysite.com) (origin is the cdn bucket) by configuring CNAME.

2. [assets.mysite.com](http://assets.mysite.com) (origin is [mysite.com](http://mysite.com)) (Community is on the main domain, not sub-domain) by configuring CNAME.

Based on [this guide](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916):

Added the AWS S3 code, and configuration to app.yml as follows:

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/9/8/c981a2caab90604ec184553e3e7244d0194b232b.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/0/3/303cb7a1bd580a2a35cc77f6ad6259addfe3c8ae.png)

Thank You.

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 4, 2023, 6:00pm UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/19 "2023-11-04T18:00:59Z")

</div>

Thanks a lot to @pfaffman

Who gave me a clue about using **www** in the **host address**. My forum was using a non-www version!

I changed to www version, and rebuilt it!

Everything now works fine including cdn and assets!

Thank You.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 5, 2023, 12:03am UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/20 "2023-11-05T00:03:51Z")

</div>

I can’t quite see how that fixed it, but glad you got it sorted!

---

<div class="post-metadata">

### Author: ![akhil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/akhil/32/340051_2.png) [@akhil](https://meta.discourse.org/u/akhil)
#### Post date: [November 5, 2023, 4:53am UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/21 "2023-11-05T04:53:16Z")

</div>

As I explained [here](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/17), after I did this, the site was offline. So, I was unable to see the outcome of that. But when I tried the same setup on a test sub-domain, all was working fine. Therefore, I suspect there is something wrong with the SSL.

Based on your clue of www, I changed the host address, and the issue was fixed immediately.

I also suspect that the site may have gone offline because of [Cloudflare’s recent service outage](https://www.cloudflarestatus.com/incidents/hm7491k53ppg).

Anyway, it got fixed.

Thank you!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 5, 2023, 4:53am UTC](https://meta.discourse.org/t/s3-and-cloudfront-setup-not-working/284332/22 "2023-12-05T04:53:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
