Transforms simplify template writing for specific scenarios. You can declare a transform by specifying it in a template. Resource Orchestration Service (ROS) converts templates that use a transform into standard templates, and then performs operations such as creating or updating resources.
ROS supports the Aliyun::Serverless transform. This transform is used for serverless scenarios that are based on the Function Compute service. For more information, see What is Function Compute.
The Aliyun::Serverless transform converts templates written in Serverless Application Model (SAM) syntax to standard ROS templates. This syntax is based on the Alibaba Cloud Funcraft tool.
For more information, see What is Serverless Devs and Serverless Application Model (SAM) syntax.
Supported resource types
Syntax
The value of a transform declaration must be a string. You cannot use parameters or functions to specify the transform value.
JSON example"Transform" : "Aliyun::Serverless-2018-04-03"YAML exampleTransform: Aliyun::Serverless-2018-04-03Example
The following template uses Alibaba Cloud SAM syntax:
ROSTemplateFormatVersion: "2015-09-01"
Transform: "Aliyun::Serverless-2018-04-03"
Resources:
MyService: # service name
Type: "Aliyun::Serverless::Service"
Properties:
Policies:
- AliyunFCReadOnlyAccess # Managed Policy
- Version: "1" # Policy Document
Statement:
- Effect: Allow
Action:
- oss:GetObject
- oss:GetObjectACL
Resource: "*"
MyFunction: # function name
Type: "Aliyun::Serverless::Function"
Properties:
Handler: index.handler
Runtime: nodejs6
CodeUri: "oss://testBucket/myCode.zip"When you create a change set or a stack from the template, ROS expands the SAM syntax. The preceding template is converted as follows:
- Converts the Aliyun::Serverless::Service resource to an ALIYUN::FC::Service resource.
- Converts the Policies defined in the Aliyun::Serverless::Service resource to ALIYUN::RAM::Role and ALIYUN::RAM::AttachPolicyToRole resources, and then specifies these resources in the Role parameter of the ALIYUN::FC::Service resource.
- Converts the Aliyun::Serverless::Function resource to an ALIYUN::FC::Function resource.
The converted ROS template is as follows:
{
"ROSTemplateFormatVersion": "2015-09-01",
"Resources": {
"MyServiceRole": {
"Type": "ALIYUN::RAM::Role",
"Properties": {
"RoleName": "test-MyServiceRole-7840BA19B01C",
"Description": "Function Compute default role",
"Policies": [
{
"PolicyName": "test-MyServiceRole-7840BA19B01CPolicy1",
"PolicyDocument": {
"Version": "1",
"Statement": [
{
"Action": ["oss:GetObject", "oss:GetObjectACL"],
"Resource": ["*"],
"Effect": "Allow"
}
]
}
}
],
"AssumeRolePolicyDocument": {
"Version": "1",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": ["fc.aliyuncs.com"]
}
}
]
}
}
},
"AliyunFCReadOnlyAccessMyServiceRole": {
"Type": "ALIYUN::RAM::AttachPolicyToRole",
"Properties": {
"PolicyName": "AliyunFCReadOnlyAccess",
"PolicyType": "System",
"RoleName": {
"Fn::GetAtt": ["MyServiceRole", "RoleName"]
}
},
"DependsOn": "MyServiceRole"
},
"MyService": {
"Type": "ALIYUN::FC::Service",
"Properties": {
"ServiceName": "test-MyService-E522E1B83D81",
"Role": {
"Fn::GetAtt": ["MyServiceRole", "Arn"]
},
"LogConfig": {
"Project": "",
"Logstore": ""
},
"InternetAccess": true
},
"DependsOn": ["MyServiceRole", "AliyunFCReadOnlyAccessMyServiceRole"]
},
"MyServiceMyFunction": {
"Type": "ALIYUN::FC::Function",
"Properties": {
"Code": {
"OssBucketName": "testBucket",
"OssObjectName": "myCode.zip"
},
"FunctionName": "MyFunction",
"ServiceName": "test-MyService-E522E1B83D81",
"EnvironmentVariables": {
"PATH": "/code/.fun/root/usr/local/bin:/code/.fun/root/usr/local/sbin:/code/.fun/root/usr/bin:/code/.fun/root/usr/sbin:/code/.fun/root/sbin:/code/.fun/root/bin:/code/.fun/python/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin",
"LD_LIBRARY_PATH": "/code/.fun/root/usr/lib:/code/.fun/root/usr/lib/x86_64-linux-gnu:/code/.fun/root/lib/x86_64-linux-gnu:/code/.fun/root/usr/lib64:/code:/code/lib:/usr/local/lib",
"PYTHONUSERBASE": "/code/.fun/python"
},
"Handler": "index.handler",
"Runtime": "nodejs6"
},
"DependsOn": ["MyService"]
}
}
}