You create a function in two stages:
-
Create the function code as JavaScript. You can use the default example from the CloudFront console or write your own. For more information, see the following topics:
-
Use CloudFront to create the function and include your code. The code exists inside the function (not as a reference).
To create a function
-
Sign in to the CloudFront console at https://console.aws.amazon.com/cloudfront/v4/home#/functions
and choose the Functions page. -
Choose Create function.
-
Enter a function name that is unique within the AWS account, choose the JavaScript version, and then choose Continue. The details page for the new function appears.
Note
To use key-value pairs in the function, you must choose JavaScript runtime 2.0.
-
In the Function code section, choose the Build tab and enter your function code. The sample code that is included in the Build tab illustrates the basic syntax for the function code.
-
Choose Save changes.
-
If the function code uses key-value pairs, you must associate a key value store.
You can associate the key value store when you first create the function. Or, you can associate it later, by updating the function.
To associate a key value store now, follow these steps:
-
Go to the Associate KeyValueStore section and choose Associate existing KeyValueStore.
-
Select the key value store that contains the key-value pairs in the function, and then choose Associate KeyValueStore.
CloudFront immediately associates the store with the function. You don't need to save the function.
-
After you create the function, it's added to the DEVELOPMENT
stage. We
recommend that you test your function before you publish it. After you publish your function, the
function changes to the LIVE
stage.