Skip to content

Instantly share code, notes, and snippets.

@shimo164
Last active August 3, 2022 05:40
Show Gist options
  • Select an option

  • Save shimo164/759a987da96cb41543b7fa087eb5d684 to your computer and use it in GitHub Desktop.

Select an option

Save shimo164/759a987da96cb41543b7fa087eb5d684 to your computer and use it in GitHub Desktop.
Move AWS Lambda function with another name, region.
#!/bin/bash
# Rename Lambda by moviong function to another name.
# Moving to another region is also possible.
# Param: role_lambda_execute
# See. https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-awscli.html
# accountID
# function_name_orig
# region_orig
# function_name_orig
# region_new
#
# Uncomment aws `lambda delete-functon ...` to delete original lambda function
role_lambda_execute="arn:aws:iam::<accountID>:role/lambda-ex"
function_name_orig="Lambda_function1"
region_orig="<region>"
function_name_new="Lambda_function2"
region_new="<region>"
zip_name="tmp.zip"
jsonData=$(aws lambda get-function --function-name $function_name_orig --region $region_orig)
handler=$(echo $jsonData | jq -r ".Configuration.Handler")
runtime=$(echo $jsonData | jq -r ".Configuration.Runtime")
S3LocationURL=$(echo $jsonData | jq -r ".Code.Location")
wget --quiet --output-document $zip_name $S3LocationURL
aws lambda create-function --function-name $function_name_new \
--zip-file fileb://$zip_name \
--handler $handler \
--runtime $runtime \
--role $role_lambda_execute \
--region $region_new
rm $zip_name
# aws lambda delete-function --function-name $function_name_orig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment