Class Function
Deploys a file from inside the construct library as a function.
Inheritance
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.Lambda
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Function : FunctionBase, IFunction, IResource, IConnectable, IGrantable, IClientVpnConnectionHandler
Syntax (vb)
Public Class Function
Inherits FunctionBase
Implements IFunction, IResource, IConnectable, IGrantable, IClientVpnConnectionHandler
Remarks
The supplied file is subject to the 4096 bytes limit of being embedded in a CloudFormation template.
The construct includes an associated role with the lambda.
This construct does not yet reproduce all features from the underlying resource library.
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.Signer;
var signingProfile = new SigningProfile(this, "SigningProfile", new SigningProfileProps {
Platform = Platform.AWS_LAMBDA_SHA384_ECDSA
});
var codeSigningConfig = new CodeSigningConfig(this, "CodeSigningConfig", new CodeSigningConfigProps {
SigningProfiles = new [] { signingProfile }
});
new Function(this, "Function", new FunctionProps {
CodeSigningConfig = codeSigningConfig,
Runtime = Runtime.NODEJS_18_X,
Handler = "index.handler",
Code = Code.FromAsset(Join(__dirname, "lambda-handler"))
});
Synopsis
Constructors
Function(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Function(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Function(Construct, String, IFunctionProps) |
Properties
Architecture | The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64). |
CanCreatePermissions | Whether the addPermission() call adds any permissions. |
CurrentVersion | Returns a |
DeadLetterQueue | The DLQ (as queue) associated with this Lambda Function (this is an optional attribute). |
DeadLetterTopic | The DLQ (as topic) associated with this Lambda Function (this is an optional attribute). |
FunctionArn | ARN of this function. |
FunctionName | Name of this function. |
GrantPrincipal | The principal this Lambda Function is running as. |
LogGroup | The LogGroup where the Lambda function's logs are made available. |
PermissionsNode | The construct node where permissions are attached. |
ResourceArnsForGrantInvoke | The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke(). |
Role | Execution role associated with this function. |
Runtime | The runtime configured for this lambda. |
Timeout | The timeout configured for this lambda. |
Methods
AddAlias(String, IAliasOptions) | Defines an alias for this function. |
AddEnvironment(String, String, IEnvironmentOptions) | Adds an environment variable to this Lambda function. |
AddLayers(ILayerVersion[]) | Adds one or more Lambda Layers to this Lambda function. |
ClassifyVersionProperty(String, Boolean) | Record whether specific properties in the |
FromFunctionArn(Construct, String, String) | Import a lambda function into the CDK using its ARN. |
FromFunctionAttributes(Construct, String, IFunctionAttributes) | Creates a Lambda function object which represents a function not defined within this stack. |
FromFunctionName(Construct, String, String) | Import a lambda function into the CDK using its name. |
InvalidateVersionBasedOn(String) | Mix additional information into the hash of the Version object. |
MetricAll(String, IMetricOptions) | Return the given named metric for this Lambda. |
MetricAllConcurrentExecutions(IMetricOptions) | Metric for the number of concurrent executions across all Lambdas. |
MetricAllDuration(IMetricOptions) | Metric for the Duration executing all Lambdas. |
MetricAllErrors(IMetricOptions) | Metric for the number of Errors executing all Lambdas. |
MetricAllInvocations(IMetricOptions) | Metric for the number of invocations of all Lambdas. |
MetricAllThrottles(IMetricOptions) | Metric for the number of throttled invocations of all Lambdas. |
MetricAllUnreservedConcurrentExecutions(IMetricOptions) | Metric for the number of unreserved concurrent executions across all Lambdas. |
Constructors
Function(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Function(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Function(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Function(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Function(Construct, String, IFunctionProps)
public Function(Construct scope, string id, IFunctionProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IFunctionProps
Properties
Architecture
The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).
public override Architecture Architecture { get; }
Property Value
Overrides
CanCreatePermissions
Whether the addPermission() call adds any permissions.
protected override bool CanCreatePermissions { get; }
Property Value
System.Boolean
Overrides
Remarks
True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.
CurrentVersion
Returns a lambda.Version
which represents the current version of this Lambda function. A new version will be created every time the function's configuration changes.
public virtual Version_ CurrentVersion { get; }
Property Value
Remarks
You can specify options for this version using the currentVersionOptions
prop when initializing the lambda.Function
.
DeadLetterQueue
The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).
public virtual IQueue DeadLetterQueue { get; }
Property Value
DeadLetterTopic
The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).
public virtual ITopic DeadLetterTopic { get; }
Property Value
FunctionArn
ARN of this function.
public override string FunctionArn { get; }
Property Value
System.String
Overrides
FunctionName
Name of this function.
public override string FunctionName { get; }
Property Value
System.String
Overrides
GrantPrincipal
The principal this Lambda Function is running as.
public override IPrincipal GrantPrincipal { get; }
Property Value
Overrides
LogGroup
The LogGroup where the Lambda function's logs are made available.
public virtual ILogGroup LogGroup { get; }
Property Value
Remarks
If either logRetention
is set or this property is called, a CloudFormation custom resource is added to the stack that
pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention
period (never expire, by default).
Further, if the log group already exists and the logRetention
is not set, the custom resource will reset the log retention
to never expire even if it was configured with a different value.
PermissionsNode
The construct node where permissions are attached.
public override Node PermissionsNode { get; }
Property Value
Constructs.Node
Overrides
ResourceArnsForGrantInvoke
The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
public override string[] ResourceArnsForGrantInvoke { get; }
Property Value
System.String[]
Overrides
Role
Execution role associated with this function.
public override IRole Role { get; }
Property Value
Overrides
Runtime
The runtime configured for this lambda.
public virtual Runtime Runtime { get; }
Property Value
Timeout
The timeout configured for this lambda.
public virtual Duration Timeout { get; }
Property Value
Methods
AddAlias(String, IAliasOptions)
Defines an alias for this function.
public virtual Alias AddAlias(string aliasName, IAliasOptions options = null)
Parameters
- aliasName System.String
The name of the alias.
- options IAliasOptions
Alias options.
Returns
Remarks
The alias will automatically be updated to point to the latest version of the function as it is being updated during a deployment.
Function fn;
fn.AddAlias("Live");
// Is equivalent to
// Is equivalent to
new Alias(this, "AliasLive", new AliasProps {
AliasName = "Live",
Version = fn.CurrentVersion
});
AddEnvironment(String, String, IEnvironmentOptions)
Adds an environment variable to this Lambda function.
public virtual Function AddEnvironment(string key, string value, IEnvironmentOptions options = null)
Parameters
- key System.String
The environment variable key.
- value System.String
The environment variable's value.
- options IEnvironmentOptions
Environment variable options.
Returns
Remarks
If this is a ref to a Lambda function, this operation results in a no-op.
AddLayers(ILayerVersion[])
Adds one or more Lambda Layers to this Lambda function.
public virtual void AddLayers(params ILayerVersion[] layers)
Parameters
- layers ILayerVersion[]
the layers to be added.
Remarks
Throws: if there are already 5 layers on this function, or the layer is incompatible with this function's runtime.
ClassifyVersionProperty(String, Boolean)
Record whether specific properties in the AWS::Lambda::Function
resource should also be associated to the Version resource.
public static void ClassifyVersionProperty(string propertyName, bool locked)
Parameters
- propertyName System.String
The property to classify.
- locked System.Boolean
whether the property should be associated to the version or not.
Remarks
See 'currentVersion' section in the module README for more details.
FromFunctionArn(Construct, String, String)
Import a lambda function into the CDK using its ARN.
public static IFunction FromFunctionArn(Construct scope, string id, string functionArn)
Parameters
- scope Constructs.Construct
- id System.String
- functionArn System.String
Returns
Remarks
For Function.addPermissions()
to work on this imported lambda, make sure that is
in the same account and region as the stack you are importing it into.
FromFunctionAttributes(Construct, String, IFunctionAttributes)
Creates a Lambda function object which represents a function not defined within this stack.
public static IFunction FromFunctionAttributes(Construct scope, string id, IFunctionAttributes attrs)
Parameters
- scope Constructs.Construct
The parent construct.
- id System.String
The name of the lambda construct.
- attrs IFunctionAttributes
the attributes of the function to import.
Returns
Remarks
For Function.addPermissions()
to work on this imported lambda, set the sameEnvironment property to true
if this imported lambda is in the same account and region as the stack you are importing it into.
FromFunctionName(Construct, String, String)
Import a lambda function into the CDK using its name.
public static IFunction FromFunctionName(Construct scope, string id, string functionName)
Parameters
- scope Constructs.Construct
- id System.String
- functionName System.String
Returns
InvalidateVersionBasedOn(String)
Mix additional information into the hash of the Version object.
public virtual void InvalidateVersionBasedOn(string x)
Parameters
- x System.String
Remarks
The Lambda Function construct does its best to automatically create a new Version when anything about the Function changes (its code, its layers, any of the other properties).
However, you can sometimes source information from places that the CDK cannot look into, like the deploy-time values of SSM parameters. In those cases, the CDK would not force the creation of a new Version object when it actually should.
This method can be used to invalidate the current Version object. Pass in any string into this method, and make sure the string changes when you know a new Version needs to be created.
This method may be called more than once.
MetricAll(String, IMetricOptions)
Return the given named metric for this Lambda.
public static Metric MetricAll(string metricName, IMetricOptions props = null)
Parameters
- metricName System.String
- props IMetricOptions
Returns
MetricAllConcurrentExecutions(IMetricOptions)
Metric for the number of concurrent executions across all Lambdas.
public static Metric MetricAllConcurrentExecutions(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: max over 5 minutes
MetricAllDuration(IMetricOptions)
Metric for the Duration executing all Lambdas.
public static Metric MetricAllDuration(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: average over 5 minutes
MetricAllErrors(IMetricOptions)
Metric for the number of Errors executing all Lambdas.
public static Metric MetricAllErrors(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: sum over 5 minutes
MetricAllInvocations(IMetricOptions)
Metric for the number of invocations of all Lambdas.
public static Metric MetricAllInvocations(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: sum over 5 minutes
MetricAllThrottles(IMetricOptions)
Metric for the number of throttled invocations of all Lambdas.
public static Metric MetricAllThrottles(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: sum over 5 minutes
MetricAllUnreservedConcurrentExecutions(IMetricOptions)
Metric for the number of unreserved concurrent executions across all Lambdas.
public static Metric MetricAllUnreservedConcurrentExecutions(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: max over 5 minutes