class FunctionCode
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.CloudFront.FunctionCode |
Java | software.amazon.awscdk.services.cloudfront.FunctionCode |
Python | aws_cdk.aws_cloudfront.FunctionCode |
TypeScript (source) | @aws-cdk/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
Name | Description |
---|---|
render() | renders the function code. |
static from | Code from external file for function. |
static from | Inline code for function. |
render()
public render(): string
Returns
string
renders the function code.
File(options)
static frompublic static fromFile(options: FileCodeOptions): FunctionCode
Parameters
- options
File
— the options for the external file.Code Options
Returns
Code from external file for function.
Inline(code)
static frompublic static fromInline(code: string): FunctionCode
Parameters
- code
string
— The actual function code.
Returns
Inline code for function.