我添加了一些自动化脚本示例来删除* .HTML扩展名,并通过添加元对象的内容类型将其上传到s3。我使用JavaScript创建sh文件,运行sh文件。
const recursive = require("recursive-readdir");
const fs = require("fs");
(async (params) => {
let buffer = "aws s3 cp ./out s3://www.Example.com \n";
await recursive("out", [
"css",
"_next",
"images",
"static",
"svg",
"*.ico",
"*.txt",
"*.xml",
"index.html",
"404.html",
]).then(
(files) => {
for (const file of files) {
const path = file.substring(file.indexOf("\\") + 1);
buffer += `aws s3 cp --content-type 'text/html' --metadata-directive REPLACE ./out/${path} s3://www.example.com/${path} \n`;
const removeExtension = file.replace(/\.[^/.]+$/, "");
fs.rename(file, removeExtension, function (err) {
if (err) console.log("ERROR: " + err);
});
}
},
(error) => {
console.error("something exploded", error);
}
);
fs.writeFileSync("deploy.sh", "echo 'copy your files' \n");
fs.appendFileSync("deploy.sh", buffer);
fs.appendFileSync("deploy.sh", 'echo "Invalidation cloudfront"');
fs.appendFileSync("deploy.sh", 'aws cloudfront create-invalidation --distribution-id XXXXXXX --paths "/*" ');
})();
Content-type
在命令行工具中编辑标题?还是在S3或Cloudfront的控制台中?