Skip to content

Function

This class encapsulates and extends the ROS resource type ALIYUN::FC::Function, which is used to create a function.

A function must belong to a service. All functions of a service share the same attributes as the service, such as the service authorization and log configurations.

Initializers

import ros_cdk_fc
ros_cdk_fc.Function(
  scope: Construct,
  id: str,
  function_name: typing.Union[str, IResolvable],
  handler: typing.Union[str, IResolvable],
  runtime: typing.Union[str, IResolvable],
  service_name: typing.Union[str, IResolvable],
  async_configuration: typing.Union[IResolvable, AsyncConfigurationProperty] = None,
  ca_port: typing.Union[typing.Union[int, float], IResolvable] = None,
  code: typing.Union[IResolvable, CodeProperty] = None,
  cpu: typing.Union[typing.Union[int, float], IResolvable] = None,
  custom_container_config: typing.Union[IResolvable, CustomContainerConfigProperty] = None,
  custom_dns: typing.Union[IResolvable, CustomDNSProperty] = None,
  custom_health_check_config: typing.Union[IResolvable, CustomHealthCheckConfigProperty] = None,
  custom_runtime_config: typing.Union[IResolvable, CustomRuntimeConfigProperty] = None,
  description: typing.Union[str, IResolvable] = None,
  disk_size: typing.Union[typing.Union[int, float], IResolvable] = None,
  environment_variables: typing.Union[IResolvable, typing.Mapping[typing.Any]] = None,
  gpu_memory_size: typing.Union[typing.Union[int, float], IResolvable] = None,
  initialization_timeout: typing.Union[typing.Union[int, float], IResolvable] = None,
  initializer: typing.Union[str, IResolvable] = None,
  instance_concurrency: typing.Union[typing.Union[int, float], IResolvable] = None,
  instance_lifecycle_config: typing.Union[IResolvable, InstanceLifecycleConfigProperty] = None,
  instance_soft_concurrency: typing.Union[typing.Union[int, float], IResolvable] = None,
  instance_type: typing.Union[str, IResolvable] = None,
  memory_size: typing.Union[typing.Union[int, float], IResolvable] = None,
  timeout: typing.Union[typing.Union[int, float], IResolvable] = None,
  enable_resource_property_constraint: bool = None
)
Name Type Description
scope ros_cdk_core.Construct No description.
id str No description.
function_name typing.Union[str, ros_cdk_core.IResolvable] Property functionName: Function name.
handler typing.Union[str, ros_cdk_core.IResolvable] Property handler: The function execution entry point.
runtime typing.Union[str, ros_cdk_core.IResolvable] Property runtime: The function runtime environment.
service_name typing.Union[str, ros_cdk_core.IResolvable] Property serviceName: Service name.
async_configuration typing.Union[ros_cdk_core.IResolvable, AsyncConfigurationProperty] Property asyncConfiguration: Configuration of asynchronous function calls.
ca_port typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property caPort: Custom runtime and custom container runtime dedicated fields, which represent the port that the started custom http server listens to.
code typing.Union[ros_cdk_core.IResolvable, CodeProperty] Property code: The code that contains the function implementation.
cpu typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property cpu: The number of vCPUs of the function.
custom_container_config typing.Union[ros_cdk_core.IResolvable, CustomContainerConfigProperty] Property customContainerConfig: Custom container runtime related configuration.
custom_dns typing.Union[ros_cdk_core.IResolvable, CustomDNSProperty] Property customDns: The custom DNS configurations of the function.
custom_health_check_config typing.Union[ros_cdk_core.IResolvable, CustomHealthCheckConfigProperty] Property customHealthCheckConfig: The health check configurations for the custom runtime and custom container.
custom_runtime_config typing.Union[ros_cdk_core.IResolvable, CustomRuntimeConfigProperty] Property customRuntimeConfig: Custom runtime related configuration.
description typing.Union[str, ros_cdk_core.IResolvable] Property description: Function description.
disk_size typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property diskSize: The disk size of the function.
environment_variables typing.Union[ros_cdk_core.IResolvable, typing.Mapping[typing.Any]] Property environmentVariables: The environment variable set for the function, you can get the value of the environment variable in the function.
gpu_memory_size typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property gpuMemorySize: The GPU memory capacity for the function.
initialization_timeout typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property initializationTimeout: the max execution time of the initializer, in second.
initializer typing.Union[str, ros_cdk_core.IResolvable] Property initializer: the entry point of the initializer.
instance_concurrency typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property instanceConcurrency: Function instance concurrency.
instance_lifecycle_config typing.Union[ros_cdk_core.IResolvable, InstanceLifecycleConfigProperty] Property instanceLifecycleConfig: The configuration of the instance lifecycle function.
instance_soft_concurrency typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property instanceSoftConcurrency: The soft concurrency of the instance.
instance_type typing.Union[str, ros_cdk_core.IResolvable] Property instanceType: Instance type.
memory_size typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property memorySize: The amount of memory that’s used to run function, in MB.
timeout typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property timeout: The maximum time duration a function can run, in seconds.
enable_resource_property_constraint bool No description.

