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

标签 amazon-s3 aws-cli

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

aws s3 sync C:\app s3://myBucket

我想将 js、jpg 和 html 文件的内容编码设置为 gzip。 我成功地通过此命令对所有文件夹执行此操作: --content-encoding gzip 我怎样才能只针对特定的文件类型呢?

最佳答案

这已经很旧了,但我需要找到一种方法来做到这一点:我没有使用 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 \ 

仅从 s3 提供服务的速度有相当巧妙的小提升。

关于amazon-s3 - 通过 aws 命令将内容编码设置为特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165946/

相关文章:

python-2.7 - 无法离线安装 s3cmd

amazon-s3 - UPSERT 拼花 Pyspark

amazon-web-services - 如何从 ec2 snapshot_id 中提取标签名称

amazon-web-services - 复制 S3 文件的更快方法

python - CERBOT ContextualVersionConflict : (zope. 接口(interface) 4.3.2 (/usr/lib/python3/dist-packages)

aws-api-gateway - AWS CLI 更新路径失败

java - Amazon SES 使用来自 S3ObjectInputStream 对象的 java 读取存储在 s3 存储桶中的电子邮件

python - 如何使用适用于 Python 的 AWS SDK 递归列出 AWS S3 存储桶中的文件?

python-2.7 - 使用 ChangeResourceRecordSets Boto3 删除/更新插入时,Change 中缺少字段 'SetIdentifier'

amazon-s3 - 将 Amazon S3 连接到 QlikView 以提取数据