uploadFunction method
Creates a new Lambda function or updates an existing function. The function metadata is created from the request parameters, and the code for the function is provided by a .zip file in the request body. If the function name already exists, the existing Lambda function is updated with the new code and metadata.
This operation requires permission for the
lambda:UploadFunction
action.
May throw ServiceException. May throw InvalidParameterValueException. May throw ResourceNotFoundException.
Parameter functionName
:
The name you want to assign to the function you are uploading. The
function names appear in the console and are returned in the
ListFunctions API. Function names are used to specify functions to
other AWS Lambda APIs, such as InvokeAsync.
Parameter functionZip
:
A .zip file containing your packaged source code. For more information
about creating a .zip file, go to AWS
LambdaL How it Works in the AWS Lambda Developer Guide.
Parameter handler
:
The function that Lambda calls to begin execution. For Node.js, it is the
module-name.export value in your function.
Parameter mode
:
How the Lambda function will be invoked. Lambda supports only the "event"
mode.
Parameter role
:
The Amazon Resource Name (ARN) of the IAM role that Lambda assumes when it
executes your function to access any other Amazon Web Services (AWS)
resources.
Parameter runtime
:
The runtime environment for the Lambda function you are uploading.
Currently, Lambda supports only "nodejs" as the runtime.
Parameter description
:
A short, user-defined function description. Lambda does not use this
value. Assign a meaningful description as you see fit.
Parameter memorySize
:
The amount of memory, in MB, your Lambda function is given. Lambda uses
this memory size to infer the amount of CPU allocated to your function.
Your function use-case determines your CPU and memory requirements. For
example, database operation might need less memory compared to image
processing function. The default value is 128 MB. The value must be a
multiple of 64 MB.
Parameter timeout
:
The function execution time at which Lambda should terminate the function.
Because the execution time has cost implications, we recommend you set
this value based on your expected execution time. The default is 3
seconds.
Implementation
Future<FunctionConfiguration> uploadFunction({
required String functionName,
required Uint8List functionZip,
required String handler,
required Mode mode,
required String role,
required Runtime runtime,
String? description,
int? memorySize,
int? timeout,
}) async {
ArgumentError.checkNotNull(functionName, 'functionName');
_s.validateStringLength(
'functionName',
functionName,
1,
64,
isRequired: true,
);
ArgumentError.checkNotNull(functionZip, 'functionZip');
ArgumentError.checkNotNull(handler, 'handler');
ArgumentError.checkNotNull(mode, 'mode');
ArgumentError.checkNotNull(role, 'role');
ArgumentError.checkNotNull(runtime, 'runtime');
_s.validateStringLength(
'description',
description,
0,
256,
);
_s.validateNumRange(
'memorySize',
memorySize,
128,
1024,
);
_s.validateNumRange(
'timeout',
timeout,
1,
60,
);
final $query = <String, List<String>>{
'Handler': [handler],
'Mode': [mode.toValue()],
'Role': [role],
'Runtime': [runtime.toValue()],
if (description != null) 'Description': [description],
if (memorySize != null) 'MemorySize': [memorySize.toString()],
if (timeout != null) 'Timeout': [timeout.toString()],
};
final response = await _protocol.send(
payload: functionZip,
method: 'PUT',
requestUri: '/2014-11-13/functions/${Uri.encodeComponent(functionName)}',
queryParams: $query,
exceptionFnMap: _exceptionFns,
);
return FunctionConfiguration.fromJson(response);
}