View a markdown version of this page

UpdateFunctionCode - AWS Lambda

UpdateFunctionCode

Updates a Lambda 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.

Note

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.

Request Syntax

PUT /2015-03-31/functions/FunctionName/code HTTP/1.1 Content-type: application/json { "Architectures": [ "string" ], "DryRun": boolean, "ImageUri": "string", "Publish": boolean, "PublishTo": "string", "RevisionId": "string", "S3Bucket": "string", "S3Key": "string", "S3ObjectStorageMode": "string", "S3ObjectVersion": "string", "SourceKMSKeyArn": "string", "ZipFile": blob }

URI Request Parameters

The request uses the following URI parameters.

FunctionName

The name or ARN of the Lambda function.

Name formats
  • Function namemy-function.

  • Function ARNarn:aws:lambda:us-west-2:123456789012:function:my-function.

  • Partial ARN123456789012: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.

Length Constraints: Minimum length of 1. Maximum length of 140.

Pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?

Required: Yes

Request Body

The request accepts the following data in JSON format.

Architectures

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.

Type: Array of strings

Array Members: Fixed number of 1 item.

Valid Values: x86_64 | arm64

Required: No

DryRun

Set to true to validate the request parameters and access permissions without modifying the function code.

Type: Boolean

Required: No

ImageUri

URI of a container image in the Amazon ECR registry. Do not use for a function defined with a .zip file archive.

Type: String

Required: No

Publish

Set to true to publish a new version of the function after updating the code. This has the same effect as calling PublishVersion separately.

Type: Boolean

Required: No

PublishTo

Specifies where to publish the function version or configuration.

Type: String

Valid Values: LATEST_PUBLISHED

Required: No

RevisionId

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.

Type: String

Required: No

S3Bucket

An Amazon S3 bucket in the same AWS Region as your function. The bucket can be in a different AWS account. Use only with a function defined with a .zip file archive deployment package.

Type: String

Length Constraints: Minimum length of 3. Maximum length of 63.

Pattern: [0-9A-Za-z\.\-_]*(?<!\.)

Required: No

S3Key

The Amazon S3 key of the deployment package. Use only with a function defined with a .zip file archive deployment package.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

S3ObjectStorageMode

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.

Type: String

Valid Values: COPY | REFERENCE

Required: No

S3ObjectVersion

For versioned objects, the version of the deployment package object to use.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

SourceKMSKeyArn

The ARN of the AWS Key Management Service (AWS 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 AWS managed key.

Type: String

Pattern: (arn:(aws[a-zA-Z-]*)?:[a-z0-9-.]+:.*)|()

Required: No

ZipFile

The base64-encoded contents of the deployment package. AWS SDK and AWS CLI clients handle the encoding for you. Use only with a function defined with a .zip file archive deployment package.

Type: Base64-encoded binary data object

Required: No

Response Syntax

HTTP/1.1 200 Content-type: application/json { "Architectures": [ "string" ], "CapacityProviderConfig": { "LambdaManagedInstancesCapacityProviderConfig": { "CapacityProviderArn": "string", "ExecutionEnvironmentMemoryGiBPerVCpu": number, "PerExecutionEnvironmentMaxConcurrency": number } }, "CodeSha256": "string", "CodeSize": number, "ConfigSha256": "string", "DeadLetterConfig": { "TargetArn": "string" }, "Description": "string", "DurableConfig": { "ExecutionTimeout": number, "KMSKeyArn": "string", "RetentionPeriodInDays": number }, "Environment": { "Error": { "ErrorCode": "string", "Message": "string" }, "Variables": { "string" : "string" } }, "EphemeralStorage": { "Size": number }, "FileSystemConfigs": [ { "Arn": "string", "LocalMountPath": "string", "S3FilesConfig": { "DirectS3Read": "string" } } ], "FunctionArn": "string", "FunctionName": "string", "Handler": "string", "ImageConfigResponse": { "Error": { "ErrorCode": "string", "Message": "string" }, "ImageConfig": { "Command": [ "string" ], "EntryPoint": [ "string" ], "WorkingDirectory": "string" } }, "KMSKeyArn": "string", "LastModified": "string", "LastUpdateStatus": "string", "LastUpdateStatusReason": "string", "LastUpdateStatusReasonCode": "string", "Layers": [ { "Arn": "string", "CodeSize": number, "SigningJobArn": "string", "SigningProfileVersionArn": "string" } ], "LoggingConfig": { "ApplicationLogLevel": "string", "LogFormat": "string", "LogGroup": "string", "SystemLogLevel": "string" }, "MasterArn": "string", "MemorySize": number, "PackageType": "string", "RevisionId": "string", "Role": "string", "Runtime": "string", "RuntimeVersionConfig": { "Error": { "ErrorCode": "string", "Message": "string" }, "RuntimeVersionArn": "string" }, "SigningJobArn": "string", "SigningProfileVersionArn": "string", "SnapStart": { "ApplyOn": "string", "OptimizationStatus": "string" }, "State": "string", "StateReason": "string", "StateReasonCode": "string", "TenancyConfig": { "TenantIsolationMode": "string" }, "Timeout": number, "TracingConfig": { "Mode": "string" }, "Version": "string", "VpcConfig": { "Ipv6AllowedForDualStack": boolean, "SecurityGroupIds": [ "string" ], "SubnetIds": [ "string" ], "