:doc:`AppSync <../../appsync>` / Client / create_function

***************
create_function
***************



.. py:method:: AppSync.Client.create_function(**kwargs)

  

  Creates a ``Function`` object.

   

  A function is a reusable entity. You can use multiple functions to compose the resolver logic.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/appsync-2017-07-25/CreateFunction>`_  


  **Request Syntax**
  ::

    response = client.create_function(
        apiId='string',
        name='string',
        description='string',
        dataSourceName='string',
        requestMappingTemplate='string',
        responseMappingTemplate='string',
        functionVersion='string',
        syncConfig={
            'conflictHandler': 'OPTIMISTIC_CONCURRENCY'|'LAMBDA'|'AUTOMERGE'|'NONE',
            'conflictDetection': 'VERSION'|'NONE',
            'lambdaConflictHandlerConfig': {
                'lambdaConflictHandlerArn': 'string'
            }
        },
        maxBatchSize=123,
        runtime={
            'name': 'APPSYNC_JS',
            'runtimeVersion': 'string'
        },
        code='string'
    )
    
  :type apiId: string
  :param apiId: **[REQUIRED]** 

    The GraphQL API ID.

    

  
  :type name: string
  :param name: **[REQUIRED]** 

    The ``Function`` name. The function name does not have to be unique.

    

  
  :type description: string
  :param description: 

    The ``Function`` description.

    

  
  :type dataSourceName: string
  :param dataSourceName: **[REQUIRED]** 

    The ``Function`` ``DataSource`` name.

    

  
  :type requestMappingTemplate: string
  :param requestMappingTemplate: 

    The ``Function`` request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

    

  
  :type responseMappingTemplate: string
  :param responseMappingTemplate: 

    The ``Function`` response mapping template.

    

  
  :type functionVersion: string
  :param functionVersion: 

    The ``version`` of the request mapping template. Currently, the supported value is 2018-05-29. Note that when using VTL and mapping templates, the ``functionVersion`` is required.

    

  
  :type syncConfig: dict
  :param syncConfig: 

    Describes a Sync configuration for a resolver.

     

    Specifies which Conflict Detection strategy and Resolution strategy to use when the resolver is invoked.

    

  
    - **conflictHandler** *(string) --* 

      The Conflict Resolution strategy to perform in the event of a conflict.

       

      
      * **OPTIMISTIC_CONCURRENCY**: Resolve conflicts by rejecting mutations when versions don't match the latest version at the server.
       
      * **AUTOMERGE**: Resolve conflicts with the Automerge conflict resolution strategy.
       
      * **LAMBDA**: Resolve conflicts with an Lambda function supplied in the ``LambdaConflictHandlerConfig``.
      

      

    
    - **conflictDetection** *(string) --* 

      The Conflict Detection strategy to use.

       

      
      * **VERSION**: Detect conflicts based on object versions for this resolver.
       
      * **NONE**: Do not detect conflicts when invoking this resolver.
      

      

    
    - **lambdaConflictHandlerConfig** *(dict) --* 

      The ``LambdaConflictHandlerConfig`` when configuring ``LAMBDA`` as the Conflict Handler.

      

    
      - **lambdaConflictHandlerArn** *(string) --* 

        The Amazon Resource Name (ARN) for the Lambda function to use as the Conflict Handler.

        

      
    
  
  :type maxBatchSize: integer
  :param maxBatchSize: 

    The maximum batching size for a resolver.

    

  
  :type runtime: dict
  :param runtime: 

    Describes a runtime used by an Amazon Web Services AppSync pipeline resolver or Amazon Web Services AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified.

    

  
    - **name** *(string) --* **[REQUIRED]** 

      The ``name`` of the runtime to use. Currently, the only allowed value is ``APPSYNC_JS``.

      

    
    - **runtimeVersion** *(string) --* **[REQUIRED]** 

      The ``version`` of the runtime to use. Currently, the only allowed version is ``1.0.0``.

      

    
  
  :type code: string
  :param code: 

    The ``function`` code that contains the request and response functions. When code is used, the ``runtime`` is required. The ``runtime`` value must be ``APPSYNC_JS``.

    

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

    
    ::

      {
          'functionConfiguration': {
              'functionId': 'string',
              'functionArn': 'string',
              'name': 'string',
              'description': 'string',
              'dataSourceName': 'string',
              'requestMappingTemplate': 'string',
              'responseMappingTemplate': 'string',
              'functionVersion': 'string',
              'syncConfig': {
                  'conflictHandler': 'OPTIMISTIC_CONCURRENCY'|'LAMBDA'|'AUTOMERGE'|'NONE',
                  'conflictDetection': 'VERSION'|'NONE',
                  'lambdaConflictHandlerConfig': {
                      'lambdaConflictHandlerArn': 'string'
                  }
              },
              'maxBatchSize': 123,
              'runtime': {
                  'name': 'APPSYNC_JS',
                  'runtimeVersion': 'string'
              },
              'code': 'string'
          }
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **functionConfiguration** *(dict) --* 

        The ``Function`` object.

        
        

        - **functionId** *(string) --* 

          A unique ID representing the ``Function`` object.

          
        

        - **functionArn** *(string) --* 

          The Amazon Resource Name (ARN) of the ``Function`` object.

          
        

        - **name** *(string) --* 

          The name of the ``Function`` object.

          
        

        - **description** *(string) --* 

          The ``Function`` description.

          
        

        - **dataSourceName** *(string) --* 

          The name of the ``DataSource``.

          
        

        - **requestMappingTemplate** *(string) --* 

          The ``Function`` request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

          
        

        - **responseMappingTemplate** *(string) --* 

          The ``Function`` response mapping template.

          
        

        - **functionVersion** *(string) --* 

          The version of the request mapping template. Currently, only the 2018-05-29 version of the template is supported.

          
        

        - **syncConfig** *(dict) --* 

          Describes a Sync configuration for a resolver.

           

          Specifies which Conflict Detection strategy and Resolution strategy to use when the resolver is invoked.

          
          

          - **conflictHandler** *(string) --* 

            The Conflict Resolution strategy to perform in the event of a conflict.

             

            
            * **OPTIMISTIC_CONCURRENCY**: Resolve conflicts by rejecting mutations when versions don't match the latest version at the server.
             
            * **AUTOMERGE**: Resolve conflicts with the Automerge conflict resolution strategy.
             
            * **LAMBDA**: Resolve conflicts with an Lambda function supplied in the ``LambdaConflictHandlerConfig``.
            

            
          

          - **conflictDetection** *(string) --* 

            The Conflict Detection strategy to use.

             

            
            * **VERSION**: Detect conflicts based on object versions for this resolver.
             
            * **NONE**: Do not detect conflicts when invoking this resolver.
            

            
          

          - **lambdaConflictHandlerConfig** *(dict) --* 

            The ``LambdaConflictHandlerConfig`` when configuring ``LAMBDA`` as the Conflict Handler.

            
            

            - **lambdaConflictHandlerArn** *(string) --* 

              The Amazon Resource Name (ARN) for the Lambda function to use as the Conflict Handler.

              
        
      
        

        - **maxBatchSize** *(integer) --* 

          The maximum batching size for a resolver.

          
        

        - **runtime** *(dict) --* 

          Describes a runtime used by an Amazon Web Services AppSync pipeline resolver or Amazon Web Services AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified.

          
          

          - **name** *(string) --* 

            The ``name`` of the runtime to use. Currently, the only allowed value is ``APPSYNC_JS``.

            
          

          - **runtimeVersion** *(string) --* 

            The ``version`` of the runtime to use. Currently, the only allowed version is ``1.0.0``.

            
      
        

        - **code** *(string) --* 

          The ``function`` code that contains the request and response functions. When code is used, the ``runtime`` is required. The ``runtime`` value must be ``APPSYNC_JS``.

          
    
  
  **Exceptions**
  
  *   :py:class:`AppSync.Client.exceptions.ConcurrentModificationException`

  
  *   :py:class:`AppSync.Client.exceptions.NotFoundException`

  
  *   :py:class:`AppSync.Client.exceptions.UnauthorizedException`

  
  *   :py:class:`AppSync.Client.exceptions.InternalFailureException`

  
  *   :py:class:`AppSync.Client.exceptions.BadRequestException`

  