:doc:`Lambda <../../lambda>` / Client / put_function_event_invoke_config

********************************
put_function_event_invoke_config
********************************



.. py:method:: Lambda.Client.put_function_event_invoke_config(**kwargs)

  

  Configures options for `asynchronous invocation <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html>`__ on a function, version, or alias. If a configuration already exists for a function, version, or alias, this operation overwrites it. If you exclude any settings, they are removed. To set one option without affecting existing settings for other options, use  UpdateFunctionEventInvokeConfig.

   

  By default, Lambda retries an asynchronous invocation twice if the function returns an error. It retains events in a queue for up to six hours. When an event fails all processing attempts or stays in the asynchronous invocation queue for too long, Lambda discards it. To retain discarded events, configure a dead-letter queue with  UpdateFunctionConfiguration.

   

  To send an invocation record to a queue, topic, S3 bucket, function, or event bus, specify a `destination <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-async-destinations>`__. You can configure separate destinations for successful invocations (on-success) and events that fail all processing attempts (on-failure). You can configure destinations in addition to or instead of a dead-letter queue.

   

  .. note::

    

    S3 buckets are supported only for on-failure destinations. To retain records of successful invocations, use another destination type.

    

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/lambda-2015-03-31/PutFunctionEventInvokeConfig>`_  


  **Request Syntax**
  ::

    response = client.put_function_event_invoke_config(
        FunctionName='string',
        Qualifier='string',
        MaximumRetryAttempts=123,
        MaximumEventAgeInSeconds=123,
        DestinationConfig={
            'OnSuccess': {
                'Destination': 'string'
            },
            'OnFailure': {
                'Destination': 'string'
            }
        }
    )
    
  :type FunctionName: string
  :param FunctionName: **[REQUIRED]** 

    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.

    

  
  :type Qualifier: string
  :param Qualifier: 

    A version number or alias name.

    

  
  :type MaximumRetryAttempts: integer
  :param MaximumRetryAttempts: 

    The maximum number of times to retry when the function returns an error.

    

  
  :type MaximumEventAgeInSeconds: integer
  :param MaximumEventAgeInSeconds: 

    The maximum age of a request that Lambda sends to a function for processing.

    

  
  :type DestinationConfig: dict
  :param DestinationConfig: 

    A destination for events after they have been sent to a function for processing.

     

    **Destinations**

     

    
    * **Function** - The Amazon Resource Name (ARN) of a Lambda function.
     
    * **Queue** - The ARN of a standard SQS queue.
     
    * **Bucket** - The ARN of an Amazon S3 bucket.
     
    * **Topic** - The ARN of a standard SNS topic.
     
    * **Event Bus** - The ARN of an Amazon EventBridge event bus.
    

     

    .. note::

      

      S3 buckets are supported only for on-failure destinations. To retain records of successful invocations, use another destination type.

      

    

  
    - **OnSuccess** *(dict) --* 

      The destination configuration for successful invocations. Not supported in ``CreateEventSourceMapping`` or ``UpdateEventSourceMapping``.

      

    
      - **Destination** *(string) --* 

        The Amazon Resource Name (ARN) of the destination resource.

         

        .. note::

          

          Amazon SNS destinations have a message size limit of 256 KB. If the combined size of the function request and response payload exceeds the limit, Lambda will drop the payload when sending ``OnFailure`` event to the destination. For details on this behavior, refer to `Retaining records of asynchronous invocations <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html>`__.

          

        

      
    
    - **OnFailure** *(dict) --* 

      The destination configuration for failed invocations.

      

    
      - **Destination** *(string) --* 

        The Amazon Resource Name (ARN) of the destination resource.

         

        To retain records of failed invocations from `Kinesis <https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html>`__, `DynamoDB <https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html>`__, `self-managed Apache Kafka <https://docs.aws.amazon.com/lambda/latest/dg/kafka-on-failure.html>`__, or `Amazon MSK <https://docs.aws.amazon.com/lambda/latest/dg/kafka-on-failure.html>`__, you can configure an Amazon SNS topic, Amazon SQS queue, Amazon S3 bucket, or Kafka topic as the destination.

         

        .. note::

          

          Amazon SNS destinations have a message size limit of 256 KB. If the combined size of the function request and response payload exceeds the limit, Lambda will drop the payload when sending ``OnFailure`` event to the destination. For details on this behavior, refer to `Retaining records of asynchronous invocations <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html>`__.

          

         

        To retain records of failed invocations from `Kinesis <https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html>`__, `DynamoDB <https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html>`__, `self-managed Kafka <https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html#services-smaa-onfailure-destination>`__ or `Amazon MSK <https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html#services-msk-onfailure-destination>`__, you can configure an Amazon SNS topic, Amazon SQS queue, or Amazon S3 bucket as the destination.

        

      
    
  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'LastModified': datetime(2015, 1, 1),
          'FunctionArn': 'string',
          'MaximumRetryAttempts': 123,
          'MaximumEventAgeInSeconds': 123,
          'DestinationConfig': {
              'OnSuccess': {
                  'Destination': 'string'
              },
              'OnFailure': {
                  'Destination': 'string'
              }
          }
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **LastModified** *(datetime) --* 

        The date and time that the configuration was last updated.

        
      

      - **FunctionArn** *(string) --* 

        The Amazon Resource Name (ARN) of the function.

        
      

      - **MaximumRetryAttempts** *(integer) --* 

        The maximum number of times to retry when the function returns an error.

        
      

      - **MaximumEventAgeInSeconds** *(integer) --* 

        The maximum age of a request that Lambda sends to a function for processing.

        
      

      - **DestinationConfig** *(dict) --* 

        A destination for events after they have been sent to a function for processing.

         

        **Destinations**

         

        
        * **Function** - The Amazon Resource Name (ARN) of a Lambda function.
         
        * **Queue** - The ARN of a standard SQS queue.
         
        * **Bucket** - The ARN of an Amazon S3 bucket.
         
        * **Topic** - The ARN of a standard SNS topic.
         
        * **Event Bus** - The ARN of an Amazon EventBridge event bus.
        

         

        .. note::

          

          S3 buckets are supported only for on-failure destinations. To retain records of successful invocations, use another destination type.

          

        
        

        - **OnSuccess** *(dict) --* 

          The destination configuration for successful invocations. Not supported in ``CreateEventSourceMapping`` or ``UpdateEventSourceMapping``.

          
          

          - **Destination** *(string) --* 

            The Amazon Resource Name (ARN) of the destination resource.

             

            .. note::

              

              Amazon SNS destinations have a message size limit of 256 KB. If the combined size of the function request and response payload exceeds the limit, Lambda will drop the payload when sending ``OnFailure`` event to the destination. For details on this behavior, refer to `Retaining records of asynchronous invocations <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html>`__.

              

            
      
        

        - **OnFailure** *(dict) --* 

          The destination configuration for failed invocations.

          
          

          - **Destination** *(string) --* 

            The Amazon Resource Name (ARN) of the destination resource.

             

            To retain records of failed invocations from `Kinesis <https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html>`__, `DynamoDB <https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html>`__, `self-managed Apache Kafka <https://docs.aws.amazon.com/lambda/latest/dg/kafka-on-failure.html>`__, or `Amazon MSK <https://docs.aws.amazon.com/lambda/latest/dg/kafka-on-failure.html>`__, you can configure an Amazon SNS topic, Amazon SQS queue, Amazon S3 bucket, or Kafka topic as the destination.

             

            .. note::

              

              Amazon SNS destinations have a message size limit of 256 KB. If the combined size of the function request and response payload exceeds the limit, Lambda will drop the payload when sending ``OnFailure`` event to the destination. For details on this behavior, refer to `Retaining records of asynchronous invocations <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html>`__.

              

             

            To retain records of failed invocations from `Kinesis <https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html>`__, `DynamoDB <https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html>`__, `self-managed Kafka <https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html#services-smaa-onfailure-destination>`__ or `Amazon MSK <https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html#services-msk-onfailure-destination>`__, you can configure an Amazon SNS topic, Amazon SQS queue, or Amazon S3 bucket as the destination.

            
      
    
  
  **Exceptions**
  
  *   :py:class:`Lambda.Client.exceptions.InvalidParameterValueException`

  
  *   :py:class:`Lambda.Client.exceptions.ResourceConflictException`

  
  *   :py:class:`Lambda.Client.exceptions.ServiceException`

  
  *   :py:class:`Lambda.Client.exceptions.TooManyRequestsException`

  
  *   :py:class:`Lambda.Client.exceptions.ResourceNotFoundException`

  

  **Examples**

  The following example sets a maximum event age of one hour and disables retries for the specified function.
  ::

    response = client.put_function_event_invoke_config(
        FunctionName='my-function',
        MaximumEventAgeInSeconds=3600,
        MaximumRetryAttempts=0,
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        'DestinationConfig': {
            'OnFailure': {
            },
            'OnSuccess': {
            },
        },
        'FunctionArn': 'arn:aws:lambda:us-east-2:123456789012:function:my-function:$LATEST',
        'LastModified': datetime(2016, 11, 21, 19, 49, 20, 0, 326, 0),
        'MaximumEventAgeInSeconds': 3600,
        'MaximumRetryAttempts': 0,
        'ResponseMetadata': {
            '...': '...',
        },
    }

  