用于 OpenAPI 导入的 AWS 变量 - Amazon API Gateway

用于 OpenAPI 导入的 AWS 变量

您可以在 OpenAPI 定义中使用以下 AWS 变量。API Gateway 在导入 API 时解析变量。要指定变量,请使用 ${variable-name}

AWS 变量
变量名称 说明
AWS::AccountId 导入 API 的 AWS 账户 ID(例如,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