In lib/tasks/sitemap.rake
:
namespace :sitemap do
task update: :environment do
Rake::Task["sitemap:generate"].execute
key = ENV['AWS_ACCESS_KEY_ID']
secret = ENV['AWS_SECRET_ACCESS_KEY']
bucket = ENV['S3_BUCKET']
s3 = AWS::S3.new(access_key_id: key, secret_access_key: secret)
s3.buckets[bucket].objects['sitemap.xml'].write(data: File.open(Rails.root.join('tmp','sitemaps','sitemap.xml')), acl: :public_read)
end
end
In this code, if I type the strings manually the process runs fine. But as soon as I use ENV
I get the following error:
rake aborted!
AWS::Errors::MissingCredentialsError:
Missing Credentials.
How can I safely use the credentials without setting them in my committable codebase.