Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - AWS-SDK configuration file

I'm using AWS-SDK gem in my Rails project, and I want a kind-of initializer file to connect directly to my repo and make changes directly in the Rails console, something like this:

    # At config/initializers/aws.rb

    Aws::S3::Client.new(
      :access_key_id => 'ACCESS_KEY_ID',
      :secret_access_key => 'SECRET_ACCESS_KEY'
    )

I've looked for documentation or tutorials but it's not clear for me. How do I do it? Thank you!

like image 990
mariec Avatar asked Mar 23 '15 11:03

mariec


People also ask

What is AWS SDK for Ruby on rails?

A Ruby on Rails plugin that integrates AWS services with your application using the latest version of AWS SDK For Ruby. If you want to use other services (such as S3), you will still need to add them to your Gemfile: You will have to ensure that you provide credentials for the SDK to use. See the latest AWS SDK for Ruby Docs for details.

What Ruby gems are supported by AWS?

You can see a full list of supported gems in the README on our GitHub page, which also includes a detailed upgrading guide for version 2 users. Other gems relevant to Ruby developers include: aws-sdk-rails: Provides Ruby on Rails integrations for the AWS SDK for Ruby.

How do I set up the AWS SDK?

To use the SDK, you must set either AWS credentials or create an AWS STS access token, and set the AWS Region you want to use. Access keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS. If you don’t have access keys, you can create them by using the Management Console.

What are the file storage options available in Ruby on rails?

Ruby on Rails Active Storage out of the box comes equipped with four different file storage options: 1 a local disk-based service, useful for development and testing, 2 Google Cloud Platform, 3 Amazon AWS S3, 4 Microsoft Azure Storage,


1 Answers

i think you can try like this

put this in aws.rb

AWS.config(
   :access_key_id => ENV['ACCESS_KEY_ID'],
   :secret_access_key => ENV['SECRET_ACCESS_KEY']
)

and when you initialize the object wherever you need, will call the configuration

s3 = AWS::S3.new
like image 56
Developer Avatar answered Oct 12 '22 19:10

Developer