class EdgeFunction (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.CloudFront.experimental.EdgeFunction |
![]() | software.amazon.awscdk.services.cloudfront.experimental.EdgeFunction |
![]() | aws_cdk.aws_cloudfront.experimental.EdgeFunction |
![]() | @aws-cdk/aws-cloudfront » experimental » EdgeFunction |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IVersion
, IConnectable
, IGrantable
, IFunction
A Lambda@Edge function.
Convenience resource for requesting a Lambda function in the 'us-east-1' region for use with Lambda@Edge. Implements several restrictions enforced by Lambda@Edge.
Note that this construct requires that the 'us-east-1' region has been bootstrapped. See https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html or 'cdk bootstrap --help' for options.
Example
// A Lambda@Edge function added to default behavior of a Distribution
// and triggered on every request
const myFunc = new cloudfront.experimental.EdgeFunction(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
});
declare const myBucket: s3.Bucket;
new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: {
origin: new origins.S3Origin(myBucket),
edgeLambdas: [
{
functionVersion: myFunc.currentVersion,
eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
}
],
},
});
Initializer
new EdgeFunction(scope: Construct, id: string, props: EdgeFunctionProps)
Parameters
- scope
Construct
- id
string
- props
Edge
Function Props
Construct Props
Name | Type | Description |
---|---|---|
code | Code | The source code of your Lambda function. |
handler | string | The name of the method within your code that Lambda calls to execute your function. |
runtime | Runtime | The runtime environment for the Lambda function that you are uploading. |
allow | boolean | Whether to allow the Lambda to send all network traffic. |
allow | boolean | Lambda Functions in a public subnet can NOT access the internet. |
architecture? | Architecture | The system architectures compatible with this lambda function. |
architectures? | Architecture [] | DEPRECATED. |
code | ICode | Code signing config associated with this function. |
current | Version | Options for the lambda.Version resource automatically created by the fn.currentVersion method. |
dead | IQueue | The SQS queue to use if DLQ is enabled. |
dead | boolean | Enabled DLQ. |
dead | ITopic | The SNS topic to use as a DLQ. |
description? | string | A description of the function. |
environment? | { [string]: string } | Key-value pairs that Lambda caches and makes available for your Lambda functions. |
environment | IKey | The AWS KMS key that's used to encrypt your function's environment variables. |
ephemeral | Size | The size of the function’s /tmp directory in MiB. |
events? | IEvent [] | Event sources for this function. |
filesystem? | File | The filesystem configuration for the lambda function. |
function | string | A name for the function. |
initial | Policy [] | Initial policy statements to add to the created Lambda Role. |
insights | Lambda | Specify the version of CloudWatch Lambda insights to use for monitoring. |
layers? | ILayer [] | A list of layers to add to the function's execution environment. |
log | Retention | The number of days log events are kept in CloudWatch Logs. |
log | Log | When log retention is specified, a custom resource attempts to create the CloudWatch log group. |
log | IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. |
max | Duration | The maximum age of a request that Lambda sends to a function for processing. |
memory | number | The amount of memory, in MB, that is allocated to your Lambda function. |
on | IDestination | The destination for failed invocations. |
on | IDestination | The destination for successful invocations. |
profiling? | boolean | Enable profiling. |
profiling | IProfiling | Profiling Group. |
reserved | number | The maximum of concurrent executions you want to reserve for the function. |
retry | number | The maximum number of times to retry when the function returns an error. |
role? | IRole | Lambda execution role. |
security | ISecurity | What security group to associate with the Lambda's network interfaces. This property is being deprecated, consider using securityGroups instead. |
security | ISecurity [] | The list of security groups to associate with the Lambda's network interfaces. |
stack | string | The stack ID of Lambda@Edge function. |
timeout? | Duration | The function execution time (in seconds) after which Lambda terminates the function. |
tracing? | Tracing | Enable AWS X-Ray Tracing for Lambda Function. |
vpc? | IVpc | VPC network to place Lambda network interfaces. |
vpc | Subnet | Where to place the network interfaces within the VPC. |
code
Type:
Code
The source code of your Lambda function.
You can point to a file in an Amazon Simple Storage Service (Amazon S3) bucket or specify your source code as inline text.
handler
Type:
string
The name of the method within your code that Lambda calls to execute your function.
The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-features.html#gettingstarted-features-programmingmodel.
Use Handler.FROM_IMAGE
when defining a function from a Docker image.
NOTE: If you specify your source code as inline text by specifying the ZipFile property within the Code property, specify index.function_name as the handler.
runtime
Type:
Runtime
The runtime environment for the Lambda function that you are uploading.
For valid values, see the Runtime property in the AWS Lambda Developer Guide.
Use Runtime.FROM_IMAGE
when when defining a function from a Docker image.
allowAllOutbound?
Type:
boolean
(optional, default: true)
Whether to allow the Lambda to send all network traffic.
If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets.
allowPublicSubnet?
Type:
boolean
(optional, default: false)
Lambda Functions in a public subnet can NOT access the internet.
Use this property to acknowledge this limitation and still place the function in a public subnet.
architecture?
Type:
Architecture
(optional, default: Architecture.X86_64)
The system architectures compatible with this lambda function.
architectures?
⚠️ Deprecated: use architecture
Type:
Architecture
[]
(optional, default: [Architecture.X86_64])
DEPRECATED.
codeSigningConfig?
Type:
ICode
(optional, default: Not Sign the Code)
Code signing config associated with this function.
currentVersionOptions?
Type:
Version
(optional, default: default options as described in VersionOptions
)
Options for the lambda.Version
resource automatically created by the fn.currentVersion
method.
deadLetterQueue?
Type:
IQueue
(optional, default: SQS queue with 14 day retention period if deadLetterQueueEnabled
is true
)
The SQS queue to use if DLQ is enabled.
If SNS topic is desired, specify deadLetterTopic
property instead.
deadLetterQueueEnabled?
Type:
boolean
(optional, default: false unless deadLetterQueue
is set, which implies DLQ is enabled.)
Enabled DLQ.
If deadLetterQueue
is undefined,
an SQS queue with default options will be defined for your Function.
deadLetterTopic?
Type:
ITopic
(optional, default: no SNS topic)
The SNS topic to use as a DLQ.
Note that if deadLetterQueueEnabled
is set to true
, an SQS queue will be created
rather than an SNS topic. Using an SNS topic as a DLQ requires this property to be set explicitly.
description?
Type:
string
(optional, default: No description.)
A description of the function.
environment?
Type:
{ [string]: string }
(optional, default: No environment variables.)
Key-value pairs that Lambda caches and makes available for your Lambda functions.
Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.
environmentEncryption?
Type:
IKey
(optional, default: AWS Lambda creates and uses an AWS managed customer master key (CMK).)
The AWS KMS key that's used to encrypt your function's environment variables.
ephemeralStorageSize?
Type:
Size
(optional, default: 512 MiB)
The size of the function’s /tmp directory in MiB.
events?
Type:
IEvent
[]
(optional, default: No event sources.)
Event sources for this function.
You can also add event sources using addEventSource
.
filesystem?
Type:
File
(optional, default: will not mount any filesystem)
The filesystem configuration for the lambda function.
functionName?
Type:
string
(optional, default: AWS CloudFormation generates a unique physical ID and uses that
ID for the function's name. For more information, see Name Type.)
A name for the function.
initialPolicy?
Type:
Policy
[]
(optional, default: No policy statements are added to the created Lambda role.)
Initial policy statements to add to the created Lambda Role.
You can call addToRolePolicy
to the created lambda to add statements post creation.
insightsVersion?
Type:
Lambda
(optional, default: No Lambda Insights)
Specify the version of CloudWatch Lambda insights to use for monitoring.
layers?
Type:
ILayer
[]
(optional, default: No layers.)
A list of layers to add to the function's execution environment.
You can configure your Lambda function to pull in additional code during initialization in the form of layers. Layers are packages of libraries or other dependencies that can be used by multiple functions.
logRetention?
Type:
Retention
(optional, default: logs.RetentionDays.INFINITE)
The number of days log events are kept in CloudWatch Logs.
When updating
this property, unsetting it doesn't remove the log retention policy. To
remove the retention policy, set the value to INFINITE
.
logRetentionRetryOptions?
Type:
Log
(optional, default: Default AWS SDK retry options.)
When log retention is specified, a custom resource attempts to create the CloudWatch log group.
These options control the retry policy when interacting with CloudWatch APIs.
logRetentionRole?
Type:
IRole
(optional, default: A new role is created.)
The IAM role for the Lambda function associated with the custom resource that sets the retention policy.
maxEventAge?
Type:
Duration
(optional, default: Duration.hours(6))
The maximum age of a request that Lambda sends to a function for processing.
Minimum: 60 seconds Maximum: 6 hours
memorySize?
Type:
number
(optional, default: 128)
The amount of memory, in MB, that is allocated to your Lambda function.
Lambda uses this value to proportionally allocate the amount of CPU power. For more information, see Resource Model in the AWS Lambda Developer Guide.
onFailure?
Type:
IDestination
(optional, default: no destination)
The destination for failed invocations.
onSuccess?
Type:
IDestination
(optional, default: no destination)
The destination for successful invocations.
profiling?
Type:
boolean
(optional, default: No profiling.)
Enable profiling.
See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html
profilingGroup?
Type:
IProfiling
(optional, default: A new profiling group will be created if profiling
is set.)
Profiling Group.
See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html
reservedConcurrentExecutions?
Type:
number
(optional, default: No specific limit - account limit.)
The maximum of concurrent executions you want to reserve for the function.
See also: https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
retryAttempts?
Type:
number
(optional, default: 2)
The maximum number of times to retry when the function returns an error.
Minimum: 0 Maximum: 2
role?
Type:
IRole
(optional, default: A unique role will be generated for this lambda function.
Both supplied and generated roles can always be changed by calling addToRolePolicy
.)
Lambda execution role.
This is the role that will be assumed by the function upon execution. It controls the permissions that the function will have. The Role must be assumable by the 'lambda.amazonaws.com' service principal.
The default Role automatically has permissions granted for Lambda execution. If you provide a Role, you must add the relevant AWS managed policies yourself.
The relevant managed policies are "service-role/AWSLambdaBasicExecutionRole" and "service-role/AWSLambdaVPCAccessExecutionRole".
securityGroup?
⚠️ Deprecated: - This property is deprecated, use securityGroups instead
Type:
ISecurity
(optional, default: If the function is placed within a VPC and a security group is
not specified, either by this or securityGroups prop, a dedicated security
group will be created for this function.)
What security group to associate with the Lambda's network interfaces. This property is being deprecated, consider using securityGroups instead.
Only used if 'vpc' is supplied.
Use securityGroups property instead. Function constructor will throw an error if both are specified.
securityGroups?
Type:
ISecurity
[]
(optional, default: If the function is placed within a VPC and a security group is
not specified, either by this or securityGroup prop, a dedicated security
group will be created for this function.)
The list of security groups to associate with the Lambda's network interfaces.
Only used if 'vpc' is supplied.
stackId?
Type:
string
(optional, default: edge-lambda-stack-${region}
)
The stack ID of Lambda@Edge function.
timeout?
Type:
Duration
(optional, default: Duration.seconds(3))
The function execution time (in seconds) after which Lambda terminates the function.
Because the execution time affects cost, set this value based on the function's expected execution time.
tracing?
Type:
Tracing
(optional, default: Tracing.Disabled)
Enable AWS X-Ray Tracing for Lambda Function.
vpc?
Type:
IVpc
(optional, default: Function is not placed within a VPC.)
VPC network to place Lambda network interfaces.
Specify this if the Lambda function needs to access resources in a VPC.
vpcSubnets?
Type:
Subnet
(optional, default: the Vpc default strategy if not specified)
Where to place the network interfaces within the VPC.
Only used if 'vpc' is supplied. Note: internet access for Lambdas requires a NAT gateway, so picking Public subnets is not allowed.
Properties
Name | Type | Description |
---|---|---|
architecture | Architecture | The system architectures compatible with this lambda function. |
connections | Connections | Not supported. |
current | IVersion | Convenience method to make EdgeFunction conform to the same interface as Function . |
edge | string | The ARN of the version for Lambda@Edge. |
env | Resource | The environment this resource belongs to. |
function | string | The ARN of the function. |
function | string | The name of the function. |
grant | IPrincipal | The principal to grant permissions to. |
is | boolean | Whether or not this Lambda function was bound to a VPC. |
lambda | IFunction | The underlying AWS Lambda function. |
latest | IVersion | The $LATEST version of this function. |
node | Construct | The construct tree node associated with this construct. |
permissions | Construct | The construct node where permissions are attached. |
resource | string[] | The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke(). |
stack | Stack | The stack in which this resource is defined. |
version | string | The most recently deployed version of this function. |
role? | IRole | The IAM role associated with this function. |
architecture
Type:
Architecture
The system architectures compatible with this lambda function.
connections
Type:
Connections
Not supported.
Connections are only applicable to VPC-enabled functions.
currentVersion
Type:
IVersion
Convenience method to make EdgeFunction
conform to the same interface as Function
.
edgeArn
Type:
string
The ARN of the version for Lambda@Edge.
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 function.
functionName
Type:
string
The name of the function.
grantPrincipal
Type:
IPrincipal
The principal to grant permissions to.
isBoundToVpc
Type:
boolean
Whether or not this Lambda function was bound to a VPC.
If this is is false
, trying to access the connections
object will fail.
lambda
Type:
IFunction
The underlying AWS Lambda function.
latestVersion
Type:
IVersion
The $LATEST
version of this function.
Note that this is reference to a non-specific AWS Lambda version, which means the function this version refers to can return different results in different invocations.
To obtain a reference to an explicit version which references the current
function configuration, use lambdaFunction.currentVersion
instead.
node
Type:
Construct
The construct tree node associated with this construct.
permissionsNode
Type:
Construct
The construct node where permissions are attached.
resourceArnsForGrantInvoke
Type:
string[]
The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
This property is for cdk modules to consume only. You should not need to use this property. Instead, use grantInvoke() directly.
stack
Type:
Stack
The stack in which this resource is defined.
version
Type:
string
The most recently deployed version of this function.
role?
Type:
IRole
(optional)
The IAM role associated with this function.
Methods
Name | Description |
---|---|
add | Defines an alias for this version. |
add | Adds an event source to this function. |
add | Adds an event source that maps to this AWS Lambda function. |
add | Adds a url to this lambda function. |
add | Adds a permission to the Lambda resource policy. |
add | Adds a statement to the IAM role assumed by the instance. |
apply | Apply the given removal policy to this resource. |
configure | Configures options for asynchronous invocation. |
grant | Grant the given identity permissions to invoke this Lambda. |
grant | Grant the given identity permissions to invoke this Lambda Function URL. |
metric(metricName, props?) | Return the given named metric for this Lambda Return the given named metric for this Function. |
metric | Metric for the Duration of this Lambda How long execution of this Lambda takes. |
metric | How many invocations of this Lambda fail. |
metric | Metric for the number of invocations of this Lambda How often this Lambda is invoked. |
metric | Metric for the number of throttled invocations of this Lambda How often this Lambda is throttled. |
to | Returns a string representation of this construct. |
addAlias(aliasName, options?)
public addAlias(aliasName: string, options?: AliasOptions): Alias
Parameters
- aliasName
string
- options
Alias
Options
Returns
Defines an alias for this version.
addEventSource(source)
public addEventSource(source: IEventSource): void
Parameters
- source
IEvent
Source
Adds an event source to this function.
addEventSourceMapping(id, options)
public addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMapping
Parameters
- id
string
- options
Event
Source Mapping Options
Returns
Adds an event source that maps to this AWS Lambda function.
addFunctionUrl(options?)
public addFunctionUrl(options?: FunctionUrlOptions): FunctionUrl
Parameters
- options
Function
Url Options
Returns
Adds a url to this lambda function.
addPermission(id, permission)
public addPermission(id: string, permission: Permission): void
Parameters
- id
string
- permission
Permission
Adds a permission to the Lambda resource policy.
addToRolePolicy(statement)
public addToRolePolicy(statement: PolicyStatement): void
Parameters
- statement
Policy
Statement
Adds a statement to the IAM role assumed by the instance.
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
).
configureAsyncInvoke(options)
public configureAsyncInvoke(options: EventInvokeConfigOptions): void
Parameters
- options
Event
Invoke Config Options
Configures options for asynchronous invocation.
grantInvoke(identity)
public grantInvoke(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity permissions to invoke this Lambda.
grantInvokeUrl(identity)
public grantInvokeUrl(identity: IGrantable): Grant
Parameters
- identity
IGrantable
Returns
Grant the given identity permissions to invoke this Lambda Function URL.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Lambda Return the given named metric for this Function.
metricDuration(props?)
public metricDuration(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the Duration of this Lambda How long execution of this Lambda takes.
Average over 5 minutes
metricErrors(props?)
public metricErrors(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
How many invocations of this Lambda fail.
Sum over 5 minutes
metricInvocations(props?)
public metricInvocations(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of invocations of this Lambda How often this Lambda is invoked.
Sum over 5 minutes
metricThrottles(props?)
public metricThrottles(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of throttled invocations of this Lambda How often this Lambda is throttled.
Sum over 5 minutes
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.