class Function (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.CloudFront.Function |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#Function |
![]() | software.amazon.awscdk.services.cloudfront.Function |
![]() | aws_cdk.aws_cloudfront.Function |
![]() | aws-cdk-lib » aws_cloudfront » Function |
Implements
IConstruct
, IDependable
, IResource
, IFunction
A CloudFront Function.
Example
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,
});
Initializer
new Function(scope: Construct, id: string, props: FunctionProps)
Parameters
- scope
Construct
- id
string
- props
Function
Props
Construct Props
Name | Type | Description |
---|---|---|
code | Function | The source code of the function. |
auto | boolean | A flag that determines whether to automatically publish the function to the LIVE stage when it’s created. |
comment? | string | A comment to describe the function. |
function | string | A name to identify the function. |
key | IKey | The Key Value Store to associate with this function. |
runtime? | Function | The runtime environment for the function. |
code
Type:
Function
The source code of the function.
autoPublish?
Type:
boolean
(optional, default: true)
A flag that determines whether to automatically publish the function to the LIVE stage when it’s created.
comment?
Type:
string
(optional, default: same as functionName
)
A comment to describe the function.
functionName?
Type:
string
(optional, default: generated from the id
)
A name to identify the function.
keyValueStore?
Type:
IKey
(optional, default: no key value store is associated)
The Key Value Store to associate with this function.
In order to associate a Key Value Store, the runtime
must be
cloudfront-js-2.0
or newer.
runtime?
Type:
Function
(optional, default: FunctionRuntime.JS_1_0 (unless keyValueStore
is specified, then FunctionRuntime.JS_2_0
))
The runtime environment for the function.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
function | string | the ARN of the CloudFront function. |
function | string | the name of the CloudFront function. |
function | string | the runtime of the CloudFront function. |
function | string | the deployment stage of the CloudFront function. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
functionArn
Type:
string
the ARN of the CloudFront function.
functionName
Type:
string
the name of the CloudFront function.
functionRuntime
Type:
string
the runtime of the CloudFront function.
functionStage
Type:
string
the deployment stage of the CloudFront function.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Imports a function by its name and ARN. |
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromFunctionAttributes(scope, id, attrs)
public static fromFunctionAttributes(scope: Construct, id: string, attrs: FunctionAttributes): IFunction
Parameters
- scope
Construct
- id
string
- attrs
Function
Attributes
Returns
Imports a function by its name and ARN.