我一直在试图找出如何更新AWS CodeBuild预安装的jq从1.3到1.6,因为需要使用——argjson参数。一个简单的apt-get
不起作用。
我一直在试图弄清楚如何将AWS CodeBuild预安装的jq从1.3更新到1.6,以便我可以使用我的DevOps所需的一些额外功能。我确实弄清楚了,所以这更像是一个答案而不是一个问题,但我想我应该分享一下,因为我在网上找不到任何专门针对CodeBuild的东西。
# !/bin/bash
pip install --upgrade awscli
aws --version
# Upgrade JQ so JSON substitution can work for layers
wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz
tar -xzf jq-1.6.tar.gz
cd jq-1.6
autoreconf -fi && ./configure --disable-maintainer-mode && make && make install || exit 1
jq --version
现在这个解决方案的原因是,所以我可以用我的CodeBuild生成的一个新的lambda层更新我的Chalice配置文件。以下是CodeBuild for Chalice的完整解决方案:
# !/bin/bash
pip install --upgrade awscli
aws --version
# Upgrade JQ
cd ..
# Upgrade JQ so JSON substitution can work for layers
wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz
tar -xzf jq-1.6.tar.gz
cd jq-1.6
autoreconf -fi && ./configure --disable-maintainer-mode && make && make install || exit 1
jq --version
cd ../
cd src
# Create virtual environment and install requirements
pip install virtualenv
virtualenv /tmp/venv
. /tmp/venv/bin/activate
pip install -r requirements.txt
pip install snowflake-sqlalchemy
cd ../
## Layer update
mkdir -p lambda_layers/python/lib/python3.7/site-packages
# 1) install the dependencies in the desired folder
pip3 install --upgrade snowflake-sqlalchemy -t lambda_layers/python/lib/python3.7/site-packages/.
# 2) Zip the lambda_layers folder
cd lambda_layers
zip -r snowflake_lambda_layer.zip *
# 3) publish layer
layerResults=$(
echo aws lambda publish-layer-version
--layer-name fl-snowflake-lambda-layer
--compatible-runtimes python3.7
--zip-file fileb://snowflake_lambda_layer.zip
)
echo "layer response: $layerResults"
layerARN=$(${layerResults} | jq '.LayerVersionArn')
echo "LayerARN: $layerARN"
cd ../
cd src
## Update Config
contents="$(jq --argjson arn ${layerARN} '.layers = [$arn]' .chalice/config.json)" && echo ${contents} && echo ${contents} > .chalice/config.json
# Unit tests
pip install -r requirements-test.txt
pip install chalice
export PYTHONPATH=.
pytest ./tests/ || exit 1
# Run Migrations
alembic -x stage=${stage} upgrade heads || exit 1
# Load Fixtures
echo ${stage}
python chalicelib/Fixtures/loadFixtures.py ${stage} || exit 1
# Package and deploy Chalice
# chalice deploy --stage ${stage}
chalice package --stage ${stage} /tmp/packaged
aws cloudformation package --template-file /tmp/packaged/sam.json --s3-bucket "${APP_S3_BUCKET}" --output-template-file transformed.yaml