AWS 匯入應用程式介面的變數 - Amazon API Gateway

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

AWS 匯入應用程式介面的變數

您可以在 OpenAPI 定義中使用下列 AWS 變數。API Gateway 會在匯入 API 時解析變數。若要指定變數,請使用 ${variable-name}

AWS 變數
變數名稱 描述
AWS::AccountId 匯入 API 的 AWS 帳戶識別碼,例如 123456789012。
AWS::Partition 匯入 API 所在的 AWS 分割區。對於標準 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