Aliyun::Serverless::Api
Updated at:
Creates an API group and API in API Gateway and publishes the API to a specified environment.
Syntax
{
"Type": "Aliyun::Serverless::Api",
"Properties": {
"Name": String,
"StageName": String,
"DefinitionUri": String,
"DefinitionBody": Map
}
}
Properties
| Property | Type | Required | Editable | Description | Constraint |
| Name | String | No | Yes | The name of the API. | None |
| StageName | String | Yes | Yes | The target environment for API publishing. | Valid values:
|
| DefinitionBody | Map | No | Yes | The request body of the API. | Specify either DefinitionUri or DefinitionBody. For more information, see api-gateway. |
| DefinitionUri | String | No | Yes | The URL of the API request. | Specify either DefinitionUri or DefinitionBody. |
Return values
Fn::GetAtt
- ApiId: the API ID.
- SubDomain: the second-level domain assigned to the API group for testing.
- GroupId: the system-generated GUID of the API group.
Examples
JSON format
{
"ROSTemplateFormatVersion": "2015-09-01",
"Transform": "Aliyun::Serverless-2018-04-03",
"Resources": {
"MyService": {
"Type": "Aliyun::Serverless::Service",
"Properties": {},
"MyFunction": {
"Type": "Aliyun::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"Runtime": "nodejs8",
"CodeUri": "oss://transform-fvt/nodejs8.zip",
"Timeout": 60
}
}
},
"MyApi": {
"Type": "Aliyun::Serverless::Api",
"Properties": {
"StageName": "RELEASE",
"DefinitionBody": {
"/": {
"get": {
"x-aliyun-apigateway-api-name": "MyApiName",
"x-aliyun-apigateway-fc": {
"arn": "acs:fc:::services/${MyService.Arn}/functions/${MyFunction.Arn}/",
"timeout": 10000
},
"x-aliyun-apigateway-request-config": {
"requestMode": "MAPPING",
"requestProtocol": "http"
},
"x-aliyun-apigateway-request-parameters": [
{
"apiParameterName": "token",
"location": "Query",
"parameterType": "String",
"required": "REQUIRED"
},
{
"apiParameterName": "token2",
"location": "Query",
"parameterType": "String",
"required": "REQUIRED"
}
]
}
}
}
}
}
},
"Outputs": {
"GroupId": {
"Value": {
"Fn::GetAtt": [
"MyApi",
"GroupId"
]
}
},
"SubDomain": {
"Value": {
"Fn::GetAtt": [
"MyApi",
"SubDomain"
]
}
},
"ApiId": {
"Value": {
"Fn::GetAtt": [
"MyApiName",
"ApiId"
]
}
}
}
}
YAML format
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
MyService:
Type: 'Aliyun::Serverless::Service'
Properties: {}
MyFunction:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8
CodeUri: 'oss://transform-fvt/nodejs8.zip'
Timeout: 60
MyApi:
Type: 'Aliyun::Serverless::Api'
Properties:
StageName: RELEASE
DefinitionBody:
/:
get:
x-aliyun-apigateway-api-name: MyApiName
x-aliyun-apigateway-fc:
arn: 'acs:fc:::services/${MyService.Arn}/functions/${MyFunction.Arn}/'
timeout: 10000
x-aliyun-apigateway-request-config:
requestMode: MAPPING
requestProtocol: http
x-aliyun-apigateway-request-parameters:
- apiParameterName: token
location: Query
parameterType: String
required: REQUIRED
- apiParameterName: token2
location: Query
parameterType: String
required: REQUIRED
Outputs:
GroupId:
Value:
'Fn::GetAtt':
- MyApi
- GroupId
SubDomain:
Value:
'Fn::GetAtt':
- MyApi
- SubDomain
ApiId:
Value:
'Fn::GetAtt':
- MyApiName
- ApiId
Is this page helpful?