TL;DR
- sitemapathsを使えばsitemap.xmlのURLパスを列挙できるよ
-
sitemapaths
を使ってワンラインでCloudFrontのキャッシュを消せるよ - sitemapbotを使えばsitemap.xmlのURLパス全てにHTTPリクエストできるよ
sitemapathsのシンプルな使い方
https://github.com/hareku/sitemapaths
sitemapaths
は、sitemap.xmlからURLパスを列挙するCLIツールであり、以下のように使える。
$ sitemapaths https://example.com/sitemap.xml
/
/first-post
/second-post
sitemapathsでCloudFrontのキャッシュを削除
sitemapaths
を使って、sitemap.xmlに記載されたURLパス全てをCloudFrontのキャッシュから削除できる。
# CloudFrontのディストリビューションIDを設定
$ CF_DISTRIBUTION_ID=ET5LGZEQ5FWA4
# sitemap.xmlのパスを列挙
$ PATHS=$(sitemapaths https://example.com/sitemap.xml)
# Invalidation(キャッシュの無効化)のリクエストを作成
$ INVALIDATION_REQUEST=$(aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths $PATHS)
# InvalidationリクエストのIDを取得
$ INVALIDATION_ID=$(echo $INVALIDATION_REQUEST | jq -r '.Invalidation.Id')
# Invalidationが完了するまで待つ
$ aws cloudfront wait invalidation-completed --distribution-id $CF_DISTRIBUTION_ID --id INVALIDATION_ID
これは以下のようにワンラインで書ける。
$ CF_DISTRIBUTION_ID=ABCDEFG123
$ aws cloudfront wait invalidation-completed --distribution-id $CF_DISTRIBUTION_ID --id $(aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths $(sitemapaths https://example.com/sitemap.xml) | jq -r '.Invalidation.Id')
sitemapbotでsitemap.xmlのURLを全て巡回する
https://github.com/hareku/sitemapbot
sitemapbot
を使えばsitemap.xmlに記載されているURL全てにアクセスできる。
主にキャッシュを再作成する用途として使う。
$ sitemapbot https://example.com/sitemap.xml
2019/03/03 19:02:41 crawling started: https://example.com/sitemap.xml
213 / 213 [================================================] 100.00% 11s
2019/03/03 19:02:53 crawling finished: https://example.com/sitemap.xml, success:213, error:0