Skip to main content

functions

Creates, updates, deletes or gets a function resource or lists functions in a region

Overview

Namefunctions
TypeResource
DescriptionCreates a CF 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, and the function’s stage.
By default, when you create a function, it’s in the ``DEVELOPMENT`` stage. In this stage, you can [test the function](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/test-function.html) in the CF console (or with ``TestFunction`` in the CF API).
When you’re ready to use your function with a CF distribution, publish the function to the ``LIVE`` stage. You can do this in the CF console, with ``PublishFunction`` in the CF API, or by updating the ``AWS::CloudFront::Function`` resource with the ``AutoPublish`` property set to ``true``. When the function is published to the ``LIVE`` stage, you can attach it to a distribution’s cache behavior, using the function’s ARN.
To automatically publish the function to the ``LIVE`` stage when it’s created, set the ``AutoPublish`` property to ``true``.
Idawscc.cloudfront.functions

Fields

NameDatatypeDescription
auto_publishbooleanA flag that determines whether to automatically publish the function to the ``LIVE`` stage when it’s created. To automatically publish to the ``LIVE`` stage, set this property to ``true``.
function_arnstring
function_codestringThe function code. For more information about writing a CloudFront function, see [Writing function code for CloudFront Functions](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/writing-function-code.html) in the *Amazon CloudFront Developer Guide*.
function_configobjectContains configuration information about a CloudFront function.
function_metadataobjectContains metadata about a CloudFront function.
namestringA name to identify the function.
stagestring
regionstringAWS region.

For more information, see AWS::CloudFront::Function.

Methods

NameResourceAccessible byRequired Params
create_resourcefunctionsINSERTName, FunctionConfig, FunctionCode, region
delete_resourcefunctionsDELETEIdentifier, region
update_resourcefunctionsUPDATEIdentifier, PatchDocument, region
list_resourcesfunctions_list_onlySELECTregion
get_resourcefunctionsSELECTIdentifier, region

SELECT examples

Gets all properties from an individual function.

SELECT
region,
auto_publish,
function_arn,
function_code,
function_config,
function_metadata,
name,
stage
FROM awscc.cloudfront.functions
WHERE
region = 'us-east-1' AND
Identifier = '{{ function_arn }}';

INSERT example

Use the following StackQL query and manifest file to create a new function resource, using stack-deploy.

/*+ create */
INSERT INTO awscc.cloudfront.functions (
FunctionCode,
FunctionConfig,
Name,
region
)
SELECT
'{{ function_code }}',
'{{ function_config }}',
'{{ name }}',
'{{ region }}';

UPDATE example

Use the following StackQL query and manifest file to update a function resource, using stack-deploy.

/*+ update */
UPDATE awscc.cloudfront.functions
SET PatchDocument = string('{{ {
"AutoPublish": auto_publish,
"FunctionCode": function_code,
"FunctionConfig": function_config
} | generate_patch_document }}')
WHERE
region = '{{ region }}' AND
Identifier = '{{ function_arn }}';

DELETE example

/*+ delete */
DELETE FROM awscc.cloudfront.functions
WHERE
Identifier = '{{ function_arn }}' AND
region = 'us-east-1';

Permissions

To operate on the functions resource, the following permissions are required:

cloudfront:CreateFunction,
cloudfront:PublishFunction,
cloudfront:DescribeFunction