FunctionCode

class aws_cdk.aws_cloudfront.FunctionCode

Bases: object

Represents the function’s source code.

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
        )]
    )
)

Methods

abstract render()

renders the function code.

Return type:

str

Static Methods

classmethod from_file(*, file_path)

Code from external file for function.

Parameters:

file_path (str) – The path of the file to read the code from.

Return type:

FunctionCode

Returns:

code object with contents from file.

classmethod from_inline(code)

Inline code for function.

Parameters:

code (str) – The actual function code.

Return type:

FunctionCode

Returns:

code object with inline code.