aws-cdk-lib.aws_cloudfront.FunctionCode

class FunctionCode

LanguageType name
.NETAmazon.CDK.AWS.CloudFront.FunctionCode
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#FunctionCode
Javasoftware.amazon.awscdk.services.cloudfront.FunctionCode
Pythonaws_cdk.aws_cloudfront.FunctionCode
TypeScript (source)aws-cdk-lib » aws_cloudfront » FunctionCode

Represents the function's source code.

Example

// Add a cloudfront Function to a Distribution
const cfFunction = new cloudfront.Function(this, 'Function', {
  code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
});

declare const s3Bucket: s3.Bucket;
new cloudfront.Distribution(this, 'distro', {
  defaultBehavior: {
    origin: new origins.S3Origin(s3Bucket),
    functionAssociations: [{
      function: cfFunction,
      eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
    }],
  },
});

Initializer

new FunctionCode()

Methods

NameDescription
render()renders the function code.
static fromFile(options)Code from external file for function.
static fromInline(code)Inline code for function.

render()

public render(): string

Returns

  • string

renders the function code.


static fromFile(options)

public static fromFile(options: FileCodeOptions): FunctionCode

Parameters

  • options FileCodeOptions — the options for the external file.

Returns

  • FunctionCode

Code from external file for function.


static fromInline(code)

public static fromInline(code: string): FunctionCode

Parameters

  • code string — The actual function code.

Returns

  • FunctionCode

Inline code for function.