update_function_code
¶
update_function_code(
function_name: FunctionName,
*,
config_overrides: Optional[LambdaClientConfig] = None,
zip_file: Optional[Blob] = None,
s3_bucket: Optional[S3Bucket] = None,
s3_key: Optional[S3Key] = None,
s3_object_version: Optional[S3ObjectVersion] = None,
s3_object_storage_mode: Optional[S3ObjectStorageMode] = None,
image_uri: Optional[String] = None,
architectures: Optional[ArchitecturesList] = None,
publish: Optional[Boolean] = None,
publish_to: Optional[FunctionVersionLatestPublished] = None,
dry_run: Optional[Boolean] = None,
revision_id: Optional[String] = None,
source_kms_key_arn: Optional[KMSKeyArn] = None,
) -> FunctionConfiguration
Updates a Lambda Event Function's code. If code signing is enabled for the function, the code package must be signed by a trusted publisher. For more information, see Configuring code signing for Lambda.
If the function's package type is Image, then you must specify the code package in ImageUri as the URI of a container image in the Amazon ECR registry.
If the function's package type is Zip, then you must specify the deployment package as a .zip file archive. Enter the Amazon S3 bucket and key of the code .zip file location. You can also provide the function code inline using the ZipFile field.
The code in the deployment package must be compatible with the target instruction set architecture of the function (x86-64 or arm64).
The function's code is locked when you publish a version. You can't modify the code of a published version, only the unpublished version.
For a function defined as a container image, Lambda resolves the image tag to an image digest. In Amazon ECR, if you update the image tag to a new image, Lambda does not automatically update the function.
Parameters:
-
function_name(FunctionName) –The name or ARN of the Lambda function.
Name formats
-
Function name –
my-function. -
Function ARN –
arn:aws:lambda:us-west-2:123456789012:function:my-function. -
Partial ARN –
123456789012:function:my-function.
The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.
-
-
zip_file(Optional[Blob], default:None) –The base64-encoded contents of the deployment package. Amazon Web Services SDK and CLI clients handle the encoding for you. Use only with a function defined with a .zip file archive deployment package.
-
s3_bucket(Optional[S3Bucket], default:None) –An Amazon S3 bucket in the same Amazon Web Services Region as your function. The bucket can be in a different Amazon Web Services account. Use only with a function defined with a .zip file archive deployment package.
-
s3_key(Optional[S3Key], default:None) –The Amazon S3 key of the deployment package. Use only with a function defined with a .zip file archive deployment package.
-
s3_object_version(Optional[S3ObjectVersion], default:None) –For versioned objects, the version of the deployment package object to use.
-
s3_object_storage_mode(Optional[S3ObjectStorageMode], default:None) –Specifies how the deployment package is stored. Valid values:
-
COPY(default) – Uploads a copy of your deployment package to Lambda. -
REFERENCE– Lambda references the deployment package from the specified Amazon S3 bucket.
-
-
image_uri(Optional[String], default:None) –URI of a container image in the Amazon ECR registry. Do not use for a function defined with a .zip file archive.
-
architectures(Optional[ArchitecturesList], default:None) –The instruction set architecture that the function supports. Enter a string array with one of the valid values (arm64 or x86_64). The default value is
x86_64. -
publish(Optional[Boolean], default:None) –Set to true to publish a new version of the function after updating the code. This has the same effect as calling PublishVersion separately.
-
publish_to(Optional[FunctionVersionLatestPublished], default:None) –Specifies where to publish the function version or configuration.
-
dry_run(Optional[Boolean], default:None) –Set to true to validate the request parameters and access permissions without modifying the function code.
-
revision_id(Optional[String], default:None) –Update the function only if the revision ID matches the ID that's specified. Use this option to avoid modifying a function that has changed since you last read it.
-
source_kms_key_arn(Optional[KMSKeyArn], default:None) –The ARN of the Key Management Service (KMS) customer managed key that's used to encrypt your function's .zip deployment package. If you don't provide a customer managed key, Lambda uses an Amazon Web Services managed key.
Raises:
-
CodeSigningConfigNotFoundException–The specified code signing configuration does not exist.
-
CodeStorageExceededException–Your Amazon Web Services account has exceeded its maximum total code size. For more information, see Lambda quotas.
-
CodeVerificationFailedException–The code signature failed one or more of the validation checks for signature mismatch or expiry, and the code signing policy is set to ENFORCE. Lambda blocks the deployment.
-
InvalidCodeSignatureException–The code signature failed the integrity check. If the integrity check fails, then Lambda blocks deployment, even if the code signing policy is set to WARN.
-
InvalidParameterValueException–One of the parameters in the request is not valid.
-
PreconditionFailedException–The RevisionId provided does not match the latest RevisionId for the Lambda function or alias.
-
For AddPermission and RemovePermission API operations: Call
GetPolicyto retrieve the latest RevisionId for your resource. -
For all other API operations: Call
GetFunctionorGetAliasto retrieve the latest RevisionId for your resource.
-
-
ResourceConflictException–The resource already exists, or another operation is in progress.
-
ResourceNotFoundException–The resource specified in the request does not exist.
-
ServiceException–The Lambda service encountered an internal error.
-
TooManyRequestsException–The request throughput limit was exceeded. For more information, see Lambda quotas.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To update a Lambda function's code The following example replaces the code of the unpublished ($LATEST) version of a function named my-function with the contents of the specified zip file in Amazon S3.
>>> client.update_function_code(function_name='my-function', s3_bucket='my-bucket-1xpuxmplzrlbh', s3_key='function.zip')
Source code in docs_src/capo_lambda/_services/_lambda.py
3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 | |