scopeRequired

  • Type: ros_cdk_core.Construct

idRequired

  • Type: str

function_nameRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property functionName: Function name.


handlerRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property handler: The function execution entry point.


runtimeRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property runtime: The function runtime environment.

Supporting nodejs16、nodejs14、nodejs12、nodejs10、nodejs8、nodejs6、nodejs4.4、python3.10、python3.9、python3、python2.7、java11、java8、go1、php7.2、dotnetcore3.1、dotnetcore2.1、custom.debian10、custom和custom-container and so on


service_nameRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property serviceName: Service name.


async_configurationOptional

Property asyncConfiguration: Configuration of asynchronous function calls.


ca_portOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property caPort: Custom runtime and custom container runtime dedicated fields, which represent the port that the started custom http server listens to.

The default value is 9000


codeOptional

  • Type: typing.Union[ros_cdk_core.IResolvable, CodeProperty]

Property code: The code that contains the function implementation.


cpuOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property cpu: The number of vCPUs of the function.

The value must be a multiple of 0.05.


custom_container_configOptional

Property customContainerConfig: Custom container runtime related configuration.

After configuration, the function can be replaced with a custom container to execute the function


custom_dnsOptional

Property customDns: The custom DNS configurations of the function.


custom_health_check_configOptional

Property customHealthCheckConfig: The health check configurations for the custom runtime and custom container.


custom_runtime_configOptional

Property customRuntimeConfig: Custom runtime related configuration.


descriptionOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property description: Function description.


disk_sizeOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property diskSize: The disk size of the function.

Unit: MB. Valid values: 512 and 10240.


environment_variablesOptional

  • Type: typing.Union[ros_cdk_core.IResolvable, typing.Mapping[typing.Any]]

Property environmentVariables: The environment variable set for the function, you can get the value of the environment variable in the function.


gpu_memory_sizeOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property gpuMemorySize: The GPU memory capacity for the function.

Unit: MB. The value must be a multiple of 1,024.


initialization_timeoutOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property initializationTimeout: the max execution time of the initializer, in second.


initializerOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property initializer: the entry point of the initializer.


instance_concurrencyOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property instanceConcurrency: Function instance concurrency.

Value can be between 1 to 100.


instance_lifecycle_configOptional

Property instanceLifecycleConfig: The configuration of the instance lifecycle function.


instance_soft_concurrencyOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property instanceSoftConcurrency: The soft concurrency of the instance.

You can use this parameter to implement graceful scale-up of instances. If the number of concurrent requests on an instance is greater than the value of soft concurrency, an instance scale-up is triggered. For example, if your instance requires a long time to start, you can specify a suitable soft concurrency to start the instance in advance.The value must be less than or equal to that of the instanceConcurrency parameter.


instance_typeOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property instanceType: Instance type.

Value:- e1: Elastic Instance.- c1: Performance Instance.- fc.gpu.tesla.1: GPU Tesla Series Instance Type.- fc.gpu.ampere.1: GPU Ampere Series Instance Type.- fc.gpu.ada.1: GPU Ada Series Instance Type.- g1: Same as fc.gpu.tesla.1.


memory_sizeOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property memorySize: The amount of memory that’s used to run function, in MB.

Function Compute uses this value to allocate CPU resources proportionally. Defaults to 128 MB. It can be multiple of 64 MB and between 128 MB and 32768 MB.


timeoutOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property timeout: The maximum time duration a function can run, in seconds.

After which Function Compute terminates the execution. Defaults to 3 seconds, and can be between 1 to 86400 seconds.


enable_resource_property_constraintOptional

  • Type: bool

Methods

Name Description
to_string Returns a string representation of this construct.
synthesize Allows this construct to emit artifacts into the cloud assembly during synthesis.
add_condition No description.
add_count No description.
add_dependency No description.
add_resource_desc No description.
apply_removal_policy No description.
fetch_condition No description.
fetch_dependency No description.
fetch_resource_desc No description.
get_att No description.
set_metadata No description.
code_from_asset Loads the fcFunction code from a local disk path.
code_from_bucket Function handler code as an OSS object.
code_from_inline Inline code for FC fcFunction handler.

