Skip to content

create_function async

create_function(
    name: FunctionName,
    function_config: FunctionConfig,
    function_code: FunctionBlob,
    *,
    config_overrides: Optional[AsyncCloudFrontClientConfig] = None,
    tags: Optional[Tags] = None,
) -> CreateFunctionResult

Creates a CloudFront function.

To create a function, you provide the function code and some configuration information about the function. The response contains an Amazon Resource Name (ARN) that uniquely identifies the function.

When you create a function, it's in the DEVELOPMENT stage. In this stage, you can test the function with TestFunction, and update it with UpdateFunction.

When you're ready to use your function with a CloudFront distribution, use PublishFunction to copy the function from the DEVELOPMENT stage to LIVE. When it's live, you can attach the function to a distribution's cache behavior, using the function's ARN.

Parameters:

Raises:

  • FunctionAlreadyExists –

    A function with the same name already exists in this Amazon Web Services account. To create a function, you must provide a unique name. To update an existing function, use UpdateFunction.

  • FunctionSizeLimitExceeded –

    The function is too large. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • InvalidArgument –

    An argument is invalid.

  • TooManyFunctions –

    You have reached the maximum number of CloudFront functions for this Amazon Web Services account. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • UnsupportedOperation –

    This operation is not supported in this Amazon Web Services Region.

  • UnknownServiceError –

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

Examples:

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

>>> await client.create_function(name='my-function-name', function_config={'Comment': 'my-function-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.js')
Source code in docs_src/capo_cloudfront/_services/async_cloud_front.py
async def create_function(
    self,
    name: "capo_cloudfront.types.function_name.FunctionName",
    function_config: "capo_cloudfront.types.function_config.FunctionConfig",
    function_code: "capo_cloudfront.types.function_blob.FunctionBlob",
    *,
    config_overrides: Optional[AsyncCloudFrontClientConfig] = None,
    tags: Optional["capo_cloudfront.types.tags.Tags"] = None,
) -> "capo_cloudfront.types.create_function_result.CreateFunctionResult":
    """<p>Creates a CloudFront function.</p> <p>To create a function, you provide the function code and some configuration information about the function. The response contains an Amazon Resource Name (ARN) that uniquely identifies the function.</p> <p>When you create a function, it's in the <code>DEVELOPMENT</code> stage. In this stage, you can test the function with <code>TestFunction</code>, and update it with <code>UpdateFunction</code>.</p> <p>When you're ready to use your function with a CloudFront distribution, use <code>PublishFunction</code> to copy the function from the <code>DEVELOPMENT</code> stage to <code>LIVE</code>. When it's live, you can attach the function to a distribution's cache behavior, using the function's ARN.</p>

    Args:
        name: <p>A name to identify the function.</p>
        function_config: <p>Configuration information about the function, including an optional comment and the function's runtime.</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_already_exists.FunctionAlreadyExists: <p>A function with the same name already exists in this Amazon Web Services account. To create a function, you must provide a unique name. To update an existing function, use <code>UpdateFunction</code>.</p>
        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.too_many_functions.TooManyFunctions: <p>You have reached the maximum number of CloudFront functions for this Amazon Web Services account. 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.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 create a function
        Use the following command to create a function.

        >>> await client.create_function(name='my-function-name', function_config={'Comment': 'my-function-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.js')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cloudfront.types.create_function_request.CreateFunctionRequest]",
    ) -> AsyncOperationResponse[
        "capo_cloudfront.types.create_function_result.CreateFunctionResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.create_function

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

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

        return capo_cloudfront.types.create_function_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateFunction", redact_input=_redact_input),
    )
    input_: capo_cloudfront.types.create_function_request.CreateFunctionRequest = {
        "name": name,
        "function_config": function_config,
        "function_code": function_code,
    }
    if tags is not None:
        input_["tags"] = tags

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