https://rubygems.org/gems/aws_s3_website_sync
This is a tool to sync a folder from your local developer enviroment to your S3 Bucket and then invalidate the CloudFront cache.
Create a Gemfile
that installs the gem:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rake'
gem 'aws_s3_website_sync', tag: '1.0.1'
gem 'dotenv', groups: [:development, :test]
The proceed to install the required gems:
bundle install
Create a Rakefile
with the following:
require 'aws_s3_website_sync'
require 'dotenv'
task :sync do
puts "sync =="
AwsS3WebsiteSync::Runner.run(
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
aws_default_region: ENV["AWS_DEFAULT_REGION"],
s3_bucket: ENV["S3_BUCKET"],
distribution_id: ENV["CLOUDFRONT_DISTRUBTION_ID"],
build_dir: ENV["BUILD_DIR"],
output_changset_path: ENV["OUTPUT_CHANGESET_PATH"],
auto_approve: ENV["AUTO_APPROVE"],
silent: "ignore,no_change",
ignore_files: [
'stylesheets/index',
'android-chrome-192x192.png',
'android-chrome-256x256.png',
'apple-touch-icon-precomposed.png',
'apple-touch-icon.png',
'site.webmanifest',
'error.html',
'favicon-16x16.png',
'favicon-32x32.png',
'favicon.ico',
'robots.txt',
'safari-pinned-tab.svg'
]
)
end
Then to proceed to sync you just type:
bundle exec rake sync