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. To invoke a function asynchronously, set InvocationType to Event.

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 Retry Behavior.

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, limit errors, or issues with your function's code and configuration. For example, Lambda returns TooManyRequestsException if executing 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 be disconnected 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.

Note:

For .NET Core, PCL and Unity 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 AWS Lambda was throttled by Amazon EC2 during Lambda function initialization using the execution role provided for the Lambda function.
EC2UnexpectedException AWS Lambda received an unexpected EC2 client exception while setting up for the Lambda function.
ENILimitReachedException AWS Lambda was not able to create an elastic network interface in the VPC, specified as part of Lambda function configuration, because the limit for network interfaces has been reached.
InvalidParameterValueException One of the parameters in the request is invalid.
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 invalid.
InvalidSubnetIDException The Subnet ID provided in the Lambda function VPC configuration is invalid.
InvalidZipFileException AWS Lambda could not unzip the deployment package.
KMSAccessDeniedException Lambda was unable to decrypt the environment variables because KMS access was denied. Check the Lambda function's KMS permissions.
KMSDisabledException Lambda was unable to decrypt the environment variables because the KMS key used is disabled. Check the Lambda function's KMS key settings.
KMSInvalidStateException Lambda was unable to decrypt the environment variables because the KMS key used is in an invalid state for Decrypt. Check the function's KMS key settings.
KMSNotFoundException Lambda was unable to decrypt the environment variables because the KMS key was not found. Check the function's KMS key settings.
RequestTooLargeException The request payload exceeded the Invoke request body JSON input limit. For more information, see Limits.
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 AWS Lambda service encountered an internal error.
SubnetIPAddressLimitReachedException AWS Lambda was not able to 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.
UnsupportedMediaTypeException The content type of the Invoke request body is not JSON.

Examples

This operation invokes a Lambda function

To invoke a Lambda function


var response = client.Invoke(new InvokeRequest 
{
    FunctionName = "MyFunction",
    InvocationType = "Event",
    LogType = "Tail",
    Qualifier = "1"
});

string functionError = response.FunctionError;
string logResult = response.LogResult;
MemoryStream payload = response.Payload;
int statusCode = response.StatusCode;

            

Version Information

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

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms

Unity:
Supported Versions: 4.6 and above
Supported Platforms: Android, iOS, Standalone

See Also