

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

# AWS OpenAPI 匯入的 變數
<a name="import-api-aws-variables"></a>

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


| 變數名稱 | Description | 
| --- | --- | 
| AWS::AccountId | 匯入 API AWS 的帳戶 ID。例如：123456789012。 | 
| AWS::Partition | 匯入 API 的 AWS 分割區。對於標準 AWS 區域，分割區為 aws。 | 
| AWS::Region | 匯入 API AWS 的區域。例如 us-east-2。 | 

## AWS 變數範例
<a name="import-api-aws-variables-example"></a>

下列範例使用 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
```

------