2

I am using sitemap_generator gem with rails 6 on heroku. I am told the easiest way is to use an s3 on amazon and bridge with aws_fog.

The implementation is well documented on the gem side... but I am struggling to make sure the amazon config is correct.

I search a lot and couldn't find anything so I was hoping someone could help

I configure an s3 instance lets name it example and I add it to region US East(Ohio). This is all pretty simple.

The Properties tab... what should and shouldn't be selected? i select nothing.

The Permissions tab. I make public, although this feels wrong... the bucket is for a sitemap, so it should be public right?

I set up my region as per the doumentation

SitemapGenerator::Sitemap.default_host = "https://www.example.com"
SitemapGenerator::Sitemap.public_path = 'tmp/'
SitemapGenerator::Sitemap.sitemaps_host = "https://example.s3.amazonaws.com/"
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(fog_provider: 'AWS',
  aws_access_key_id: Rails.application.credentials.aws[:access_key_id],
  aws_secret_access_key: Rails.application.credentials.aws[:secret_access_key],
  fog_region: 'us-east-2')

when i hit rake sitemap:refresh:no_ping on my local host I get :status_line => "HTTP/1.1 301 Moved Permanently\r\n"

I think maybe i need to add the sitemaps folder to the s3 instance, so i do but i still get the :status_line => "HTTP/1.1 301 Moved Permanently\r\n".

Any tips would be great...

Joe Bloggos
  • 889
  • 7
  • 24

1 Answers1

1

I am also using sitemap-generator gem on my rails application (heroku hosted and rails 6). I have the following code inside config/sitemap.rb, before SitemapGenerator::Sitemap.create. I have configured it with aws-sdk-s3 gem and it goes like this:

require 'aws-sdk-s3'
SitemapGenerator::Sitemap.default_host = "https://www.example.com"
SitemapGenerator::Sitemap.sitemaps_host = 'https://example.s3.eu-west-2.amazonaws.com/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AwsSdkAdapter.new(Rails.application.credentials.dig(:amazon, :s3, :bucket),
                                                                        aws_access_key_id: Rails.application.credentials.dig(:amazon, :s3, :access_key_id),
                                                                        aws_secret_access_key: Rails.application.credentials.dig(:amazon, :s3, :secret_access_key),
                                                                        aws_region: Rails.application.credentials.dig(:amazon, :s3, :region)
)
JohnDel
  • 2,092
  • 8
  • 35
  • 64
  • thanks for your response... but that doesnt help with the aws side of the implementation... did you add a folder 'sitemaps' – Joe Bloggos Jun 10 '20 at 09:23
  • I just created a bucket on AWS which allows to be publicly accessible and I can view it directly. So when I try the command to generate it, I can "see" the uploaded sitemap file. – JohnDel Jun 10 '20 at 13:04
  • 1
    awesome mate thats really helpful, might move to the sdk gem. thanks – Joe Bloggos Jun 10 '20 at 21:12
  • I still cannot get this to work... i just get access denied – Joe Bloggos Jun 14 '20 at 10:26
  • 1
    @JemBuilt This has to do with the public permissions. Check how to do it public here https://havecamerawilltravel.com/photographer/how-allow-public-access-amazon-bucket/ and also be sure that you are trying on the correct region. – JohnDel Jun 14 '20 at 17:45