AWS SDK Version 4 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to CreateFunctionAsync.

Namespace: Amazon.CloudFront
Assembly: AWSSDK.CloudFront.dll
Version: 3.x.y.z

Syntax

C#
public abstract CreateFunctionResponse CreateFunction(
         CreateFunctionRequest request
)

Parameters

request
Type: Amazon.CloudFront.Model.CreateFunctionRequest

Container for the necessary parameters to execute the CreateFunction service method.

Return Value


The response from the CreateFunction service method, as returned by CloudFront.

Exceptions

ExceptionCondition
FunctionAlreadyExistsException 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.
FunctionSizeLimitExceededException The function is too large. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.
InvalidArgumentException An argument is invalid.
TooManyFunctionsException 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.
UnsupportedOperationException This operation is not supported in this Amazon Web Services Region.

Examples

Use the following command to create a function.

To create a function


var client = new AmazonCloudFrontClient();
var response = client.CreateFunction(new CreateFunctionRequest 
{
    FunctionCode = new MemoryStream(function-code.js),
    FunctionConfig = new FunctionConfig {
        Comment = "my-function-comment",
        KeyValueStoreAssociations = new KeyValueStoreAssociations {
            Items = new List<KeyValueStoreAssociation> {
                new KeyValueStoreAssociation { KeyValueStoreARN = "arn:aws:cloudfront::123456789012:key-value-store/54947df8-0e9e-4471-a2f9-9af509fb5889" }
            },
            Quantity = 1
        },
        Runtime = "cloudfront-js-2.0"
    },
    Name = "my-function-name"
});

string eTag = response.ETag;
FunctionSummary functionSummary = response.FunctionSummary;
string location = response.Location;

            

Version Information

.NET Framework:
Supported in: 4.7.2 and newer

See Also