问题描述
我已经建立了一个代码构建项目并在ubuntu服务器上运行,以从快照克隆rds数据库服务器。许多功能都按预期工作,但是当我尝试在buildspec.yml中包含以下内容时,该工作失败了,它不喜欢该命令。
猜测作业不喜欢格式设置,但是有点困惑如何使用
- while [ $(aws rds describe-db-clusters --db-cluster-identifier MysqL-dev-20201009|grep -c '"Status": "available"') -eq 0 ]; do echo "sleep 60s"; sleep 60; done
这是完整的buildspec文件:
Version: 0.2
phases:
install:
runtime-versions:
python: 3.7
pre_build:
commands:
- pip install --upgrade pip
- pip3 install awscli --upgrade --user
- export SOURCEDBENV=MysqL-dev
- export DATE=`date +%Y%m%d`
- export TARGETDBENV=$SOURCEDBENV-$DATE
- echo $TARGETDBENV
- export PREARNSNAP=$(aws rds describe-db-cluster-snapshots --db-cluster-identifier $SOURCEDBENV --query="reverse(sort_by(DBClusterSnapshots,&SnapshotCreateTime))[0]|DBClusterSnapshotArn" )
- export ARNSNAP=`echo $PREARNSNAP | tr -d '"'`
- echo $ARNSNAP
- aws rds restore-db-cluster-from-snapshot --snapshot-identifier $ARNSNAP --db-cluster-identifier $TARGETDBENV --engine aurora-MysqL
- aws rds create-db-instance --db-instance-identifier $TARGETDBENV --db-instance-class db.t3.medium --db-subnet-group-name db_subnet_grp_2019 --engine aurora-MysqL --db-cluster-identifier $TARGETDBENV
- while [ $(aws rds describe-db-cluster-endpoints --db-cluster-identifier $dbnAME | grep -c available) -eq 0 ]; do echo "sleep 60s"; sleep 60; done
- echo "Temp db ready"
- export ENDPOINT=$(aws rds describe-db-cluster-endpoints --db-cluster-identifier $DBIDENTIFIER| grep "\"Endpoint\"" | grep -v "\-ro\-" | awk -F '\"' '{print $4}')
- echo $ENDPOINT
build:
commands:
- echo Build started on `date`
- echo proceed db connection to $ENDPOINT
- echo proceed db migrate update,DDL proceed here
- echo proceed application test,CRUD test run here
post_build:
commands:
- echo Build completed on `date`
- echo $dbnAME