updateFunctionCode method

Future<FunctionConfiguration> updateFunctionCode({
  1. required String functionName,
  2. bool? dryRun,
  3. String? imageUri,
  4. bool? publish,
  5. String? revisionId,
  6. String? s3Bucket,
  7. String? s3Key,
  8. String? s3ObjectVersion,
  9. 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.

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 ServiceException. May throw ResourceNotFoundException. May throw InvalidParameterValueException. May throw TooManyRequestsException. May throw CodeStorageExceededException. May throw PreconditionFailedException. May throw ResourceConflictException. May throw CodeVerificationFailedException. May throw InvalidCodeSignatureException. May throw CodeSigningConfigNotFoundException.

Parameter functionName : The name 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.

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.

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 revisionId : Only update the function 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 AWS Region as your function. The bucket can be in a different AWS account.

Parameter s3Key : The Amazon S3 key of the deployment package.

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

Parameter zipFile : The base64-encoded contents of the deployment package. AWS SDK and AWS CLI clients handle the encoding for you.

Implementation

Future<FunctionConfiguration> updateFunctionCode({
  required String functionName,
  bool? dryRun,
  String? imageUri,
  bool? publish,
  String? revisionId,
  String? s3Bucket,
  String? s3Key,
  String? s3ObjectVersion,
  Uint8List? zipFile,
}) async {
  ArgumentError.checkNotNull(functionName, 'functionName');
  _s.validateStringLength(
    'functionName',
    functionName,
    1,
    140,
    isRequired: true,
  );
  _s.validateStringLength(
    's3Bucket',
    s3Bucket,
    3,
    63,
  );
  _s.validateStringLength(
    's3Key',
    s3Key,
    1,
    1024,
  );
  _s.validateStringLength(
    's3ObjectVersion',
    s3ObjectVersion,
    1,
    1024,
  );
  final $payload = <String, dynamic>{
    if (dryRun != null) 'DryRun': dryRun,
    if (imageUri != null) 'ImageUri': imageUri,
    if (publish != null) 'Publish': publish,
    if (revisionId != null) 'RevisionId': revisionId,
    if (s3Bucket != null) 'S3Bucket': s3Bucket,
    if (s3Key != null) 'S3Key': s3Key,
    if (s3ObjectVersion != null) 'S3ObjectVersion': s3ObjectVersion,
    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);
}