AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to InvokeAsync.

Namespace: Amazon.Lambda
Assembly: AWSSDK.Lambda.dll
Version: 3.x.y.z

Syntax

C#
public virtual InvokeResponse Invoke(
         InvokeRequest request
)

Parameters

request
Type: Amazon.Lambda.Model.InvokeRequest

Container for the necessary parameters to execute the Invoke service method.

Return Value


The response from the Invoke service method, as returned by Lambda.

Exceptions

ExceptionCondition
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.
InvalidParameterValueException One of the parameters in the request is not valid.
InvalidRequestContentException The request body could not be parsed as JSON.
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.
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 Invoke request 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.
ServiceException The Lambda service encountered an internal error.
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.
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 Invoke request body is not JSON.

Examples

The following example invokes version 1 of a function named my-function with an empty event payload.

To invoke a Lambda function


var response = client.Invoke(new InvokeRequest 
{
    FunctionName = "my-function",
    Qualifier = "1"
});

MemoryStream payload = response.Payload;
int statusCode = response.StatusCode;

            

The following example invokes version 1 of a function named my-function asynchronously.

To invoke a Lambda function asynchronously


var response = client.Invoke(new InvokeRequest 
{
    FunctionName = "my-function",
    InvocationType = "Event",
    Qualifier = "1"
});

MemoryStream payload = response.Payload;
int statusCode = response.StatusCode;

            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

See Also