Function

class Function : KotlinCustomResource

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

Properties

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

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

Link copied to clipboard
val codeChecksum: Output<String>

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>?

The Function Compute function description.

Link copied to clipboard

A map that defines environment variables for the function.

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

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 functionId: Output<String>

The Function Compute service ID.

Link copied to clipboard
val handler: Output<String>

The function entry point in your code.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard

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

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

The entry point of the function's initialization.

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

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

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

The instance type of the function.

Link copied to clipboard
val lastModified: Output<String>

The date this resource was last modified.

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

The configuration for layers.

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

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>

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>?

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

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

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>?

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

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val runtime: Output<String>

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

Link copied to clipboard
val service: Output<String>

The Function Compute service name.

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

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

Link copied to clipboard
val urn: Output<String>