FunctionEventType Enum
The type of events that a CloudFront function can be invoked in response to.
Example
ts
// Add a cloudfront Function to a Distribution
const cfFunction = new cloudfront.Function(this, 'Function', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
runtime: cloudfront.FunctionRuntime.JS_2_0,
});
declare const s3Bucket: s3.Bucket;
new cloudfront.Distribution(this, 'distro', {
defaultBehavior: {
origin: new origins.S3Origin(s3Bucket),
functionAssociations: [{
function: cfFunction,
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
}],
},
});
python
# 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 }"),
runtime=cloudfront.FunctionRuntime.JS_2_0
)
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
)]
)
)
java
Bucket s3Bucket;
// Add a cloudfront Function to a Distribution
Function cfFunction = Function.Builder.create(this, "Function")
.code(FunctionCode.fromInline("function handler(event) { return event.request }"))
.runtime(FunctionRuntime.JS_2_0)
.build();
Distribution.Builder.create(this, "distro")
.defaultBehavior(BehaviorOptions.builder()
.origin(new S3Origin(s3Bucket))
.functionAssociations(List.of(FunctionAssociation.builder()
.function(cfFunction)
.eventType(FunctionEventType.VIEWER_REQUEST)
.build()))
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Bucket s3Bucket;
// Add a cloudfront Function to a Distribution
var cfFunction = new Function(this, "Function", new FunctionProps {
Code = FunctionCode.FromInline("function handler(event) { return event.request }"),
Runtime = FunctionRuntime.JS_2_0
});
new Distribution(this, "distro", new DistributionProps {
DefaultBehavior = new BehaviorOptions {
Origin = new S3Origin(s3Bucket),
FunctionAssociations = new [] { new FunctionAssociation {
Function = cfFunction,
EventType = FunctionEventType.VIEWER_REQUEST
} }
}
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var s3Bucket Bucket
// Add a cloudfront Function to a Distribution
cfFunction := cloudfront.NewFunction(this, jsii.String("Function"), &FunctionProps{
Code: cloudfront.FunctionCode_FromInline(jsii.String("function handler(event) { return event.request }")),
Runtime: cloudfront.FunctionRuntime_JS_2_0(),
})
cloudfront.NewDistribution(this, jsii.String("distro"), &DistributionProps{
DefaultBehavior: &BehaviorOptions{
Origin: origins.NewS3Origin(s3Bucket),
FunctionAssociations: []FunctionAssociation{
&FunctionAssociation{
Function: cfFunction,
EventType: cloudfront.FunctionEventType_VIEWER_REQUEST,
},
},
},
})
Members
| Member | Description |
|---|---|
VIEWER_REQUEST | The viewer-request specifies the incoming request. |
VIEWER_RESPONSE | The viewer-response specifies the outgoing response. |
Referenced by
FunctionAssociation.eventTypeevent_typeeventTypeEventTypeEventType