Skip to content

update_function async

update_function(
    name: FunctionName,
    if_match: string,
    function_config: FunctionConfig,
    function_code: FunctionBlob,
    *,
    config_overrides: Optional[AsyncCloudFrontClientConfig] = None,
) -> UpdateFunctionResult

Updates a CloudFront function.

You can update a function's code or the comment that describes the function. You cannot update a function's name.

To update a function, you provide the function's name and version (ETag value) along with the updated function code. To get the name and version, you can use ListFunctions and DescribeFunction.

Parameters:

  • name (FunctionName) –

    The name of the function that you are updating.

  • if_match (string) –

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

  • function_config (FunctionConfig) –

    Configuration information about the function.

  • function_code (FunctionBlob) –

    The function code. For more information about writing a CloudFront function, see Writing function code for CloudFront Functions in the Amazon CloudFront Developer Guide.

Raises:

Examples:

To update a function Use the following command to update a function.

>>> await client.update_function(name='my-function-name', function_config={'Comment': 'my-changed-comment', 'Runtime': 'cloudfront-js-2.0', 'KeyValueStoreAssociations': {'Quantity': 1, 'Items': [{'KeyValueStoreARN': 'arn:aws:cloudfront::123456789012:key-value-store/54947df8-0e9e-4471-a2f9-9af509fb5889'}]}}, function_code='function-code-changed.js', if_match='ETVPDKIKX0DER')
Source code in docs_src/capo_cloudfront/_services/async_cloud_front.py
async def update_function(
    self,
    name: "capo_cloudfront.types.function_name.FunctionName",
    if_match: "capo_cloudfront.types.string.string",
    function_config: "capo_cloudfront.types.function_config.FunctionConfig",
    function_code: "capo_cloudfront.types.function_blob.FunctionBlob",
    *,
    config_overrides: Optional[AsyncCloudFrontClientConfig] = None,
) -> "capo_cloudfront.types.update_function_result.UpdateFunctionResult":
    """<p>Updates a CloudFront function.</p> <p>You can update a function's code or the comment that describes the function. You cannot update a function's name.</p> <p>To update a function, you provide the function's name and version (<code>ETag</code> value) along with the updated function code. To get the name and version, you can use <code>ListFunctions</code> and <code>DescribeFunction</code>.</p>

    Args:
        name: <p>The name of the function that you are updating.</p>
        if_match: <p>The current version (<code>ETag</code> value) of the function that you are updating, which you can get using <code>DescribeFunction</code>.</p>
        function_config: <p>Configuration information about the function.</p>
        function_code: <p>The function code. For more information about writing a CloudFront function, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/writing-function-code.html">Writing function code for CloudFront Functions</a> in the <i>Amazon CloudFront Developer Guide</i>.</p>

    Raises:
        capo_cloudfront.errors.function_size_limit_exceeded.FunctionSizeLimitExceeded: <p>The function is too large. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        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.

    Examples:
        To update a function
        Use the following command to update a function.

        >>> await client.update_function(name='my-function-name', function_config={'Comment': 'my-changed-comment', 'Runtime': 'cloudfront-js-2.0', 'KeyValueStoreAssociations': {'Quantity': 1, 'Items': [{'KeyValueStoreARN': 'arn:aws:cloudfront::123456789012:key-value-store/54947df8-0e9e-4471-a2f9-9af509fb5889'}]}}, function_code='function-code-changed.js', if_match='ETVPDKIKX0DER')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cloudfront.types.update_function_request.UpdateFunctionRequest]",
    ) -> AsyncOperationResponse[
        "capo_cloudfront.types.update_function_result.UpdateFunctionResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.update_function

        (
            output,
            http_response,
        ) = await capo_cloudfront._operations.cloudfront2020_05_31.update_function.async_update_function(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cloudfront.types.update_function_request.UpdateFunctionRequest",
    ) -> dict[str, Any]:
        import capo_cloudfront.types.update_function_request

        return capo_cloudfront.types.update_function_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("UpdateFunction", redact_input=_redact_input),
    )
    input_: capo_cloudfront.types.update_function_request.UpdateFunctionRequest = {
        "name": name,
        "if_match": if_match,
        "function_config": function_config,
        "function_code": function_code,
    }

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output