Use case: need to copy Lambda function from one AWS account to another. Using the AWS CLI, the following commands can be run. For convenience, set up the AWS Credentials so you can use the named profiles. Below there are source and target profiles for the two IAM user credentials for the respective accounts.

# 1. Create a local file of All Lambda Functions
aws lambda list-functions --profile source > list-of-lambda-functions.json
# 2. After picking from the list above, get the Lambda function name so you can
#Download the Lambda Function
aws lambda get-function --function-name my_lambda_function --query 'Code.Location' --profile source | xargs -n 1 curl -o my_lambda_function.zip -s -L

# 3. Be sure to create an IAM role for the Lambda service. It is used in the next step.
After creating the role, you can copy the ARN from the role summary page.

#4. Create Lambda Function
The creation command requires that you have a JSON file with the parameters for creating the Lambda function. The following is the minimum you will need for my_lambda_function.json:
{
"FunctionName": "my_lambda_function",
"Runtime": "nodejs24.x",
"Role": "arn:aws:iam::123456789012:role/lambdarole",
"Handler": "index.handler",
"Code": {
"ZipFile": "fileb://my_lambda_function.zip"
},
"Description": "My function created via JSON input and local zip file",
"Timeout": 30,
"MemorySize": 128
}

You can get most of this information from the list Lambda functions in Step 1.

aws lambda create-function --cli-input-json file://my_lambda_function.json --zip-file fileb://my_lambda_function.zip --profile target

 

#This is additional information to view the settings of a Lambda function
#Get Configuration of Lambda Function
aws lambda get-function-configuration --function-name my_lambda_function