2 Answers
- Newest
- Most votes
- Most comments
4
you need to change the region in below code , it will automatically update python runtime 3.6 to 3.9 in all lambda functions.
#!/bin/bash
# listing all functions in csv format using Regular expressions
lambda_fun=$(
aws lambda list-functions \
--function-version ALL \
--region=us-east-2 \
--output text \
--query "Functions[?Runtime=='python3.6'].FunctionName" | sed -E 's/ +/\\n/g')
# adding header to csv and redirecting to file [file.csv]
echo -e "lambda_functions\n$lambda_fun" > file.csv
# updating lambda function by iterating using while loop
i=0
# input file separate
OLDIFS=$IFS
IFS=","
# while loop
while read lambda_functions
do
((i=i+1))
# skipping header
if [ "$i" -eq 1 ]; then
continue
fi
runtime_update=$(
aws lambda update-function-configuration \
--function-name "$lambda_functions" \
--runtime python3.9 --output text --query "Runtime"
)
echo "$lambda_functions" is successfully updated to "$runtime_update"
done < file.csv
IFS=$OLDIFS
answered 2 years ago
1
You can do something like this. It will update all function in one region.
Attention though:
- this will ruin any Infrastructure as Code that you have. If you have IaC you should update any code there in stead of running a script
- there are differences between python 3.6 and 3.9, your lambdas might stop working after the update so testing out all code paths is necessary
import boto3 import json client = boto3.client('lambda') functions = [] response = client.list_functions() nexttoken = response.get('NextMarker', None) functions.extend(response['Functions']) while(nexttoken): response = client.list_functions(Marker=nexttoken) nexttoken = response.get('NextMarker', None) functions.extend(response['Functions']) for function in functions: if function['Runtime'] == 'python3.6': client.update_function_configuration( FunctionName=function['FunctionName'], Runtime='python3.9' )
answered 2 years ago
Relevant content
- asked 2 months ago
- asked 5 months ago
- asked 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
be aware that aws lambda list-functions will not return all lambda since it uses pagination... (you can add the switch --no-paginate to prevent this)