Skip to content

Commit

Permalink
add aws region as env variable. add readme on s3 for dummies (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmersonEmerson authored Aug 24, 2023
1 parent 5b223ee commit 0c5601c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ SENDGRID_USERNAME=
SENDGRID_PASSWORD=
EMAIL_FROM_ADDRESS=

S3_BUCKET=
AWS_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
S3_BUCKET=

INTERCOM_APP_ID=
INTERCOM_APP_SECRET=
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,60 @@ bin/rake

*Note: As uploads use S3, you'll need to add details to the .env file for them to work. Alternatively, [replace S3 with ActiveStorage](https://github.com/forsbergplustwo/partner-metrics/issues/20).*

## S3 - Minimum setup guide

### 1. Sign up for or login to [Amazon AWS](https://aws.amazon.com)
### 2. Create an S3 Bucket:
* In the AWS console, search for S3 and click the offering in the drop down menu.
* In the S3 Management Console, click the "Create Bucket" button.
* In the bucket creation wizard - name it something cool. (eg... "ice-bucket")
* Take note of the region your bucket is in. In my case I used the default presented ("us-east-2").
* Leave all other default settings alone. Click create to finalize the creation of the bucket.

### 2b. Allow CORS
* While looking at the individual bucket overview of the bucket you just created, click into the "Permissions" tab. Scroll down to "Cross-origin resource sharing (CORS)" and paste in the following:
```
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD",
"POST",
"PUT"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
```
Note: *Make sure to update the `AllowedOrigins` details above with your production app details, if your app is being made public.*

### 3. Create a user in IAM:
* Go back to the AWS console. This time search for IAM (Identity access management) and click it in the dropdown.
* Click "Add User"
* Name your user `Partner Metrics S3 User` (or something else if you'd like) and give it only programmatic access.
* On the next screen you'll set the permissions. Click the tab for "Attach Existing Policies Directly". Next, search for S3 and click the checkbox next to AmazonS3FullAccess.
* Leave all the other settings alone and create the new user.
* Take note of the access key ID and secret access key.


### 4. Add credentials to .env
* Go to your .env file and adjust the 4 AWS relevant definitions
```
S3_BUCKET=[aws bucket handle from step 2]
AWS_REGION=[aws bucket region from step 2]
AWS_ACCESS_KEY_ID=[access key id from step 3]
AWS_SECRET_ACCESS_KEY=[secret access key from step 3]
```
* Restart your server if running just to be safe.


## Contributing
We'd love for you to contribute join us in making it better!

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/aws.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Aws.config.update({
region: "us-east-1",
region: ENV["AWS_REGION"],
credentials: Aws::Credentials.new(ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"])
})

Expand Down

0 comments on commit 0c5601c

Please sign in to comment.