createFunction
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.
Samples
import aws.sdk.kotlin.services.cloudfront.model.FunctionConfig
import aws.sdk.kotlin.services.cloudfront.model.FunctionRuntime
import aws.sdk.kotlin.services.cloudfront.model.KeyValueStoreAssociation
import aws.sdk.kotlin.services.cloudfront.model.KeyValueStoreAssociations
fun main() {
//sampleStart
// Use the following command to create a function.
val resp = cloudFrontClient.createFunction {
name = "my-function-name"
functionConfig = FunctionConfig {
comment = "my-function-comment"
runtime = FunctionRuntime.fromValue("cloudfront-js-2.0")
keyValueStoreAssociations = KeyValueStoreAssociations {
quantity = 1
items = listOf<KeyValueStoreAssociation>(
KeyValueStoreAssociation {
keyValueStoreArn = "arn:aws:cloudfront::123456789012:key-value-store/54947df8-0e9e-4471-a2f9-9af509fb5889"
}
)
}
}
functionCode = "function-code.js".encodeAsByteArray()
}
//sampleEnd
}