KeyError от настройки учетных данных для Amazon S3 - PullRequest
1 голос
/ 14 июля 2020

Я пытался настроить соединение Rails с s3 и следую этому руководству https://medium.com/@andrea.wayte / using-amazon-s3-to-store-images-for-react-on-rails-b1414ba2c0b2 но я получил эту ошибку на своем терминале.

admins-MBP:direct-s3-example admin$ rails db:migrate
rails aborted!
KeyError: key not found: "petition-form"
/Users/admin/direct-s3-example/config/environments/development.rb:67:in `fetch'
/Users/admin/direct-s3-example/config/environments/development.rb:67:in `block in <main>'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/railtie.rb:216:in `instance_eval'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/railtie.rb:216:in `configure'
/Users/admin/direct-s3-example/config/environments/development.rb:1:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/zeitwerk-2.3.1/lib/zeitwerk/kernel.rb:34:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:613:in `block (2 levels) in <class:Engine>'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:612:in `each'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:612:in `block in <class:Engine>'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `each'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
/Users/admin/direct-s3-example/config/environment.rb:5:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/zeitwerk-2.3.1/lib/zeitwerk/kernel.rb:34:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:339:in `require_environment!'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/command.rb:48:in `invoke'
/Library/Ruby/Gems/2.6.0/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
/Users/admin/direct-s3-example/bin/rails:9:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/admin/direct-s3-example/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

Это мой файл, в котором я пытаюсь настроить свои учетные данные, я добавил их все в свой .bashr c файл

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports.
  config.consider_all_requests_local = true

  # Enable/disable caching. By default caching is disabled.
  # Run rails dev:cache to toggle caching.
  if Rails.root.join('tmp', 'caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.action_controller.enable_fragment_cache_logging = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => "public, max-age=#{2.days.to_i}"
    }
  else
    config.action_controller.perform_caching = false

    config.cache_store = :null_store
  end

  # Store uploaded files on the local file system (see config/storage.yml for options).
  config.active_storage.service = :local

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.perform_caching = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Highlight code that triggered database queries in logs.
  config.active_record.verbose_query_logs = true

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Suppress logger output for asset requests.
  config.assets.quiet = true

  # Raises error for missing translations.
  # config.action_view.raise_on_missing_translations = true

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
  Paperclip.options[:command_path] = "/usr/bin/"
  config.paperclip_defaults = {
    storage: :s3,
    s3_host_name: 's3-us-east-2.amazonaws.com',
    s3_credentials: {
       bucket: ENV.fetch('petition-form'),
       access_key_id: ENV.fetch('[REDACTED]'),
       secret_access_key: ENV.fetch('[REDACTED]'),
       s3_region: ENV.fetch('us-east-2'),
    }
}

end

1 Ответ

1 голос
/ 14 июля 2020

Лучше добавить вот так в development.rb

 config.paperclip_defaults = {
  storage: :s3,
  s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...