Created
November 29, 2016 14:32
-
-
Save benoittgt/9977929b01f0d5b03c5e9fdda39adadd to your computer and use it in GitHub Desktop.
Create lambda per env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
version=`cat package.json | grep version | cut -d: -f2 | sed -e "s/\"//g" | sed -e "s/ //g" | sed -e "s/\,//g"` | |
function_name=stats_refresher | |
filename=$function_name-$version.zip | |
region=eu-west-1 | |
envs=(int demo prod) | |
files_to_copy=( index.js package.json node_modules dist rds_config_from_env.js ) | |
echo "$(tput setaf 3)-> Test pass?$(tput sgr0)" | |
npm test | |
echo -e "$(tput setaf 2)-> Tests succeed !\n$(tput sgr0)" | |
echo "$(tput setaf 3)-> Install npm package$(tput sgr0)" | |
npm install | |
echo -e "$(tput setaf 2)-> Npm package installed\n$(tput sgr0)" | |
for env in "${envs[@]}" | |
do | |
lambda_name="$function_name"_"$env" | |
echo "$(tput setaf 6)-> Let's go with $lambda_name$(tput sgr0)" | |
echo "$(tput setaf 3) -> Copying $lambda_name$(tput sgr0)" | |
mkdir -p $lambda_name | |
cp -rf ${files_to_copy[@]} $lambda_name/ | |
cd $lambda_name | |
echo "$(tput setaf 3) -> Zip $lambda_name$(tput sgr0)" | |
zip -q -r ${filename} ${files_to_copy[@]} | |
echo "$(tput setaf 3) -> Move to dist folder for backups$(tput sgr0)" | |
mv -f $filename dist/$filename | |
echo "$(tput setaf 3) -> Updating $lambda_name lambda in AWS$(tput sgr0)" | |
aws lambda update-function-code --function-name $lambda_name --zip-file fileb://dist/$filename --region $region --output table | |
echo -e "$(tput setaf 4)-> Done updating $lambda_name lambda\n$(tput sgr0)" | |
cd .. | |
done | |
echo -e "$(tput setaf 4)-> Done updating all lambdas 👸🏾$(tput sgr0)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment