invoke
¶
invoke(
function_name: NamespacedFunctionName,
*,
config_overrides: Optional[LambdaClientConfig] = None,
invocation_type: Optional[InvocationType] = None,
log_type: Optional[LogType] = None,
client_context: Optional[String] = None,
durable_execution_name: Optional[DurableExecutionName] = None,
payload: Optional[Blob] = None,
qualifier: Optional[NumericLatestPublishedOrAliasQualifier] = None,
tenant_id: Optional[TenantId] = None,
) -> InvocationResponse
Invokes a Lambda Event Function. You can invoke a function synchronously (and wait for the response), or asynchronously. By default, Lambda invokes your function synchronously (i.e. theInvocationType is RequestResponse). To invoke a function asynchronously, set InvocationType to Event. Lambda passes the ClientContext object to your function for synchronous invocations only.
For synchronous invocations, the maximum payload size is 6 MB. For asynchronous invocations, the maximum payload size is 1 MB.
For synchronous invocation, details about the function response, including errors, are included in the response body and headers. For either invocation type, you can find more information in the execution log and trace.
When an error occurs, your function may be invoked multiple times. Retry behavior varies by error type, client, event source, and invocation type. For example, if you invoke a function asynchronously and it returns an error, Lambda executes the function up to two more times. For more information, see Error handling and automatic retries in Lambda.
For asynchronous invocation, Lambda adds events to a queue before sending them to your function. If your function does not have enough capacity to keep up with the queue, events may be lost. Occasionally, your function may receive the same event multiple times, even if no error occurs. To retain events that were not processed, configure your function with a dead-letter queue.
The status code in the API response doesn't reflect function errors. Error codes are reserved for errors that prevent your function from executing, such as permissions errors, quota errors, or issues with your function's code and configuration. For example, Lambda returns TooManyRequestsException if running the function would cause you to exceed a concurrency limit at either the account level (ConcurrentInvocationLimitExceeded) or function level (ReservedFunctionConcurrentInvocationLimitExceeded).
For functions with a long timeout, your client might disconnect during synchronous invocation while it waits for a response. Configure your HTTP client, SDK, firewall, proxy, or operating system to allow for long connections with timeout or keep-alive settings.
This operation requires permission for the lambda:InvokeFunction action. For details on how to set up permissions for cross-account invocations, see Granting function access to other accounts.
Parameters:
-
function_name(NamespacedFunctionName) –The name or ARN of the Lambda function, version, or alias.
Name formats
-
Function name –
my-function(name-only),my-function:v1(with alias). -
Function ARN –
arn:aws:lambda:us-west-2:123456789012:function:my-function. -
Partial ARN –
123456789012:function:my-function.
You can append a version number or alias to any of the formats. The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.
-
-
invocation_type(Optional[InvocationType], default:None) –Choose from the following options.
-
RequestResponse(default) – Invoke the function synchronously. Keep the connection open until the function returns a response or times out. The API response includes the function response and additional data. -
Event– Invoke the function asynchronously. Send events that fail multiple times to the function's dead-letter queue (if one is configured). The API response only includes a status code. -
DryRun– Validate parameter values and verify that the user or role has permission to invoke the function.
-
-
log_type(Optional[LogType], default:None) –Set to
Tailto include the execution log in the response. Applies to synchronously invoked functions only. -
client_context(Optional[String], default:None) –Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object. Lambda passes the
ClientContextobject to your function for synchronous invocations only. -
durable_execution_name(Optional[DurableExecutionName], default:None) –A unique name for the durable execution. If you invoke a durable function using a name that already exists with the same payload, Lambda returns the existing execution instead of creating a duplicate. If the payload differs, Lambda returns a
DurableExecutionAlreadyStartedExceptionerror.If not specified, Lambda generates a unique identifier automatically. For more information, see Execution names.
-
payload(Optional[Blob], default:None) –The JSON that you want to provide to your Lambda function as input. The maximum payload size is 6 MB for synchronous invocations and 1 MB for asynchronous invocations.
You can enter the JSON directly. For example,
--payload '{ "key": "value" }'. You can also specify a file path. For example,--payload file://payload.json. -
qualifier(Optional[NumericLatestPublishedOrAliasQualifier], default:None) –Specify a version or alias to invoke a published version of the function.
-
tenant_id(Optional[TenantId], default:None) –The identifier of the tenant in a multi-tenant Lambda function.
Raises:
-
CodeArtifactUserDeletedException–The Lambda function couldn't be invoked because its code artifact user has been deleted. Wait for Lambda to provision a new code artifact user, or update the function's code package to recreate it.
-
CodeArtifactUserFailedException–The Lambda function couldn't be invoked because provisioning of its code artifact user failed. Update the function's code package or check the Lambda function's
StateandStateReasonCodefor additional context. -
CodeArtifactUserPendingException–The Lambda function couldn't be invoked because its code artifact user is still being provisioned. Wait for the function's
Stateto becomeActiveand try the request again. -
DurableExecutionAlreadyStartedException–The durable execution with the specified name has already been started. Each durable execution name must be unique within the function. Use a different name or check the status of the existing execution.
-
EC2AccessDeniedException–Need additional permissions to configure VPC settings.
-
EC2ThrottledException–Amazon EC2 throttled Lambda during Lambda function initialization using the execution role provided for the function.
-
EC2UnexpectedException–Lambda received an unexpected Amazon EC2 client exception while setting up for the Lambda function.
-
EFSIOException–An error occurred when reading from or writing to a connected file system.
-
EFSMountConnectivityException–The Lambda function couldn't make a network connection to the configured file system.
-
EFSMountFailureException–The Lambda function couldn't mount the configured file system due to a permission or configuration issue.
-
EFSMountTimeoutException–The Lambda function made a network connection to the configured file system, but the mount operation timed out.
-
ENILimitReachedException–Lambda couldn't create an elastic network interface in the VPC, specified as part of Lambda function configuration, because the limit for network interfaces has been reached. For more information, see Lambda quotas.
-
ENINotReadyException–Lambda couldn't invoke the Lambda function because the elastic network interface (ENI) configured for its VPC connection isn't ready yet. Wait a few moments and try the request again. For more information about VPC configuration, see Configuring a Lambda function to access resources in a VPC.
-
InvalidParameterValueException–One of the parameters in the request is not valid.
-
InvalidRequestContentException–The request body could not be parsed as JSON, or a request header is invalid. For example, the 'x-amzn-RequestId' header is not a valid UUID string.
-
InvalidRuntimeException–The runtime or runtime version specified is not supported.
-
InvalidSecurityGroupIDException–The security group ID provided in the Lambda function VPC configuration is not valid.
-
InvalidSubnetIDException–The subnet ID provided in the Lambda function VPC configuration is not valid.
-
InvalidZipFileException–Lambda could not unzip the deployment package.
-
KMSAccessDeniedException–Lambda couldn't decrypt the environment variables because KMS access was denied. Check the Lambda function's KMS permissions.
-
KMSDisabledException–Lambda couldn't decrypt the environment variables because the KMS key used is disabled. Check the Lambda function's KMS key settings.
-
KMSInvalidStateException–Lambda couldn't decrypt the environment variables because the state of the KMS key used is not valid for Decrypt. Check the function's KMS key settings.
-
KMSNotFoundException–Lambda couldn't decrypt the environment variables because the KMS key was not found. Check the function's KMS key settings.
-
ModeNotSupportedException–The Lambda function doesn't support the invocation mode requested. For example, calling
InvokewithInvocationType=RequestResponseon a function configured for asynchronous-only invocation, or vice versa. For more information about invocation types, see Invoking Lambda functions. -
NoPublishedVersionException–The function has no published versions available.
-
RecursiveInvocationException–Lambda has detected your function being invoked in a recursive loop with other Amazon Web Services resources and stopped your function's invocation.
-
RequestTooLargeException–The request payload exceeded the
Invokerequest body JSON input quota. For more information, see Lambda quotas. -
ResourceConflictException–The resource already exists, or another operation is in progress.
-
ResourceNotFoundException–The resource specified in the request does not exist.
-
ResourceNotReadyException–The function is inactive and its VPC connection is no longer available. Wait for the VPC connection to reestablish and try again.
-
S3FilesMountConnectivityException–The Lambda function couldn't make a network connection to the configured S3 Files access point.
-
S3FilesMountFailureException–The Lambda function couldn't mount the configured S3 Files access point due to a permission or configuration issue.
-
S3FilesMountTimeoutException–The Lambda function made a network connection to the configured S3 Files access point, but the mount operation timed out.
-
SerializedRequestEntityTooLargeException–The request payload exceeded the maximum allowed size for serialized request entities.
-
ServiceException–The Lambda service encountered an internal error.
-
ServiceQuotaExceededException–The request would exceed a service quota. For more information about Lambda service quotas, see Lambda quotas. To request a quota increase, see Requesting a quota increase in the Service Quotas User Guide.
-
SnapStartException–The
afterRestore()runtime hook encountered an error. For more information, check the Amazon CloudWatch logs. -
SnapStartNotReadyException–Lambda is initializing your function. You can invoke the function when the function state becomes
Active. -
SnapStartRegenerationFailureException–Lambda couldn't regenerate the SnapStart snapshot for the function. SnapStart-enabled functions periodically regenerate snapshots when their underlying runtime or dependencies change; this regeneration failed. Wait for Lambda to retry, or update the function's configuration to trigger a new snapshot. For more information, see Lambda SnapStart.
-
SnapStartTimeoutException–Lambda couldn't restore the snapshot within the timeout limit.
-
SubnetIPAddressLimitReachedException–Lambda couldn't set up VPC access for the Lambda function because one or more configured subnets has no available IP addresses.
-
TooManyRequestsException–The request throughput limit was exceeded. For more information, see Lambda quotas.
-
UnsupportedMediaTypeException–The content type of the
Invokerequest body is not JSON. -
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To invoke a Lambda function The following example invokes version 1 of a function named my-function with an empty event payload.
>>> client.invoke(durable_execution_name='myExecution', function_name='my-function', invocation_type='Event', payload='{}', qualifier='1')
To invoke a Lambda function asynchronously
The following example invokes version 1 of a function named my-function asynchronously.
>>> client.invoke(function_name='my-function', invocation_type='Event', payload='{}', qualifier='1')
Source code in docs_src/capo_lambda/_services/_lambda.py
4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 | |