DDG - Develop a Digital Garden

develop a digital garden

aws cliのs3 syncで特定の拡張子ファイルだけをアップロードする方法

Image from Gyazo

こんにちは、shootaceanです。

aws s3 sync というコマンドで特定の拡張子のファイルだけをアップロードする方法をご紹介します。

Web技術を試す場として、
https://web-labs.shootacean.com
というサイトをつくっていて、そのサイトにデプロイする際に利用しているコマンドです。

HTML、CSSJavaScriptファイルだけをアップロードしたい場合は、以下のコマンドになります。

$ aws s3 sync src/ s3://bucket-name/ \
     --exclude "*" \
     --include "*.html" --include "*.css" --include "*.js"

注意点

s3 — AWS CLI 1.20.10 Command Reference
When there are multiple filters, the rule is the filters that appear later in the command take precedence over filters that appear earlier in the command.
複数のフィルターがある場合、コマンドの後半に表示されるフィルターが、コマンドの前半に表示されるフィルターよりも優先されるという規則があります。

とドキュメントに記載されているとおり、
上記コマンドの --exclude--include の指定順序を変えると 全てが exclude されてしまいます。

Reference