Updating functions - Amazon CloudFront

Updating functions

You can update a function at any time. The changes are made only to the version of the function that is in the DEVELOPMENT stage. You must publish the function to copy the changes from the DEVELOPMENT stage to LIVE.

You can update a function's code in the CloudFront console or with the AWS CLI.

Console
To update function code (console)
  1. Open the Functions page in the CloudFront console at https://console.aws.amazon.com/cloudfront/v4/home#/functions, and then choose the function that you want to update.

  2. Make changes:

    • You can choose the Edit button and make change the fields in the Details section.

    • You can change or remove the associated key value store. Choose the appropriate button. For more information about key value stores, see Amazon CloudFront KeyValueStore.

    • You can change the function code. Choose the Build tab, make changes, then choose Save changes to save only the changes to the code.

CLI

To update function code (CLI)

Run the command as shown in the example.

This example uses the fileb:// notation to pass in the file. It also includes line breaks to make the command more readable.

aws cloudfront update-function \ --name MaxAge \ --function-config '{"Comment":"Max Age 2 years","Runtime":"cloudfront-js-2.0","KeyValueStoreAssociations":{"Quantity":1,"Items":[{"KeyValueStoreARN":"arn:aws:cloudfront::111122223333:key-value-store/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"}]}}' \ --function-code fileb://function-max-age-v1.js \ --if-match ETVABCEXAMPLE

Notes:

  • You identify the function by both its name and its ETag (in the if-match parameter). Make sure that you use the current ETag. You can obtain it using a describe operation.

  • You must include the function-code, even if you don't want to change it.

  • Be careful with the function-config. You should pass everything that you want to keep in the configuration. Specifically, handle the key value store as follows:

    • If you want to retain the existing key value store association (if there is one), specify the name of the existing store.

    • If you want to change the association, specify the name of the new key value store.

    • If you want to remove the association, omit the KeyValueStoreAssociations parameter.

When the command is successful, you see output like the following.

ETag: ETVXYZEXAMPLE FunctionSummary: FunctionConfig: Comment: Max Age 2 years \ Runtime: cloudfront-js-2.0 \ KeyValueStoreAssociations= \ {Quantity=1, \ Items=[{KeyValueStoreARN='arn:aws:cloudfront::111122223333:key-value-store/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111'}]} \ FunctionMetadata: \ CreatedTime: '2021-04-18T20:38:56.915000+00:00' \ FunctionARN: arn:aws:cloudfront::111122223333:function/MaxAge \ LastModifiedTime: '2023-12-19T23:41:15.389000+00:00' \ Stage: DEVELOPMENT \ Name: MaxAge \ Status: UNPUBLISHED