Aliyun::Serverless::Api is used to create an API group and an API, and publish the API to a specified environment in API Gateway.

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 environment in which to publish the API. Valid values:
  • TEST: test environment
  • PRE: staging environment
  • RELEASE: production environment
DefinitionBody Map No Yes The request body of the API. You must specify one of the DefinitionUri and DefinitionBody parameters. For more information, visit api-gateway.
DefinitionUri String No Yes The URL of the API request. You must specify one of the DefinitionUri and DefinitionBody parameters.

Response parameters

Fn::GetAtt

  • ApiId: the ID of the created API.
  • SubDomain: the second-level domain that the system assigns to the API group. The domain is used to test the API call.
  • GroupId: the ID of the API group. The ID is a globally unique identifier (GUID) generated by the system.

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