updateFunctionCode method

Future<FunctionConfiguration> updateFunctionCode({
  1. required String functionName,
  2. List<Architecture>? architectures,
  3. bool? dryRun,
  4. String? imageUri,
  5. bool? publish,
  6. FunctionVersionLatestPublished? publishTo,
  7. String? revisionId,
  8. String? s3Bucket,
  9. String? s3Key,
  10. String? s3ObjectVersion,
  11. String? sourceKMSKeyArn,
  12. Uint8List? zipFile,
})

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.

May throw CodeSigningConfigNotFoundException. May throw CodeStorageExceededException. May throw CodeVerificationFailedException. May throw InvalidCodeSignatureException. May throw InvalidParameterValueException. May throw PreconditionFailedException. May throw ResourceConflictException. May throw ResourceNotFoundException. May throw ServiceException. May throw TooManyRequestsException.

Parameter 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.

Parameter 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.

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

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

Parameter 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.

Parameter publishTo : Specifies where to publish the function version or configuration.

Parameter 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.

Parameter s3Bucket : 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.

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

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

Parameter sourceKMSKeyArn : 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.

Parameter zipFile : 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.

Implementation

Future<FunctionConfiguration> updateFunctionCode({
  required String functionName,
  List<Architecture>? architectures,
  bool? dryRun,
  String? imageUri,
  bool? publish,
  FunctionVersionLatestPublished? publishTo,
  String? revisionId,
  String? s3Bucket,
  String? s3Key,
  String? s3ObjectVersion,
  String? sourceKMSKeyArn,
  Uint8List? zipFile,
}) async {
  final $payload = <String, dynamic>{
    if (architectures != null)
      'Architectures': architectures.map((e) => e.value).toList(),
    if (dryRun != null) 'DryRun': dryRun,
    if (imageUri != null) 'ImageUri': imageUri,
    if (publish != null) 'Publish': publish,
    if (publishTo != null) 'PublishTo': publishTo.value,
    if (revisionId != null) 'RevisionId': revisionId,
    if (s3Bucket != null) 'S3Bucket': s3Bucket,
    if (s3Key != null) 'S3Key': s3Key,
    if (s3ObjectVersion != null) 'S3ObjectVersion': s3ObjectVersion,
    if (sourceKMSKeyArn != null) 'SourceKMSKeyArn': sourceKMSKeyArn,
    if (zipFile != null) 'ZipFile': base64Encode(zipFile),
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'PUT',
    requestUri:
        '/2015-03-31/functions/${Uri.encodeComponent(functionName)}/code',
    exceptionFnMap: _exceptionFns,
  );
  return FunctionConfiguration.fromJson(response);
}