FunctionArgs

data class FunctionArgs(val caPort: Output<Int>? = null, val codeChecksum: Output<String>? = null, val customContainerConfig: Output<FunctionCustomContainerConfigArgs>? = null, val description: Output<String>? = null, val environmentVariables: Output<Map<String, Any>>? = null, val filename: Output<String>? = null, val handler: Output<String>? = null, val initializationTimeout: Output<Int>? = null, val initializer: Output<String>? = null, val instanceConcurrency: Output<Int>? = null, val instanceType: Output<String>? = null, val layers: Output<List<String>>? = null, val memorySize: Output<Int>? = null, val name: Output<String>? = null, val namePrefix: Output<String>? = null, val ossBucket: Output<String>? = null, val ossKey: Output<String>? = null, val runtime: Output<String>? = null, val service: Output<String>? = null, val timeout: Output<Int>? = null) : ConvertibleToJava<FunctionArgs>

Provides a Alicloud Function Compute Function resource. Function allows you to trigger execution of code in response to events in Alibaba Cloud. The Function itself includes source code and runtime configuration. For information about Service and how to use it, see What is Function Compute.

NOTE: The resource requires a provider field 'account_id'. See account_id. NOTE: Available since v1.10.0.

Example Usage

Basic Usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.RandomInteger;
import com.pulumi.random.RandomIntegerArgs;
import com.pulumi.alicloud.log.Project;
import com.pulumi.alicloud.log.Store;
import com.pulumi.alicloud.log.StoreArgs;
import com.pulumi.alicloud.ram.Role;
import com.pulumi.alicloud.ram.RoleArgs;
import com.pulumi.alicloud.ram.RolePolicyAttachment;
import com.pulumi.alicloud.ram.RolePolicyAttachmentArgs;
import com.pulumi.alicloud.fc.Service;
import com.pulumi.alicloud.fc.ServiceArgs;
import com.pulumi.alicloud.fc.inputs.ServiceLogConfigArgs;
import com.pulumi.alicloud.oss.Bucket;
import com.pulumi.alicloud.oss.BucketArgs;
import com.pulumi.alicloud.oss.BucketObject;
import com.pulumi.alicloud.oss.BucketObjectArgs;
import com.pulumi.alicloud.fc.Function;
import com.pulumi.alicloud.fc.FunctionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var defaultRandomInteger = new RandomInteger("defaultRandomInteger", RandomIntegerArgs.builder()
.max(99999)
.min(10000)
.build());
var defaultProject = new Project("defaultProject");
var defaultStore = new Store("defaultStore", StoreArgs.builder()
.project(defaultProject.name())
.build());
var defaultRole = new Role("defaultRole", RoleArgs.builder()
.document("""
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"fc.aliyuncs.com"
]
}
}
],
"Version": "1"
}
""")
.description("this is a example")
.force(true)
.build());
var defaultRolePolicyAttachment = new RolePolicyAttachment("defaultRolePolicyAttachment", RolePolicyAttachmentArgs.builder()
.roleName(defaultRole.name())
.policyName("AliyunLogFullAccess")
.policyType("System")
.build());
var defaultService = new Service("defaultService", ServiceArgs.builder()
.description("example-value")
.role(defaultRole.arn())
.logConfig(ServiceLogConfigArgs.builder()
.project(defaultProject.name())
.logstore(defaultStore.name())
.enableInstanceMetrics(true)
.enableRequestMetrics(true)
.build())
.build());
var defaultBucket = new Bucket("defaultBucket", BucketArgs.builder()
.bucket(defaultRandomInteger.result().applyValue(result -> String.format("terraform-example-%s", result)))
.build());
var defaultBucketObject = new BucketObject("defaultBucketObject", BucketObjectArgs.builder()
.bucket(defaultBucket.id())
.key("index.py")
.content("""
import logging
def handler(event, context):
logger = logging.getLogger()
logger.info('hello world')
return 'hello world' """)
.build());
var foo = new Function("foo", FunctionArgs.builder()
.service(defaultService.name())
.description("example")
.ossBucket(defaultBucket.id())
.ossKey(defaultBucketObject.key())
.memorySize("512")
.runtime("python3.10")
.handler("hello.handler")
.environmentVariables(Map.of("prefix", "terraform"))
.build());
}
}

