Skip to content
v2.276.0

FunctionCode Class ​

Represents the function's source code.

Example ​

ts
const store = new cloudfront.KeyValueStore(this, 'KeyValueStore');
new cloudfront.Function(this, 'Function', {
  code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
  // Note that JS_2_0 must be used for Key Value Store support
  runtime: cloudfront.FunctionRuntime.JS_2_0,
  keyValueStore: store,
});
python
store = cloudfront.KeyValueStore(self, "KeyValueStore")
cloudfront.Function(self, "Function",
    code=cloudfront.FunctionCode.from_inline("function handler(event) { return event.request }"),
    # Note that JS_2_0 must be used for Key Value Store support
    runtime=cloudfront.FunctionRuntime.JS_2_0,
    key_value_store=store
)
java
KeyValueStore store = new KeyValueStore(this, "KeyValueStore");
Function.Builder.create(this, "Function")
        .code(FunctionCode.fromInline("function handler(event) { return event.request }"))
        // Note that JS_2_0 must be used for Key Value Store support
        .runtime(FunctionRuntime.JS_2_0)
        .keyValueStore(store)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var store = new KeyValueStore(this, "KeyValueStore");
new Function(this, "Function", new FunctionProps {
    Code = FunctionCode.FromInline("function handler(event) { return event.request }"),
    // Note that JS_2_0 must be used for Key Value Store support
    Runtime = FunctionRuntime.JS_2_0,
    KeyValueStore = store
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
store := cloudfront.NewKeyValueStore(this, jsii.String("KeyValueStore"))
cloudfront.NewFunction(this, jsii.String("Function"), &FunctionProps{
	Code: cloudfront.FunctionCode_FromInline(jsii.String("function handler(event) { return event.request }")),
	// Note that JS_2_0 must be used for Key Value Store support
	Runtime: cloudfront.FunctionRuntime_JS_2_0(),
	KeyValueStore: store,
})

Initializer ​

ts
new FunctionCode()
python
FunctionCode()
java
new FunctionCode()
csharp
new FunctionCode()
go
NewFunctionCode()

Methods ​

fromFile(options: FileCodeOptions): FunctionCode // chainable@staticmethod def from_file(options: FileCodeOptions) -> FunctionCodepublic static FunctionCode fromFile(FileCodeOptions options)public static FunctionCode FromFile(FileCodeOptions options)func FromFile(Options FileCodeOptions) FunctionCodestatic#
Code from external file for function.
1 parameter · returns

Parameters

  • optionsoptionsoptionsoptionsOptions — the options for the external file.

Returns: code object with contents from file.

fromInline(code: string): FunctionCode // chainable@staticmethod def from_inline(code: str) -> FunctionCodepublic static FunctionCode fromInline(String code)public static FunctionCode FromInline(string code)func FromInline(Code *string) FunctionCodestatic#
Inline code for function.
1 parameter · returns

Parameters

  • codecodecodecodeCode — The actual function code.

Returns: code object with inline code.

render(): stringdef render(self, ) -> strpublic String render()public string Render()func Render() *string#
renders the function code.