FunctionProps
- class aws_cdk.aws_cloudfront.FunctionProps(*, code, comment=None, function_name=None, key_value_store=None, runtime=None)
Bases:
object
Properties for creating a CloudFront Function.
- Parameters:
code (
FunctionCode
) – The source code of the function.comment (
Optional
[str
]) – A comment to describe the function. Default: - same asfunctionName
function_name (
Optional
[str
]) – A name to identify the function. Default: - generated from theid
key_value_store (
Optional
[IKeyValueStore
]) – The Key Value Store to associate with this function. In order to associate a Key Value Store, theruntime
must becloudfront-js-2.0
or newer. Default: - no key value store is associatedruntime (
Optional
[FunctionRuntime
]) – The runtime environment for the function. Default: FunctionRuntime.JS_1_0 (unlesskeyValueStore
is specified, thenFunctionRuntime.JS_2_0
)
- ExampleMetadata:
infused
Example:
# s3_bucket: s3.Bucket # Add a cloudfront Function to a Distribution cf_function = cloudfront.Function(self, "Function", code=cloudfront.FunctionCode.from_inline("function handler(event) { return event.request }"), runtime=cloudfront.FunctionRuntime.JS_2_0 ) cloudfront.Distribution(self, "distro", default_behavior=cloudfront.BehaviorOptions( origin=origins.S3Origin(s3_bucket), function_associations=[cloudfront.FunctionAssociation( function=cf_function, event_type=cloudfront.FunctionEventType.VIEWER_REQUEST )] ) )
Attributes
- code
The source code of the function.
- comment
A comment to describe the function.
- Default:
same as
functionName
- function_name
A name to identify the function.
- Default:
generated from the
id
- key_value_store
The Key Value Store to associate with this function.
In order to associate a Key Value Store, the
runtime
must becloudfront-js-2.0
or newer.- Default:
no key value store is associated
- runtime
The runtime environment for the function.
- Default:
FunctionRuntime.JS_1_0 (unless
keyValueStore
is specified, thenFunctionRuntime.JS_2_0
)