FunctionProps

class aws_cdk.aws_cloudfront.FunctionProps(*, code, comment=None, function_name=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 as functionName

  • function_name (Optional[str]) – A name to identify the function. Default: - generated from the id

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 }")
)
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