Module Support

You can use to the existing fc module to create a function quickly and set several triggers for it.

Import

Function Compute function can be imported using the id, e.g.

$ pulumi import alicloud:fc/function:Function foo my-fc-service:hello-world

Constructors

Link copied to clipboard
fun FunctionArgs(caPort: Output<Int>? = null, codeChecksum: Output<String>? = null, customContainerConfig: Output<FunctionCustomContainerConfigArgs>? = null, description: Output<String>? = null, environmentVariables: Output<Map<String, Any>>? = null, filename: Output<String>? = null, handler: Output<String>? = null, initializationTimeout: Output<Int>? = null, initializer: Output<String>? = null, instanceConcurrency: Output<Int>? = null, instanceType: Output<String>? = null, layers: Output<List<String>>? = null, memorySize: Output<Int>? = null, name: Output<String>? = null, namePrefix: Output<String>? = null, ossBucket: Output<String>? = null, ossKey: Output<String>? = null, runtime: Output<String>? = null, service: Output<String>? = null, timeout: Output<Int>? = null)

Functions

Link copied to clipboard
open override fun toJava(): FunctionArgs

Properties

Link copied to clipboard
val caPort: Output<Int>? = null

The port that the function listen to, only valid for custom runtime and custom container runtime.

Link copied to clipboard
val codeChecksum: Output<String>? = null

The checksum (crc64) of the function code.Used to trigger updates.The value can be generated by data source alicloud_file_crc64_checksum.

Link copied to clipboard

The configuration for custom container runtime.See custom_container_config below.

Link copied to clipboard
val description: Output<String>? = null

The Function Compute function description.

Link copied to clipboard
val environmentVariables: Output<Map<String, Any>>? = null

A map that defines environment variables for the function.

Link copied to clipboard
val filename: Output<String>? = null

The path to the function's deployment package within the local filesystem. It is conflict with the oss_-prefixed options.

Link copied to clipboard
val handler: Output<String>? = null

The function entry point in your code.

Link copied to clipboard
val initializationTimeout: Output<Int>? = null

The maximum length of time, in seconds, that the function's initialization should be run for.

Link copied to clipboard
val initializer: Output<String>? = null

The entry point of the function's initialization.

Link copied to clipboard
val instanceConcurrency: Output<Int>? = null

The maximum number of requests can be executed concurrently within the single function instance.

Link copied to clipboard
val instanceType: Output<String>? = null

The instance type of the function.

Link copied to clipboard
val layers: Output<List<String>>? = null

The configuration for layers.

Link copied to clipboard
val memorySize: Output<Int>? = null

Amount of memory in MB your function can use at runtime. Defaults to 128. Limits to 128, 32768.

Link copied to clipboard
val name: Output<String>? = null

The Function Compute function name. It is the only in one service and is conflict with "name_prefix".

Link copied to clipboard
val namePrefix: Output<String>? = null

Setting a prefix to get a only function name. It is conflict with "name".

Link copied to clipboard
val ossBucket: Output<String>? = null

The OSS bucket location containing the function's deployment package. Conflicts with filename. This bucket must reside in the same Alibaba Cloud region where you are creating the function.

Link copied to clipboard
val ossKey: Output<String>? = null

The OSS key of an object containing the function's deployment package. Conflicts with filename.

Link copied to clipboard
val runtime: Output<String>? = null

See https://www.alibabacloud.com/help/zh/function-compute/latest/manage-functions#multiTask3514 for valid values.

Link copied to clipboard
val service: Output<String>? = null

The Function Compute service name.

Link copied to clipboard
val timeout: Output<Int>? = null

The amount of time your function has to run in seconds.