通过 aws 命令将内容编码设置为特定文件

BrB*_*rBr 4 amazon-s3 aws-cli

我通过 aws 命令部署静态应用程序。我通过以下命令将所有文件从我的文件夹复制到 s3 存储桶:

aws s3 sync C:\app s3://myBucket
Run Code Online (Sandbox Code Playgroud)

我想将内容编码设置为 gzip 仅用于 js、jpg 和 html 文件。通过此命令,我成功地为所有文件夹执行了此操作:--content-encoding gzip 如何仅针对特定文件类型执行此操作?

com*_*day 7

这是旧的,但我需要找到一种方法来做到这一点:我没有使用 Cloudfront,而且我们使用的代理不处理 gzip ......所以:

  1. 排除所有文件
  2. 根据需要包括单个文件类型
  3. 设置适当的编码/选项

下面我还添加了访问控制和缓存控制,并删除了本地目录中不存在的 s3 中的任何文件

我已将 JS/CSS 与所有图像、html 分开,但这可能没有必要。

然而,由于没有为每个人明确设置内容编码/缓存,我确实遇到了很多麻烦--include,所以我将其设置如下以使其更清晰。

我能找到的 AWS 文档没有提到任何这些东西

aws s3 sync ./dist/ s3://{bucket} \
--exclude "*" \
--include "static/*.ico" --acl "public-read" --cache-control no-cache \
--include "static/*.png" --acl "public-read" --cache-control no-cache \
--include "*.html" --acl "public-read" --cache-control no-cache \
--include "static/img/*.svg" --acl "public-read" --cache-control no-cache \
--delete \

aws s3 sync ./dist/ s3://{bucket} \
--exclude "*" \
--include "static/js/*.js" --acl "public-read" --cache-control  no-cache --content-encoding gzip \
--include "static/css/*.css" --acl "public-read" --cache-control no-cache --content-encoding gzip \
--delete \ 
Run Code Online (Sandbox Code Playgroud)

仅从 s3 提供服务的非常整洁的小速度改进。