Heroku - Missing required arguments: aws_access_key_id, aws_secret_access_key, after the Hartl tutorial

Running heroku run rake db:migrate , I get this error: Missing required arguments: aws_access_key_id, aws_secret_access_key .

I made the correction recommended in SO question 25596504, in particular by changing the carrier_wave.rb file to carrierwave.rb with no luck. I follow the Hartl tutorial, p. 688, which indicates that they are added as $heroku config:set S3_ACCESS_KEY=<access key> . I replaced the "" with quotation marks and unquoted versions of the actual key. The keys show when I start the heroku configuration, for example S3_ACCESS_KEY:

The application worked before I started working on this section (11.4) of the image uploading tutorial. Incidentally, I know about Figaro's jewels; however, I would like to try to follow a training approach. What am I missing? Any thoughts would be appreciated. Thanks!

+6
source share
5 answers

Go to Heroku, in your application, go to settings, click Reveal Config Vars.

Click "Edit" on the right and enter your secrets:

 S3_BUCKET: name of your bucket goes here S3_ACCESS_KEY: xxxxx S3_SECRET_KEY: xxxx 

In config / initializers / carrierwave.rb or wherever you enter your secrets, should be:

 CarrierWave.configure do |config| config.root = Rails.root.join('tmp') # adding these... config.cache_dir = 'carrierwave' # ...two lines config.fog_credentials = { :provider => 'AWS', # required :s3_access_key_id => ENV['S3_ACCESS_KEY'], # required :s3_secret_access_key => ENV['S3_SECRET_KEY'], # required :region => 'eu-west-1', # optional, defaults to 'us-east-1' :host => 's3.example.com', # optional, defaults to nil :endpoint => 'https://s3.example.com:8080' # optional, defaults to nil } config.fog_directory = ENV['S3_Bucket'] # required config.fog_public = false # optional, defaults to true config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} end 
+12
source

Here is a tutorial that I did after a lot of work using AWS to work with Heroku, as described in chapter 11 of Michael Hartle's Ruby on Rails tutorial. Hope this helps:

Getting Rails Tutorial An example application for working between Heroku and AWS was a huge pain in the ass. But I did it. If you find this tutorial, it means that you are probably facing an error that you cannot go through. It's great. I had a few of them.

The first thing you need to do is return to the code provided by Hartl. Make sure you enter it (or copy / paste) exactly as shown. Of all the code in this section, there is only one small addition that you may need. The environment variable is "region". This is necessary if you are creating a bucket that is not in the default area in the USA. More on this later. Here is the code for /config/initializers/carrier_wave.rb :

 if Rails.env.production? CarrierWave.configure do |config| config.fog_credentials = { # Configuration for Amazon S3 :provider => 'AWS', :aws_access_key_id => ENV['S3_ACCESS_KEY'], :aws_secret_access_key => ENV['S3_SECRET_KEY'], :region => ENV['S3_REGION'] } config.fog_directory = ENV['S3_BUCKET'] end end 

This line :region => ENV['S3_REGION'] is a problem for many people. As you continue this lesson, you will know what it is for.

You should use this block of code exactly as shown. DO NOT put your actual keys. We will ship them to Heroku separately.

Now go to your AWS account and security.

  • First of all, create your AWS account. . For the most part, this is similar to registering with any website. Make a good long password and keep it somewhere safe, for example, an encrypted password manager. When you make your account, you will be provided with your first set of AWS keys. You will not use those in this tutorial, but you may need them at some point in the future to keep them safe.
  • Go to section S3 and create a bucket. It must have a unique name, so I usually just put the date at the end, and it does. For example, you can name it "my-sample-app-bucket-20160126". Once you have created your bucket, click on the name, then click on "Properties". It is important that you know what the Region is in your bucket. Find him, and remember this. You will use it later.
  • Your main account probably has all rights to everything, so do not use this to transfer random data between two web services. It can cost you a lot of money if it comes out. Instead, we will make a limited user. Create a new user in the IAM section. I called it “fog” because it is a cloud service software that handles sending and receiving. When you create it, you will have the opportunity to display and / or download keys associated with the new user. It is important that you keep this in a safe and secure place. It is NOT included in your code because it will probably end up in a repository where other people can see it. Also, do not give the new user a password, as he will not log into the AWS control panel.
  • Create a new group. I called my "s3railsbucket". This is where permissions will be assigned. Add “fog” to this group.
  • Go to the "Policies" section. Click Create New Policy, then select Create Your Own Policy. Give it a name that begins with "Allow" so that it appears next to the top of the list of policies. This is a huge list. Here is what I did:

Policy Name: AllowFullAccessToMySampleAppBucket20160126
Description: Allows remote write / delete access to the S3 bucket named my-sample-application Bucket-20160126.
Political document:

 { "Version": "2012-10-17", "Statement": [ { "Action": "s3:*", "Effect": "Allow", "Resource": [ "arn:aws:s3:::my-sample-app-bucket-20160126", "arn:aws:s3:::my-sample-app-bucket-20160126/*" ] } ] } 
  1. Go back to the Group section, select the group you created, then add your new policy for the group.

This is for AWS configuration. I did not need to pursue a policy that allowed “fog” to list the contents of the bucket, although most of the tutorials I tried said it was necessary. I think this is only necessary when you want a user who can log in through the control panel.

Now for Heroku configuration. This stuff is entered on your command line, just like "heroku run rake db: migrate" and the like. This is where you enter the actual access key and the secret key that you received from the “fog” user that you created earlier.

 $ heroku config:set S3_ACCESS_KEY=THERANDOMKEYYOUGOT $ heroku config:set S3_SECRET_KEY=an0tHeRstRing0frAnDomjUnK $ heroku config:set S3_REGION=us-west-2 $ heroku config:set S3_BUCKET=my-sample-app-bucket-20160126 

Look again at the last one. Remember when you looked at the Properties of your S3 bucket? Here you enter the code associated with your area. If your bucket is not in Oregon, you will need to change us-west-2 to your actual region code. This link worked when this tutorial was written:

http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

If this does not work, Google "AWS S3 Region Code."

Having done all this and double checking the errors in the code, I got Heroku to work with AWS for storing images!

+10
source

I think this error occurred because the var name does not match.

In carrierwave.rb you must replace: s3_access_key_id and: s3_secret_access_key with the prefix "aws".

     if Rails.env.production?
         CarrierWave.configure do | config |
         config.root = Rails.root.join ('tmp')
         config.cache_dir = 'carrierwave'

         config.fog_credentials = {
           # Configuration for Amazon S3
           : provider => 'AWS', # change var name
           : aws_access_key_id => ENV ['S3_ACCESS_KEY'], # change var name
           : aws_secret_access_key => ENV ['S3_SECRETE_KEY']
         }
         config.fog_directory = ENV ['S3_BUCKET']
       end
     end

And it can be deployed.

+3
source

For some reason running rake assets:precompile RAILS_ENV=development fixed this for me.
[and env vars no need to call S3_ACCESS_KEY etc., I used aws.access_key_id ]

+2
source

Running rake assets:precompile without RAILS_ENV was the only way I could precompile it.

0
source

Source: https://habr.com/ru/post/981007/


All Articles