functions
Creates, updates, deletes or gets a function resource or lists functions in a region
Overview
| Name | functions |
| Type | Resource |
| Description | Creates 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 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. |
| Id | awscc.cloudfront.functions |
Fields
- get (all properties)
- list (identifiers only)
| Name | Datatype | Description |
|---|---|---|
auto_publish | boolean | A 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_arn | string | |
function_code | string | The function code. For more information about writing a CloudFront function, see Writing function code for CloudFront Functions in the Amazon CloudFront Developer Guide. |
function_config | object | Contains configuration information about a CloudFront function. |
function_metadata | object | Contains metadata about a CloudFront function. |
name | string | A name to identify the function. |
stage | string | |
region | string | AWS region. |
| Name | Datatype | Description |
|---|---|---|
function_arn | string | |
region | string | AWS region. |
For more information, see AWS::CloudFront::Function.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | functions | INSERT | Name, FunctionConfig, FunctionCode, region |
delete_resource | functions | DELETE | Identifier, region |
update_resource | functions | UPDATE | Identifier, PatchDocument, region |
list_resources | functions_list_only | SELECT | region |
get_resource | functions | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
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 }}';
Lists all functions in a region.
SELECT
region,
function_arn
FROM awscc.cloudfront.functions_list_only
WHERE
region = 'us-east-1';
INSERT example
Use the following StackQL query and manifest file to create a new function resource, using stack-deploy.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO awscc.cloudfront.functions (
FunctionCode,
FunctionConfig,
Name,
region
)
SELECT
'{{ function_code }}',
'{{ function_config }}',
'{{ name }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
/*+ create */
INSERT INTO awscc.cloudfront.functions (
AutoPublish,
FunctionCode,
FunctionConfig,
FunctionMetadata,
Name,
region
)
SELECT
'{{ auto_publish }}',
'{{ function_code }}',
'{{ function_config }}',
'{{ function_metadata }}',
'{{ name }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: function
props:
- name: auto_publish
value: '{{ auto_publish }}'
- name: function_code
value: '{{ function_code }}'
- name: function_config
value:
comment: '{{ comment }}'
runtime: '{{ runtime }}'
key_value_store_associations:
- key_value_store_arn: '{{ key_value_store_arn }}'
- name: function_metadata
value:
function_arn: '{{ function_arn }}'
- name: name
value: '{{ name }}'
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 }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
DELETE example
/*+ delete */
DELETE FROM awscc.cloudfront.functions
WHERE
Identifier = '{{ function_arn }}' AND
region = 'us-east-1'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
Additional Parameters
Mutable resources in the Cloud Control provider support additional optional parameters which can be supplied with INSERT, UPDATE, or DELETE operations. These include:
| Parameter | Description |
|---|---|
ClientToken | A unique identifier to ensure the idempotency of the resource request.This allows the provider to accurately distinguish between retries and new requests.A client token is valid for 36 hours once used. After that, a resource request with the same client token is treated as a new request. If you do not specify a client token, one is generated for inclusion in the request. |
RoleArn | The ARN of the IAM role used to perform this resource operation.The role specified must have the permissions required for this operation.If you do not specify a role, a temporary session is created using your AWS user credentials. |
TypeVersionId | For private resource types, the type version to use in this resource operation.If you do not specify a resource version, the default version is used. |
Permissions
To operate on the functions resource, the following permissions are required:
- Create
- Delete
- List
- Read
- Update
cloudfront:CreateFunction,
cloudfront:PublishFunction,
cloudfront:DescribeFunction
cloudfront:DeleteFunction,
cloudfront:DescribeFunction
cloudfront:ListFunctions
cloudfront:DescribeFunction,
cloudfront:GetFunction
cloudfront:UpdateFunction,
cloudfront:PublishFunction,
cloudfront:DescribeFunction