Skip to content

publish_function

publish_function(
    name: FunctionName,
    if_match: string,
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
) -> PublishFunctionResult

Publishes a CloudFront function by copying the function code from the DEVELOPMENT stage to LIVE. This automatically updates all cache behaviors that are using this function to use the newly published copy in the LIVE stage.

When a function is published to the LIVE stage, you can attach the function to a distribution's cache behavior, using the function's Amazon Resource Name (ARN).

To publish a function, you must provide the function's name and version (ETag value). To get these values, you can use ListFunctions and DescribeFunction.

Parameters:

  • name (FunctionName) –

    The name of the function that you are publishing.

  • if_match (string) –

    The current version (ETag value) of the function that you are publishing, which you can get using DescribeFunction.

Raises:

Source code in docs_src/capo_cloudfront/_services/cloud_front.py
def publish_function(
    self,
    name: "capo_cloudfront.types.function_name.FunctionName",
    if_match: "capo_cloudfront.types.string.string",
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
) -> "capo_cloudfront.types.publish_function_result.PublishFunctionResult":
    """<p>Publishes a CloudFront function by copying the function code from the <code>DEVELOPMENT</code> stage to <code>LIVE</code>. This automatically updates all cache behaviors that are using this function to use the newly published copy in the <code>LIVE</code> stage.</p> <p>When a function is published to the <code>LIVE</code> stage, you can attach the function to a distribution's cache behavior, using the function's Amazon Resource Name (ARN).</p> <p>To publish a function, you must provide the function's name and version (<code>ETag</code> value). To get these values, you can use <code>ListFunctions</code> and <code>DescribeFunction</code>.</p>

    Args:
        name: <p>The name of the function that you are publishing.</p>
        if_match: <p>The current version (<code>ETag</code> value) of the function that you are publishing, which you can get using <code>DescribeFunction</code>.</p>

    Raises:
        capo_cloudfront.errors.invalid_argument.InvalidArgument: <p>An argument is invalid.</p>
        capo_cloudfront.errors.invalid_if_match_version.InvalidIfMatchVersion: <p>The <code>If-Match</code> version is missing or not valid.</p>
        capo_cloudfront.errors.no_such_function_exists.NoSuchFunctionExists: <p>The function does not exist.</p>
        capo_cloudfront.errors.precondition_failed.PreconditionFailed: <p>The precondition in one or more of the request fields evaluated to <code>false</code>.</p>
        capo_cloudfront.errors.unsupported_operation.UnsupportedOperation: <p>This operation is not supported in this Amazon Web Services Region.</p>
        capo_cloudfront.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudfront.types.publish_function_request.PublishFunctionRequest]",
    ) -> OperationResponse[
        "capo_cloudfront.types.publish_function_result.PublishFunctionResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.publish_function

        output, http_response = (
            capo_cloudfront._operations.cloudfront2020_05_31.publish_function.publish_function(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PublishFunction")
    )
    input_: capo_cloudfront.types.publish_function_request.PublishFunctionRequest = {
        "name": name,
        "if_match": if_match,
    }

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