-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackager.sh
More file actions
executable file
·74 lines (59 loc) · 2.21 KB
/
packager.sh
File metadata and controls
executable file
·74 lines (59 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -x
pFlag=0
rFlag=0
nFlag=0
zFlag=0
CreateZipFile(){
rm -rf package
mkdir -p package
pip install -r requirements.txt --target package/
cd package
zip -r9 ../${ZIP_NAME}.zip .
cd ../
zip -g ${ZIP_NAME}.zip appflow_ga.py
}
UsageMessage(){
echo "usage : packager -p <aws profile> -r <aws_region> -n <name of the function> -z <zipname>"
}
while getopts "p:r:n:z:" option
do
case ${option} in
"p" ) AWS_PROFILE=${OPTARG}
pFlag=1
;;
"r" ) AWS_REGION=${OPTARG}
rFlag=1
;;
"n" ) FUNCTION_NAME=${OPTARG}
nFlag=1
;;
"z" ) ZIP_NAME=${OPTARG}
zFlag=1
;;
\? ) UsageMessage
exit 4
;;
esac
done
if [ ${pFlag} -eq 0 ] || [ ${rFlag} -eq 0 ] || [ ${nFlag} -eq 0 ] || [ ${zFlag} -eq 0 ]; then
UsageMessage
exit 4
fi
CreateZipFile
function_name_cli=`aws lambda get-function --function-name ${FUNCTION_NAME} --profile ${AWS_PROFILE} --region=${AWS_REGION} | jq -r '.Configuration | .FunctionName'`
if [ ${function_name_cli} == ${FUNCTION_NAME} ]; then
echo "Found the function. Ready to update."
aws lambda update-function-code --function-name ${FUNCTION_NAME} --zip-file fileb://${ZIP_NAME}.zip --profile ${AWS_PROFILE} --region=${AWS_REGION}
aws lambda update-function-configuration --function-name ${FUNCTION_NAME} --profile ${AWS_PROFILE} --region=${AWS_REGION}
else
echo "Unable to find the function. We will create the function for you."
ACCOUNTID=`aws sts get-caller-identity --region=${AWS_REGION} --profile=${AWS_PROFILE} | jq -r '.Account'`
ROLEARN=`aws iam get-role --role-name lambda-cli-role --region=${AWS_REGION} --profile=${AWS_PROFILE} | jq -r '.Role | .Arn'`
if [ -z ${ROLEARN} ]; then
echo "The lambda role does not exist. Please ask your admin to create the role with the AWSLambdaBasicExecutionRole policy."
else
aws lambda create-function --function-name ${FUNCTION_NAME} --zip-file fileb://${ZIP_NAME}.zip --handler appflow_ga.lambda_handler --runtime python3.7 --role arn:aws:iam::${ACCOUNTID}:role/lambda-cli-role --profile ${AWS_PROFILE} --region=${AWS_REGION}
aws lambda update-function-configuration --function-name ${FUNCTION_NAME} --profile ${AWS_PROFILE} --region=${AWS_REGION}
fi
fi