title: Aws::S3::Errors::InvalidAccessKeyId (The AWS Access Key Id you provided does not exist in our records.)
body: <p>On a Rails 6 app I use aws-sdk-s3 with ActiveStorage and I want to upload images.</p>
  <p>Steps:</p>
  <ul>
  <li>I created a IAM User on AWS with S3FullAccess</li>
  <li>I configured storage.yml (see below)</li>
  <li>I created an config/aws.rb file with the following</li>
  </ul>
  <p>Here is my configuration</p>
  <pre><code># Gemfile
  gem 'aws-sdk-s3', '~&gt; 1', require: false
  
  # storage.yml
  amazon:
    service: S3
    access_key_id: ENV['AWS_ACCESS_KEY_ID']
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
    region: eu-west-1
    bucket: mybucketname
  
  # config/aws.rb
  require 'aws-sdk-core'
  
  Aws.config.update(
    region:      'eu-west-1',
    credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
  )
  </code></pre>
  <p>I have a simple model with:</p>
  <pre><code>has_one_attached :picture, dependent: :destroy
  </code></pre>
  <p>On development everything works fine, but not on production.</p>
  <p>For eg..</p>
  <pre><code>&gt; model_object.picture.attach(io: File.open(Rails.root.join('testfile.png')), filename: 'testfile.png')
  &gt; Aws::S3::Errors::InvalidAccessKeyId (The AWS Access Key Id you provided does not exist in our records.)
  </code></pre>
  <p>Environment variables are correctly visible from console, so I don't think it's a configuration issue...</p>
  <pre><code>ENV['AWS_ACCESS_KEY_ID']
  ENV['AWS_SECRET_ACCESS_KEY']
  </code></pre>
  <p>What could I do?</p>
  <hr />
  <p>To make sure I had the correct AWS access policies I uploaded an image using APIs directly from console like this:</p>
  <pre><code>require 'aws-sdk-core'
  
  Aws.config.update(
    region: 'eu-west-1',
    credentials: Aws::Credentials.new(myakid, mysecret_key)
  )
  
  s3 = Aws::S3::Client.new
  resp = s3.list_buckets
  resp.buckets.map(&amp;:name) # He gave me the list of my buckets
  
  resp = s3.list_objects(bucket: 'MYBUCKET', max_keys: 2)
  resp.contents.each do |object|
    puts &quot;#{object.key} =&gt; #{object.etag}&quot;
  end
  
  # upload
  resource = Aws::S3::Resource.new
  object = resource.bucket(MYBUCKET).object(&quot;completed.png&quot;)
  object.upload_file(Rails.root.join('app/assets/images/completed.png'))
  </code></pre>
  <p>And the file was correctly uploaded.</p>
  <p>So, I cannot understand why ActiveStorage doesn't work...</p>