Created
May 24, 2017 03:27
-
-
Save smithclay/e89dfe35fe2a4938db56bb12df76777c to your computer and use it in GitHub Desktop.
Concurrently execute a lambda function for warming purposes
This file contains hidden or 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 | |
# This attempts to concurrently execute an AWS Lambda function. WIP. | |
# After execution, roughly NUM_EXECUTION containers will be ready | |
# to accept requests. | |
# More advanced strategies are out there. Check out @lambdacult on twitter, for example. | |
AWS_LAMBDA_FUNCTION_NAME=LambdaInfo | |
NUM_EXECUTIONS=3 | |
TMP_FILE=$(mktemp) | |
# get 7-day max invocations in 1 minute | |
# todo: use this value to set the number of executions | |
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --dimensions Name=FunctionName,Value=LambdaInfo --metric-name Invocations --start-time $(date -v -2d -u +"%Y-%m-%dT%H:%M:%SZ") --end-time $(date -u +"%Y-%m-%dT%H:%M:%SZ") --statistics Maximum --period 86400 | |
for i in `seq 1 $NUM_EXECUTIONS`; | |
do | |
echo "[$i] Executing $AWS_LAMBDA_FUNCTION_NAME..." | |
aws lambda invoke --invocation-type Event --function-name $AWS_LAMBDA_FUNCTION_NAME --payload '' --qualifier \$LATEST --log-type None /dev/null >> $TMP_FILE 2>&1 & | |
done | |
wait | |
echo "Finished executing $AWS_LAMBDA_FUNCTION_NAME!" | |
cat $TMP_FILE | |
rm $TMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment