AWS 用於開啟API匯入的變數 - Amazon API 网关

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS 用於開啟API匯入的變數

您可以在 Open API 定義中使用下列 AWS 變數。API閘道會在匯入時解API析變數。若要指定變數,請使用 ${variable-name}。下表說明可用的 AWS 變數。

變數名稱 描述
AWS::AccountId 匯入的 AWS 帳號 ID API。例如,如:123456789012。
AWS::Partition 匯入的 AWS API分割區。對於標準 AWS 區域,分區是aws
AWS::Region 在其中匯入API的 AWS 區域。例如 us-east-2

AWS 變量示例

下列範例會使用 AWS 變數來指定整合的 AWS Lambda 函數。

OpenAPI 3.0
openapi: "3.0.1" info: title: "tasks-api" version: "v1.0" paths: /: get: summary: List tasks description: Returns a list of tasks responses: 200: description: "OK" content: application/json: schema: type: array items: $ref: "#/components/schemas/Task" 500: description: "Internal Server Error" content: {} x-amazon-apigateway-integration: uri: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:LambdaFunctionName/invocations responses: default: statusCode: "200" passthroughBehavior: "when_no_match" httpMethod: "POST" contentHandling: "CONVERT_TO_TEXT" type: "aws_proxy" components: schemas: Task: type: object properties: id: type: integer name: type: string description: type: string