Skip to content

create_function

create_function(
    name: ResourceName,
    target: FunctionTarget,
    request_expression: JsonataExpression,
    *,
    config_overrides: Optional[ElementalInferenceClientConfig] = None,
    response_expression: Optional[JsonataExpression] = None,
    description: Optional[FunctionDescription] = None,
    event_bridge_delivery: Optional[EventBridgeDeliveryMode] = None,
    tags: Optional[TagMap] = None,
) -> CreateFunctionResponse

Creates a function. A function analyzes a feed by building a request from the feed's media and metadata, optionally sending that request to an Amazon Bedrock model in your account, and publishing the result to the feed's metadata timeline.

A function runs only after you attach it to a feed as a function output. For more information, see Using functions in the AWS Elemental Inference User Guide.

Parameters:

  • name (ResourceName) –

    A name for this function.

  • target (FunctionTarget) –

    The destination for the request that the function builds.

  • request_expression (JsonataExpression) –

    The JSONata expression that builds the request. Elemental Inference evaluates it against the media object of the feed, which holds the media and metadata that the function asked for. Maximum length: 5,120 characters.

    When you save the function, Elemental Inference evaluates the expression against sample media and rejects it if the evaluation fails. For a Bedrock target, the result must be a JSON object; Elemental Inference doesn't check that the object is a valid request body for the model. The expression can reference at most one of media.transcript, media.contextual, and media.clip. For a passthrough target, it can't reference media.frames.

  • response_expression (Optional[JsonataExpression], default: None ) –

    The JSONata expression that selects what to store. Elemental Inference evaluates it against the result as its root: the model response for a Bedrock target, or the output of the request expression for a passthrough target. If a function has no response expression, Elemental Inference stores the entire result. Maximum length: 5,120 characters.

    When you save the function, Elemental Inference checks that the expression is valid JSONata. For a passthrough target, it also evaluates the request and response expressions together against sample media, and rejects them if they produce no value.

  • description (Optional[FunctionDescription], default: None ) –

    The description of the function. Maximum length: 1,024 characters.

  • event_bridge_delivery (Optional[EventBridgeDeliveryMode], default: None ) –

    Specifies whether Elemental Inference also sends this function's results to Amazon EventBridge. Elemental Inference sends a result only when the result is a JSON object with a top-level eventBridge field set to true. It sends the result, unchanged, as a Function Metadata Generated event to the default event bus in your account, after the result is available from GetMetadata. If the result is larger than 64 KB, the event has resultOmitted set to true in place of the result.

    Valid values:

    • ENABLED – Elemental Inference sends each marked result as an event.

    • DISABLED (default) – Elemental Inference doesn't send events.

    For a Bedrock target, ENABLED requires a response expression, because the model response itself never has a top-level eventBridge field. A feed output that runs a function with ENABLED can't use a fixedInterval trigger shorter than 4 seconds.

  • tags (Optional[TagMap], default: None ) –

    The tags to associate with this function.

Raises:

  • AccessDeniedException –

    You do not have sufficient access to perform this action.

  • ConflictException –

    The request could not be completed due to a conflict.

  • InternalServerErrorException –

    An internal server error occurred. This is a temporary condition and the request can be retried. If the problem persists, contact AWS Support.

  • ServiceQuotaExceededException –

    The request was rejected because it would exceed one or more service quotas for your account. Review your service quotas and either delete unused resources or request a quota increase.

  • TooManyRequestException –

    The request was denied due to request throttling. Too many requests have been made within a given time period. Reduce the frequency of requests and use exponential backoff when retrying.

  • ValidationException –

    The input fails to satisfy the constraints specified by the service. Check the error message for details about which parameter or field is invalid and correct the request before retrying.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_elementalinference/_services/elemental_inference.py
