The following code example shows how to update Lambda function code.
Note
The source code for these examples is in the AWS Code Examples GitHub repository. Have feedback on a code example? Create an Issue in the code examples repo.
SDK for Python (Boto3)
To learn how to set up and run this example, see GitHub.
class LambdaWrapper:
def __init__(self, lambda_client, iam_resource):
self.lambda_client = lambda_client
self.iam_resource = iam_resource
def update_function_code(self, function_name, deployment_package):
"""
Updates the code for a Lambda function by submitting a .zip archive that contains
the code for the function.
:param function_name: The name of the function to update.
:param deployment_package: The function code to update, packaged as bytes in
.zip format.
:return: Data about the update, including the status.
"""
try:
response = self.lambda_client.update_function_code(
FunctionName=function_name, ZipFile=deployment_package)
except ClientError as err:
logger.error(
"Couldn't update function %s. Here's why: %s: %s", function_name,
err.response['Error']['Code'], err.response['Error']['Message'])
raise
else:
return response
- For API details, see UpdateFunctionCode in AWS SDK for Python (Boto3) API Reference.
For a complete list of AWS SDK developer guides and code examples, see Using Lambda with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.