我们在 Angular 2 中构建了一个静态网站,托管在 s3 上。 该网站使用在 AWS 网关 + Lambda 函数中创建的 API。
对于我们的前端部署,我们喜欢在 Linux 上使用 EC2 实例,我们在其中启动一个 Shell
脚本,该脚本将处理我们的构建并从 EC2 上传到我们的 S3。
#!/bin/bash
#pull from branch
git checkout --force "$1"
git pull
#build the app
ng build --production
cd dist
#uplaod to S3
$counter = find dist -type f | wc -l
#staging parameter
if ["$1" = "staging"]
then aws s3 cp dist s3://STAGINBUCKET --recursive
#[1]
#live parameter
if ["$1" = "live"]
then aws s3 cp dist s3://LIVEBUCKT --recursive
#[1]
#Errorhandler
else echo "parameter $1 error"
我们的问题是我们无法将整个文件夹上传到 S3,因此我们需要一个 for/while 循环将每个文件上传到我们的存储桶。
我试过了:[1]
for i in `seq 1 $counter`
do
#upload to file on position $i in folder dist
done
这对我不起作用。
如果有人知道在 AWS 中处理部署的更好方法,我将不胜感激。
提前感谢您的帮助!
最佳答案
当然你可以复制整个目录。来自 aws s3 同步帮助
:
NAME
sync -
DESCRIPTION
Syncs directories and S3 prefixes. Recursively copies new and updated
files from the source directory to the destination. Only creates fold-
ers in the destination if they contain one or more files.
关于linux - 用于在 AWS s3 中部署的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44026080/