linux - 用于在 AWS s3 中部署的 Shell 脚本

标签 linux shell amazon-web-services amazon-s3 amazon-ec2

我们在 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/

相关文章:

android - 如何在 Android 中使用共享内存 (IPC)

linux - 仅回显有效用户

c - 在linux中使用execv使用 './'命令

javascript - 亚马逊 lambda : "Handler ' handle' missing on module 'exports' "

amazon-web-services - 当触发的 Lambda 函数无法处理该消息时,如何防止 AWS SQS 删除该消息?

linux - 远程检查 linux 中是否存在所有文件?

linux - RHEL 中 "members"的等效命令

linux - 在后台运行 heredoc 格式的脚本?

java - 无法启动 HBase shell

postgresql - 几个小时后无法连接 AWS RDS for PostgreSQL