【问题标题】:Shell Script for Deployment in AWS s3在 AWS s3 中部署的 Shell 脚本
【发布时间】:2017-10-16 23:43:36
【问题描述】:

我们在 Angular 2 中构建了一个静态网站,托管在 s3 上。 该网站使用由 AWS Gateway + Lambda Function 制作的 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 中处理部署的更好方法,我将不胜感激。

提前感谢您的帮助!

【问题讨论】:

  • 为什么不能把整个文件夹上传到S3?您对 aws s3 cp --recursive 命令有什么问题?

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


【解决方案1】:

当然,您可以复制整个目录。来自aws s3 sync help

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.

【讨论】:

  • 因为我已经在我的dist 文件夹中,我可以运行aws s3 sync . s3://mybucket,它会按我的意愿工作吗?
  • 确实:cd tmp; touch foo bar baz; aws s3 sync . s3://mybucket/label/sub/
猜你喜欢
  • 2015-07-28
  • 1970-01-01
  • 2013-04-14
  • 2020-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2016-09-13
相关资源
最近更新 更多