def create_function(
    self,
    name: "capo_elementalinference.types.resource_name.ResourceName",
    target: "capo_elementalinference.types.function_target.FunctionTarget",
    request_expression: "capo_elementalinference.types.jsonata_expression.JsonataExpression",
    *,
    config_overrides: Optional[ElementalInferenceClientConfig] = None,
    response_expression: Optional[
        "capo_elementalinference.types.jsonata_expression.JsonataExpression"
    ] = None,
    description: Optional[
        "capo_elementalinference.types.function_description.FunctionDescription"
    ] = None,
    event_bridge_delivery: Optional[
        "capo_elementalinference.types.event_bridge_delivery_mode.EventBridgeDeliveryMode"
    ] = None,
    tags: Optional["capo_elementalinference.types.tag_map.TagMap"] = None,
) -> (
    "capo_elementalinference.types.create_function_response.CreateFunctionResponse"
):
    """<p>Creates a function. A function analyzes a feed by building a request from the feed's media and metadata, optionally sending that request to an Amazon Bedrock model in your account, and publishing the result to the feed's metadata timeline. </p> <p>A function runs only after you attach it to a feed as a function output. For more information, see <a href="https://docs.aws.amazon.com/elemental-inference/latest/userguide/functions.html">Using functions</a> in the <i>AWS Elemental Inference User Guide</i>. </p>

    Args:
        name: <p>A name for this function.</p>
        target: <p>The destination for the request that the function builds.</p>
        request_expression: <p>The JSONata expression that builds the request. Elemental Inference evaluates it against the media object of the feed, which holds the media and metadata that the function asked for. Maximum length: 5,120 characters. </p> <p>When you save the function, Elemental Inference evaluates the expression against sample media and rejects it if the evaluation fails. For a Bedrock target, the result must be a JSON object; Elemental Inference doesn't check that the object is a valid request body for the model. The expression can reference at most one of media.transcript, media.contextual, and media.clip. For a passthrough target, it can't reference media.frames. </p>
        response_expression: <p>The JSONata expression that selects what to store. Elemental Inference evaluates it against the result as its root: the model response for a Bedrock target, or the output of the request expression for a passthrough target. If a function has no response expression, Elemental Inference stores the entire result. Maximum length: 5,120 characters. </p> <p>When you save the function, Elemental Inference checks that the expression is valid JSONata. For a passthrough target, it also evaluates the request and response expressions together against sample media, and rejects them if they produce no value. </p>
        description: <p>The description of the function. Maximum length: 1,024 characters.</p>
        event_bridge_delivery: <p>Specifies whether Elemental Inference also sends this function's results to Amazon EventBridge. Elemental Inference sends a result only when the result is a JSON object with a top-level <code>eventBridge</code> field set to <code>true</code>. It sends the result, unchanged, as a Function Metadata Generated event to the default event bus in your account, after the result is available from GetMetadata. If the result is larger than 64 KB, the event has <code>resultOmitted</code> set to <code>true</code> in place of the result. </p> <p>Valid values:</p> <ul> <li> <p>ENABLED – Elemental Inference sends each marked result as an event.</p> </li> <li> <p>DISABLED (default) – Elemental Inference doesn't send events.</p> </li> </ul> <p>For a Bedrock target, ENABLED requires a response expression, because the model response itself never has a top-level <code>eventBridge</code> field. A feed output that runs a function with ENABLED can't use a fixedInterval trigger shorter than 4 seconds. </p>
        tags: <p>The tags to associate with this function.</p>

    Raises:
        capo_elementalinference.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
        capo_elementalinference.errors.conflict_exception.ConflictException: <p>The request could not be completed due to a conflict.</p>
        capo_elementalinference.errors.internal_server_error_exception.InternalServerErrorException: <p>An internal server error occurred. This is a temporary condition and the request can be retried. If the problem persists, contact AWS Support. </p>
        capo_elementalinference.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request was rejected because it would exceed one or more service quotas for your account. Review your service quotas and either delete unused resources or request a quota increase. </p>
        capo_elementalinference.errors.too_many_request_exception.TooManyRequestException: <p>The request was denied due to request throttling. Too many requests have been made within a given time period. Reduce the frequency of requests and use exponential backoff when retrying. </p>
        capo_elementalinference.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by the service. Check the error message for details about which parameter or field is invalid and correct the request before retrying. </p>
        capo_elementalinference.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_elementalinference.types.create_function_request.CreateFunctionRequest]",
    ) -> OperationResponse[
        "capo_elementalinference.types.create_function_response.CreateFunctionResponse"
    ]:
        import capo_elementalinference._operations.elemental_inference.create_function

        output, http_response = (
            capo_elementalinference._operations.elemental_inference.create_function.create_function(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_elementalinference.types.create_function_request.CreateFunctionRequest",
    ) -> dict[str, Any]:
        import capo_elementalinference.types.create_function_request

        return (
            capo_elementalinference.types.create_function_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_elementalinference.types.create_function_response.CreateFunctionResponse",
    ) -> dict[str, Any]:
        import capo_elementalinference.types.create_function_response

        return (
            capo_elementalinference.types.create_function_response.redact_sensitive(
                output
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateFunction",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_elementalinference.types.create_function_request.CreateFunctionRequest = {
        "name": name,
        "target": target,
        "request_expression": request_expression,
    }
    if response_expression is not None:
        input_["response_expression"] = response_expression
    if description is not None:
        input_["description"] = description
    if event_bridge_delivery is not None:
        input_["event_bridge_delivery"] = event_bridge_delivery
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output