Skip to content

Instantly share code, notes, and snippets.

@jppommet
Forked from smithclay/lambda-concurrent.sh
Created June 17, 2017 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jppommet/18695478e9f084ac8db50061e92094b6 to your computer and use it in GitHub Desktop.
Save jppommet/18695478e9f084ac8db50061e92094b6 to your computer and use it in GitHub Desktop.
Concurrently execute a lambda function for warming purposes
#!/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