2017-05-17 3 views
1

私たちは、s3上でホストされている静的なウェブサイトを角2で構築しています。 ウェブサイトは、AWS Gateway + Lambda Functionで作成されたAPIを使用しています。AWS s3での展開のためのシェルスクリプト

私たちのフロントエンドの展開では、EC2インスタンスをLinuxで使用することをお勧めします。ここでは、スクリプトを開始し、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にフォルダ全体をアップロード傾けるということですので、我々は我々のバケットにエブリーファイルをアップロードしますため/ whileループを必要としています。

私がしようと試み:私のために仕事を文句を言わない[1]

for i in `seq 1 $counter` 
do 
    #upload to file on position $i in folder dist 
done 

を。

誰かがAWSでデプロイメントを処理するためのより良い方法を知っていれば、私はヒントをいただければ幸いです。

アドバンスのおかげでよろしく!

+0

なぜフォルダ全体をS3にアップロードできないのですか? aws s3 cp --recursiveコマンドで何が問題になっていますか? – jarmod

答えて

2

もちろん、ディレクトリ全体をコピーすることができます。から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. 
+0

私の 'dist'フォルダに既にあるので、aws s3 syncを実行することができます。 s3:// mybucket'それは私が望むように動作しますか? – sHamann

+0

確かに: 'cd tmp;タッチfooバーbaz; aws s3の同期。 s3:// mybucket/label/sub/' – iMil

関連する問題