# Allow use of AWS EC2 IAM roles with S3 file/image uploads

**URL:** https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197
**Category:** Feature
**Tags:** pr-welcome
**Created:** [2014年七月4日 03:54 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197 "2014-07-04T03:54:09Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![windhamg1](https://avatars.discourse-cdn.com/v4/letter/w/d78d45/32.png) [@windhamg1](https://meta.discourse.org/u/windhamg1)
#### Post date: [2014年七月4日 03:54 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/1 "2014-07-04T03:54:09Z")

</div>

I deployed the official Docker Discourse image on an AWS EC2 instance, assuming I could use the Access Key/Secret Key associated an IAM role to enable Discourse’s S3 upload feature (under Setting-\>Files)…well, I guess you know what that makes me. 😄 For reference:  
[https://meta.discourse.org/t/setting-up-file-and-image-uploads-to-s3/7229/31?u=windhamg1](https://meta.discourse.org/t/setting-up-file-and-image-uploads-to-s3/7229/31)

As the “fog” gem (used by Discourse for S3 support) has the ability to use the keys from an IAM role, I respectfully submit a request to have Discourse use this option (:use\_iam\_profile =\> true) if the “use S3” option is enabled, but the “Access Key ID” and “Secret Key” fields are left blank.

Thank you!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年七月4日 19:36 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/2 "2014-07-04T19:36:43Z")

</div>

Seems reasonable if it is easy, @zogstrip can you check? If it is not easy will have to be post V1.

---

<div class="post-metadata">

### Author: ![windhamg1](https://avatars.discourse-cdn.com/v4/letter/w/d78d45/32.png) [@windhamg1](https://meta.discourse.org/u/windhamg1)
#### Post date: [2014年七月4日 20:01 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/3 "2014-07-04T20:01:10Z")

</div>

Thanks, @codinghorror. I took a stab at it in my local instance; it was pretty easy and seems to work well. The change is in `lib/file_store/s3_store.rb`, and a diff is attached. I can submit a git pull request if desired.

[s3\_store\_diff.txt](https://global.discourse-cdn.com/meta/original/3X/d/c/dc8ecf30f29f54da18d8db2e99015046c689b6dc.txt) (1.5 KB)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年七月4日 20:02 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/4 "2014-07-04T20:02:42Z")

</div>

Yes please a PR would be awesome.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2014年七月5日 20:07 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/5 "2014-07-05T20:07:48Z")

</div>

I went ahead and pushed a branch with that patch on it for you, go click the green button to make a PR: [https://github.com/riking/discourse/compare/discourse:master...riking:patch-gary?expand=1](https://github.com/riking/discourse/compare/discourse:master...riking:patch-gary?expand=1)

* * *

P.S. next time you do that, try this:

```plaintext
git checkout -b feature-branch master
git add....
git commit
git format-patch HEAD^

```

This will create a `0001-Commit-message.patch` file, which someone else can use `git am` on to apply the commit, keeping the author and timestamp. (These git tools were originally designed for emailing patches.)

---

<div class="post-metadata">

### Author: ![windhamg1](https://avatars.discourse-cdn.com/v4/letter/w/d78d45/32.png) [@windhamg1](https://meta.discourse.org/u/windhamg1)
#### Post date: [2014年七月5日 20:42 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/6 "2014-07-05T20:42:44Z")

</div>

Thanks, @riking. However, since my last post I went ahead and submitted a PR myself, using the prescribed methodology at [discourse/CONTRIBUTING.md at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/CONTRIBUTING.md). I cleaned it up a bit (adding an option instead of relying on the other fields to be blanks, and also making it work for S3 backups).

The PR is [support for EC2 IAM roles with Amazon S3 file store/backup by windhamg · Pull Request #2511 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/2511).

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2016年八月26日 04:12 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/7 "2016-08-26T04:12:24Z")

</div>

Looks like this feature is not longer valid after the `fog`gem is removed?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2016年八月26日 05:02 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/8 "2016-08-26T05:02:09Z")

</div>

The fog gem was very bloated and @sam removed it a while back.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年二月20日 18:55 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/9 "2017-02-20T18:55:08Z")

</div>

Putting a #pr-welcome on this in case anyone wants to try bringing this feature back provided they don’t also bring back a swarm of bloated dependencies.

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [2025年十二月4日 11:31 UTC](https://meta.discourse.org/t/allow-use-of-aws-ec2-iam-roles-with-s3-file-image-uploads/17197/10 "2025-12-04T11:31:04Z")

</div>