to_string

def to_string() -> str

Returns a string representation of this construct.

synthesize

def synthesize(
  session: ISynthesisSession
) -> None

Allows this construct to emit artifacts into the cloud assembly during synthesis.

This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

sessionRequired

  • Type: ros_cdk_core.ISynthesisSession

The synthesis session.


add_condition

def add_condition(
  condition: RosCondition
) -> None

conditionRequired

  • Type: ros_cdk_core.RosCondition

add_count

def add_count(
  count: typing.Union[typing.Union[int, float], IResolvable]
) -> None

countRequired

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

add_dependency

def add_dependency(
  resource: Resource
) -> None

resourceRequired

  • Type: ros_cdk_core.Resource

add_resource_desc

def add_resource_desc(
  desc: str
) -> None

descRequired

  • Type: str

apply_removal_policy

def apply_removal_policy(
  policy: RemovalPolicy
) -> None

policyRequired

  • Type: ros_cdk_core.RemovalPolicy

fetch_condition

def fetch_condition() -> RosCondition

fetch_dependency

def fetch_dependency() -> typing.List[str]

fetch_resource_desc

def fetch_resource_desc() -> str

get_att

def get_att(
  name: str
) -> IResolvable

nameRequired

  • Type: str

set_metadata

def set_metadata(
  key: str,
  value: typing.Any
) -> None

keyRequired

  • Type: str

valueRequired

  • Type: typing.Any

code_from_asset

def code_from_asset(
  path: str
) -> None

Loads the fcFunction code from a local disk path.

pathRequired

  • Type: str

Either a directory with the Lambda code bundle or a .zip file.


code_from_bucket

def code_from_bucket(
  bucket: Bucket,
  key: str
) -> None

Function handler code as an OSS object.

bucketRequired

  • Type: ros_cdk_oss.Bucket

The OSS bucket.


keyRequired

  • Type: str

The object key.


code_from_inline

def code_from_inline(
  code: str
) -> None

Inline code for FC fcFunction handler.

codeRequired

  • Type: str

The actual handler code (limited to 4KiB).


Static Functions

Name Description
is_construct Return whether the given object is a Construct.

is_construct

import ros_cdk_fc
ros_cdk_fc.Function.is_construct(
  x: typing.Any
)

Return whether the given object is a Construct.

xRequired

  • Type: typing.Any

Properties

Name Type Description
node ros_cdk_core.ConstructNode The construct tree node associated with this construct.
env ros_cdk_core.IResourceEnvironment The environment this resource belongs to.
ref str No description.
stack ros_cdk_core.Stack The stack in which this resource is defined.
resource ros_cdk_core.RosResource No description.
attr_arn typing.Union[str, ros_cdk_core.IResolvable] Attribute ARN: The ARN for ALIYUN::ROS::CustomResource.
attr_function_id typing.Union[str, ros_cdk_core.IResolvable] Attribute FunctionId: The function ID.
attr_function_name typing.Union[str, ros_cdk_core.IResolvable] Attribute FunctionName: The function name.
attr_service_id typing.Union[str, ros_cdk_core.IResolvable] Attribute ServiceId: The service ID.
attr_service_name typing.Union[str, ros_cdk_core.IResolvable] Attribute ServiceName: The service name.
props FunctionProps No description.

nodeRequired

node: ConstructNode
  • Type: ros_cdk_core.ConstructNode

The construct tree node associated with this construct.


envRequired

env: IResourceEnvironment
  • Type: ros_cdk_core.IResourceEnvironment

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.


refRequired

ref: str
  • Type: str

stackRequired

stack: Stack
  • Type: ros_cdk_core.Stack

The stack in which this resource is defined.


resourceOptional

resource: RosResource
  • Type: ros_cdk_core.RosResource

attr_arnRequired

attr_arn: typing.Union[str, IResolvable]
  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Attribute ARN: The ARN for ALIYUN::ROS::CustomResource.


attr_function_idRequired

attr_function_id: typing.Union[str, IResolvable]
  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Attribute FunctionId: The function ID.


attr_function_nameRequired

attr_function_name: typing.Union[str, IResolvable]
  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Attribute FunctionName: The function name.


attr_service_idRequired

attr_service_id: typing.Union[str, IResolvable]
  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Attribute ServiceId: The service ID.


attr_service_nameRequired

attr_service_name: typing.Union[str, IResolvable]
  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Attribute ServiceName: The service name.


propsRequired

props: FunctionProps