ALIYUN::ApiGateway::Api is used to create an API operation.
Syntax
{
"Type": "ALIYUN::ApiGateway::Api",
"Properties": {
"ErrorCodeSamples": List,
"Description": String,
"ServiceConfig": Map,
"SystemParameters": List,
"ServiceParameters": List,
"OpenIdConnectConfig": Map,
"RequestConfig": Map,
"AuthType": String,
"Visibility": String,
"Tags": List,
"ResultSample": String,
"ResultType": String,
"ApiName": String,
"FailResultSample": String,
"DisableInternet": Boolean,
"ForceNonceCheck": Boolean,
"ConstParameters": List,
"GroupId": String,
"ServiceParametersMap": List,
"RequestParameters": List,
"AppCodeAuthType": String
}
}
Properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
ServiceConfig |
Map |
Yes |
Yes |
The configuration items of API requests sent by API Gateway to the backend service. |
For more information, see ServiceConfig properties. |
RequestConfig |
Map |
Yes |
Yes |
The configuration items of API requests sent by the consumer to API Gateway. |
For more information, see RequestConfig properties. |
Visibility |
String |
Yes |
Yes |
Specifies whether the API operation is public. |
Valid values:
|
ResultSample |
String |
Yes |
Yes |
The sample response from the backend service. |
None. |
ResultType |
String |
Yes |
Yes |
The format of the response from the backend service. |
Default value: JSON. Valid values:
- JSON
- TEXT
- BINARY
- XML
- PASSTHROUGH
|
ApiName |
String |
Yes |
Yes |
The name of the API operation. |
The name must be 4 to 50 characters in length, and can contain letters, digits, and underscores (_). The name must start with a letter.
Note The name must be unique within an API group.
|
GroupId |
String |
Yes |
No |
The ID of the API group. |
None. |
ErrorCodeSamples |
List |
No |
Yes |
The sample error codes returned by the backend service. |
For more information, see ErrorCodeSamples properties. |
Description |
String |
No |
Yes |
The description of the API operation. |
The description can be up to 180 characters in length. |
DisableInternet |
Boolean |
No |
Yes |
Specifies whether to disable calls to the API operation over the Internet. |
Valid values:
|
ForceNonceCheck |
Boolean |
No |
Yes |
Specifies whether to forcefully check X-Ca-Nonce when the request is sent. |
Valid values:
|
Tags |
List |
No |
Yes |
The tags of the API operation. |
You can add up to 20 tags. For more information, see Tags properties. |
SystemParameters |
List |
No |
Yes |
The system parameters of the API operation. |
For more information, see SystemParameters properties. |
ServiceParameters |
List |
No |
Yes |
The parameters of API requests sent by API Gateway to the backend service. |
For more information, see ServiceParameters properties. |
OpenIdConnectConfig |
Map |
No |
Yes |
The configuration items of the third-party OpenID Connect authentication method. |
For more information, see OpenIdConnectConfig properties. |
AuthType |
String |
No |
Yes |
The security authentication method of the API operation. |
Valid values:
- APP: The API operation can be called only by authorized applications.
- ANONYMOUS: The API operation can be called anonymously. API Gateway does not authenticate callers and cannot set user-specific throttling policies. Before you add an API group that contains such API operations to Alibaba Cloud Marketplace, we recommend that you move the API operations to another API group, set Visibility to PRIVATE, or set AuthType to APP.
- APPOPENID: The OpenID Connect authentication method is used. The API operation can be called only by applications that are authorized by OpenID Connect. If this method is specified, the OpenIdConnectConfig property is required.
|
ServiceParametersMap |
List |
No |
Yes |
The mappings between parameters of requests sent by the consumer to API Gateway and parameters of requests sent by API Gateway to the backend service. |
For more information, see ServiceParametersMap properties. |
FailResultSample |
String |
No |
Yes |
The sample error response from the backend service. |
None. |
RequestParameters |
List |
No |
Yes |
The parameters of API requests sent by the consumer to API Gateway. |
For more information, see RequestParameters properties. |
ConstParameters |
List |
No |
Yes |
The constant parameters of the specified API operation. |
For more information, see ConstParameters properties. |
AppCodeAuthType |
String |
No |
Yes |
The AppCode authentication method. |
This property takes effect when you set the AuthType property to APP. Default value: DEFAULT. Valid values:
- DEFAULT: AppCode authentication is configured with the API group.
- DISABLE: AppCode authentication is disabled.
- HEADER: AppCode can be placed in the Header field for authentication.
- HEADER_QUERY: AppCode can be placed in the Header or Query field for authentication.
|
Tags syntax
"Tags": [
{
"Key": String,
"Value": String
}
]
Tags properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
Key |
String |
Yes |
No |
The key of the tag. |
The tag key must be 1 to 128 characters in length, and cannot contain http:// or https:// . The tag key cannot start with aliyun or acs: . |
Value |
String |
No |
No |
The value of the tag. |
The tag value can be up to 128 characters in length, and cannot contain http:// or https:// . The tag value cannot start with aliyun or acs: . |
ErrorCodeSamples syntax
"ErrorCodeSamples": [
{
"Message": String,
"Code": String,
"Description": String
}
]
ErrorCodeSamples properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
Message |
String |
Yes |
Yes |
The error message. |
None. |
Code |
String |
Yes |
Yes |
The HTTP status code. |
None. |
Description |
String |
No |
Yes |
The error description. |
None. |
ServiceConfig syntax
"ServiceConfig": {
"ServiceTimeOut": Integer,
"FunctionComputeConfig": Map,
"VpcConfig": Map,
"MockResult": String,
"MockStatusCode": Integer,
"ServiceHttpMethod": String,
"ServiceProtocol": String,
"ServiceVpcEnable": String,
"ServiceAddress": String,
"ContentTypeValue": String,
"MockHeaders": List,
"ContentTypeCatagory": String,
"ServicePath": String,
"Mock": String
}
ServiceConfig properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
FunctionComputeConfig |
Map |
No |
Yes |
The configuration of Function Compute as the backend service. |
None. For more information, see FunctionComputeConfig properties. |
MockStatusCode |
Integer |
No. |
Yes |
The HTTP status code. |
The status code returned in an HTTP/1.1 compatible format. |
MockHeaders |
List |
No |
Yes |
The mock response headers defined when the mock mode is enabled. |
None. For more information, see MockHeaders properties. |
ServiceTimeOut |
Integer |
No. |
Yes |
The timeout period of the backend service. |
Unit: milliseconds. |
ServiceAddress |
String |
No |
Yes |
The address of the backend service. |
If the complete backend service address is http://example.com:8080/object/add?key1=value1&key2=value2 , the value of the ServiceAddress property is http://example.com:8080 . |
ServicePath |
String |
No |
Yes |
The path of the backend service. |
If the complete backend service address is http://example.com:8080/object/add?key1=value1&key2=value2 , the value of the ServicePath property is /object/add . |
ServiceProtocol |
String |
No |
Yes |
The protocol of the backend service. |
Valid values:
- HTTP
- HTTPS
- FunctionCompute
|
ServiceVpcEnable |
String |
No |
Yes |
Specifies whether to use the Virtual Private Cloud (VPC) service. |
Default value: FALSE. Valid values:
|
ServiceHttpMethod |
String |
No |
Yes |
The HTTP method used to call the backend service. |
Default value: GET. Valid values:
- GET
- POST
- DELETE
- PUT
- HEAD
- TRACE
- PATCH
- CONNECT
- OPTIONS
- ANY
|
ContentTypeCatagory |
String |
No |
Yes |
The ContentType header type used when you call the backend service over HTTP. |
Default value: CLIENT. Valid values:
- DEFAULT: the default header type in API Gateway
- CUSTOM: a custom header type
- CLIENT: the ContentType header type of the client
|
ContentTypeValue |
String |
No |
Yes |
The value of the ContentType header when the ServiceProtocol property is set to HTTP and the ContentTypeCatagory property is set to DEFAULT or CUSTOM. |
None. |
Mock |
String |
No |
Yes |
Specifies whether to use the mock mode. |
Default value: FALSE. Valid values:
|
MockResult |
String |
No |
Yes |
The result returned when the mock mode is used. |
None. |
VpcConfig |
Map |
No |
Yes |
The VPC configurations. |
For more information, see VpcConfig properties. |
VpcConfig syntax
"VpcConfig": {
"InstanceId": String,
"VpcId": String,
"Port": Integer
}
VpcConfig properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
InstanceId |
String |
Yes |
Yes |
The ID of the instance in the VPC. |
Only Elastic Compute Service (ECS) instances and Server Load Balancer(SLB) instances are supported. |
VpcId |
String |
Yes |
Yes |
The ID of the VPC. |
None. |
Port |
Integer |
Yes |
Yes |
The port number that corresponds to the instance. |
None. |
SystemParameters syntax
"SystemParameters": [
{
"DemoValue": String,
"ParameterName": String,
"ServiceParameterName": String,
"Location": String,
"Description": String
}
]
SystemParameters properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
Location |
String |
Yes |
Yes |
The location of the system parameter. |
None. |
ParameterName |
String |
Yes |
Yes |
The name of the system parameter. |
Valid values:
- CaClientIp
- CaDomain
- CaRequestHandleTime
- CaAppId
- CaRequestId
- CaHttpSchema
- CaProxy
|
ServiceParameterName |
String |
Yes |
Yes |
The name of the backend service parameter. |
None. |
Description |
String |
No |
Yes |
The description of the system parameter. |
None. |
DemoValue |
String |
No |
Yes |
The sample value of the system parameter. |
None. |
ServiceParameters syntax
"ServiceParameters": [
{
"ParameterType": String,
"Location": String,
"ServiceParameterName": String
}
]
ServiceParameters properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
ParameterType |
String |
Yes |
Yes |
The data type of the backend service parameter. |
Valid values:
|
Location |
String |
Yes |
Yes |
The location of the backend service parameter. |
Valid values:
|
ServiceParameterName |
String |
Yes |
Yes |
The name of the backend service parameter. |
None. |
OpenIdConnectConfig syntax
"OpenIdConnectConfig": {
"OpenIdApiType": String,
"PublicKey": String,
"PublicKeyId": String,
"IdTokenParamName": String
}
OpenIdConnectConfig properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
OpenIdApiType |
String |
Yes |
Yes |
The authorization type of an OpenID Connect API. |
Valid values:
- IDTOKEN: specifies an authorization API, which is used to issue a token. If you set this property to IDTOKEN, the PublicKeyId and PublicKey properties are required.
- BUSINESS: specifies a business API, which is used to verify a token. If you set this property to BUSINESS, the IdTokenParamName property is required.
|
PublicKey |
String |
No |
Yes |
The public key used for token verification. |
None. |
PublicKeyId |
String |
No |
Yes |
The ID of the public key. |
None. |
IdTokenParamName |
String |
No |
Yes |
The name of the parameter that corresponds to the token. |
None. |
RequestConfig syntax
"RequestConfig": {
"RequestMode": String,
"RequestPath": String,
"PostBodyDescription": String,
"RequestProtocol": String,
"RequestHttpMethod": String,
"BodyFormat": String
}
RequestConfig properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
RequestMode |
String |
Yes |
Yes |
The request mode. |
Default value: MAPPING. Valid values:
- MAPPING: request parameter mapping
- PASSTHROUGH: request parameter passthrough
|
RequestPath |
String |
Yes |
Yes |
The API request path. |
If the complete API URL is http://example.com:8080/object/add?key1=value1&key2=value2 , the value of the RequestPath property is /object/add . |
RequestProtocol |
String |
Yes |
Yes |
The protocol type supported by the API operation. |
Valid values:
Separate multiple protocol types with commas (,). Example: HTTP,HTTPS . |
RequestHttpMethod |
String |
Yes |
Yes |
The API request method. |
Default value: GET. Valid values:
- GET
- POST
- DELETE
- PUT
- HEADER
- TRACE
- PATCH
- OPTIONS
|
PostBodyDescription |
String |
No |
Yes |
The description of the request body. |
None. |
BodyFormat |
String |
No |
Yes |
The method used to transmit data to the server when a POST, PUT, or PATCH request is sent. |
Valid values:
This property takes effect when you set the RequestMode property to MAPPING. |
ServiceParametersMap syntax
"ServiceParametersMap": [
{
"RequestParameterName": String,
"ServiceParameterName": String
}
]
ServiceParametersMap properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
RequestParameterName |
String |
Yes |
Yes |
The name of the frontend request parameter. |
The value of this property must be included in RequestParameters and must match the value of the ApiParameterName property in RequestParameters. |
ServiceParameterName |
String |
Yes |
Yes |
The name of the backend service parameter. |
None. |
RequestParameters syntax
"RequestParameters": [
{
"ParameterType": String,
"Required": String,
"Description": String,
"DemoValue": String,
"MinLength": Integer,
"DefaultValue": String,
"RegularExpression": String,
"MaxValue": Integer,
"MinValue": Integer,
"JsonScheme": String,
"ApiParameterName": String,
"Location": String,
"DocShow": String,
"MaxLength": Integer,
"EnumValue": String,
"DocOrder": Integer
}
]
RequestParameters properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
ParameterType |
String |
Yes |
No |
The data type of the request parameter. |
Valid values:
- String
- Int
- Long
- Float
- Double
- Boolean
|
Required |
String |
Yes |
Yes |
Specifies whether the request parameter is required. |
Valid values:
|
ApiParameterName |
String |
Yes |
Yes |
The name of the request parameter. |
None. |
Location |
String |
Yes |
Yes |
The location of the request parameter. |
Valid values:
|
RegularExpression |
String |
No |
Yes |
The regular expression for parameter validation. This property takes effect only when you set the ParameterType property to String. |
None. |
Description |
String |
No |
Yes |
The description of the request parameter. |
None. |
DefaultValue |
String |
No |
Yes |
The default value of the request parameter. |
None. |
MaxLength |
Integer |
No |
Yes |
The maximum length of the request parameter. This property takes effect when you set the ParameterType property to String. |
None. |
MinLength |
Integer |
No |
Yes |
The minimum length of the request parameter. This property takes effect when you set the ParameterType property to String. |
None. |
MaxValue |
Integer |
No |
Yes |
The maximum value of the request parameter. This property takes effect when you set the ParameterType property to Int, Long, Float, or Double. |
None. |
MinValue |
Integer |
No |
Yes |
The minimum value of the request parameter. This property takes effect when you set the ParameterType property to Int, Long, Float, or Double. |
None. |
EnumValue |
String |
No |
Yes |
The hash values that can be entered when you set the ParameterType property to Int, Long, Float, Double, or String. |
Separate multiple values with commas (,), such as 1,2,3,4,9 and A,B,C,E,F . |
JsonScheme |
String |
No |
Yes |
The JSON schema used for JSON validation. This property takes effect when you set the ParameterType property to String. |
None. |
DocOrder |
Integer |
No |
Yes |
The sequence of the request parameter in the document. |
None. |
DocShow |
String |
No |
Yes |
Specifies whether the request parameter is public in the SDK or document of API Gateway. |
Valid values:
|
DemoValue |
String |
No |
Yes |
The sample value of the parameter. |
None. |
ConstParameters syntax
"ConstParameters": [
{
"ConstValue": String,
"ServiceParameterName": String,
"Description": String,
"Location": String
}
]
ConstParameters properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
Location |
String |
Yes |
Yes |
The location of the parameter. |
Default value: HEAD. Valid values:
|
ConstValue |
String |
Yes |
Yes |
The value of the parameter. |
None. |
ServiceParameterName |
String |
Yes |
Yes |
The name of the backend service parameter. |
None. |
Description |
String |
No |
Yes |
The description of the parameter. |
None. |
FunctionComputeConfig syntax
"FunctionComputeConfig": {
"FcRegionId": String,
"RoleArn": String,
"ServiceName": String,
"FunctionName": String,
"Qualifier": String,
"ContentTypeValue": String,
"ContentTypeCatagory": String,
"FcBaseUrl": String,
"FcType": String,
"Method": String,
"OnlyBusinessPath": Boolean,
"Path": String
}
FunctionComputeConfig properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
FcRegionId |
String |
No |
Yes |
The ID of the region where Function Compute resides. |
None. |
RoleArn |
String |
No |
Yes |
The Alibaba Cloud Resource Name (ARN) of the RAM role that is assigned to API Gateway to access Function Compute. |
None. |
ServiceName |
String |
No |
Yes |
The service name defined in Function Compute. |
None. |
FunctionName |
String |
No |
Yes |
The function name defined in Function Compute. |
None. |
Qualifier |
String |
No |
Yes |
The function alias defined in Function Compute. |
None. |
ContentTypeCatagory |
String |
No |
Yes |
The type of the ContentType header used when you call the backend service over HTTP. |
Default value: CLIENT. Valid values:
- DEFAULT: the default header type in API Gateway
- CUSTOM: a custom header type
- CLIENT: the ContentType header type of the client
|
ContentTypeValue |
String |
No |
Yes |
The value of the ContentType header when you set the ServiceProtocol property to HTTP and the ContentTypeCatagory property to DEFAULT or CUSTOM. |
None. |
FcBaseUrl |
String |
No |
Yes |
The URL of the trigger. |
The URL must start with http:// or https:// . |
FcType |
String |
No |
Yes |
The type of the function. |
Default value: FCEvent. Valid values:
|
Method |
String |
No |
Yes |
The HTTP request method. |
Default value: GET. Valid values:
- GET
- POST
- DELETE
- PUT
- HEAD
- PATCH
- OPTIONS
- ANY
|
OnlyBusinessPath |
Boolean |
No |
Yes |
Specifies whether to pass only the custom backend request path to the backend. |
Valid values:
|
Path |
String |
No |
Yes |
The backend request path. |
Parameters must be enclosed in brackets []. Example:/ getUserInfo / [userId] . |
MockHeaders syntax
"MockHeaders": [
{
"HeaderValue": String,
"HeaderName": String
}
]
MockHeaders properties
Property |
Type |
Required |
Editable |
Description |
Constraint |
HeaderName |
String |
Yes |
Yes |
The name of the header. |
None. |
HeaderValue |
String |
Yes |
Yes |
The value of the header. |
None. |
Return values
Fn::GetAtt
ApiId: the ID of the API operation.
Examples
YAML
format
ROSTemplateFormatVersion: '2015-09-01'
Description: Test ApiGateway Api
Parameters: {}
Resources:
RamRole:
Type: ALIYUN::RAM::Role
Properties:
RoleName: TestRole
Policies:
- PolicyName: TestPolicy
PolicyDocument:
Version: '1'
Statement:
- Action:
- fc:InvokeFunction
Resource:
- '*'
Effect: Allow
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- apigateway.aliyuncs.com
FCService:
Type: ALIYUN::FC::Service
Properties:
ServiceName: TestService
InternetAccess: true
Function:
Type: ALIYUN::FC::Function
DependsOn: FCService
Properties:
Handler: index.handler
Runtime: python3
Code:
SourceCode: "def handler(event, context):\n\treturn {'isBase64Encode': False, 'statusCode': 200, 'body': 'Hello World!', 'headers': {'Content-type': 'aplication/json'}}\n"
FunctionName: mytest
ServiceName:
Fn::GetAtt:
- FCService
- ServiceName
MemorySize: 128
Group:
Type: ALIYUN::ApiGateway::Group
Properties:
InstanceId: api-shared-vpc-001
GroupName: TestGroup
Api:
DependsOn:
- RamRole
- Group
Type: ALIYUN::ApiGateway::Api
Properties:
AppCodeAuthType: HEADER_QUERY
AuthType: APP
ServiceConfig:
FunctionComputeConfig:
fcRegionId:
Ref: ALIYUN::Region
qualifier: LATEST
roleArn:
Fn::GetAtt:
- RamRole
- Arn
serviceName:
Fn::GetAtt:
- FCService
- ServiceName
functionName:
Fn::GetAtt:
- Function
- FunctionName
ServiceProtocol: FunctionCompute
ContentTypeCatagory: CLIENT
RequestConfig:
RequestMode: MAPPING
RequestHttpMethod: POST
RequestProtocol: HTTP,HTTPS
RequestPath: /test
BodyFormat: FORM
ResultSample: ''
Visibility: PRIVATE
ResultType: JSON
ApiName: TestApi
GroupId:
Fn::GetAtt:
- Group
- GroupId
App:
Type: ALIYUN::ApiGateway::App
Properties:
Description: Test Create App
AppName: TestApp
Outputs: {}
JSON
format
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": "Test ApiGateway Api",
"Parameters": {
},
"Resources": {
"RamRole": {
"Type": "ALIYUN::RAM::Role",
"Properties": {
"RoleName": "TestRole",
"Policies": [
{
"PolicyName": "TestPolicy",
"PolicyDocument": {
"Version": "1",
"Statement": [
{
"Action": [
"fc:InvokeFunction"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
}
}
],
"AssumeRolePolicyDocument": {
"Version": "1",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"apigateway.aliyuncs.com"
]
}
}
]
}
}
},
"FCService": {
"Type": "ALIYUN::FC::Service",
"Properties": {
"ServiceName": "TestService",
"InternetAccess": true
}
},
"Function": {
"Type": "ALIYUN::FC::Function",
"DependsOn": "FCService",
"Properties": {
"Handler": "index.handler",
"Runtime": "python3",
"Code": {
"SourceCode": "def handler(event, context):\n\treturn {'isBase64Encode': False, 'statusCode': 200, 'body': 'Hello World!', 'headers': {'Content-type': 'aplication/json'}}\n"
},
"FunctionName": "mytest",
"ServiceName": {
"Fn::GetAtt": [
"FCService",
"ServiceName"
]
},
"MemorySize": 128
}
},
"Group": {
"Type": "ALIYUN::ApiGateway::Group",
"Properties": {
"InstanceId": "api-shared-vpc-001",
"GroupName": "TestGroup"
}
},
"Api": {
"DependsOn": [
"RamRole",
"Group"
],
"Type": "ALIYUN::ApiGateway::Api",
"Properties": {
"AppCodeAuthType": "HEADER_QUERY",
"AuthType": "APP",
"ServiceConfig": {
"FunctionComputeConfig": {
"fcRegionId": {
"Ref": "ALIYUN::Region"
},
"qualifier": "LATEST",
"roleArn": {
"Fn::GetAtt": [
"RamRole",
"Arn"
]
},
"serviceName": {
"Fn::GetAtt": [
"FCService",
"ServiceName"
]
},
"functionName": {
"Fn::GetAtt": [
"Function",
"FunctionName"
]
}
},
"ServiceProtocol": "FunctionCompute",
"ContentTypeCatagory": "CLIENT"
},
"RequestConfig": {
"RequestMode": "MAPPING",
"RequestHttpMethod": "POST",
"RequestProtocol": "HTTP,HTTPS",
"RequestPath": "/test",
"BodyFormat": "FORM"
},
"ResultSample": "",
"Visibility": "PRIVATE",
"ResultType": "JSON",
"ApiName": "TestApi",
"GroupId": {
"Fn::GetAtt": [
"Group",
"GroupId"
]
}
}
},
"App": {
"Type": "ALIYUN::ApiGateway::App",
"Properties": {
"Description": "Test Create App",
"AppName": "TestApp"
}
}
},
"Outputs": {
}
}
For more examples, visit Api.json and Api.yml. In the examples, the ALIYUN::ApiGateway::Api, ALIYUN::ApiGateway::App, ALIYUN::ApiGateway::Authorization, ALIYUN::ApiGateway::Deployment, ALIYUN::ApiGateway::Signature, ALIYUN::ApiGateway::SignatureBinding, ALIYUN::ApiGateway::TrafficControl, and ALIYUN::ApiGateway::TrafficControlBinding resource types are used.