

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

# Api
<a name="sam-property-function-api"></a>

描述`Api`事件來源類型的物件。如果已定義[AWS::Serverless::Api](sam-resource-api.md)資源，路徑和方法值必須對應至 API OpenAPI 定義中的 操作。

如果[AWS::Serverless::Api](sam-resource-api.md)未定義任何 ，則函數輸入和輸出代表 HTTP 請求和 HTTP 回應。

例如，使用 JavaScript API，可以透過傳回具有金鑰 statusCode 和內文的物件來控制回應statusCode和內文。

## 語法
<a name="sam-property-function-api-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-api-syntax.yaml"></a>

```
  [Auth](#sam-function-api-auth): ApiFunctionAuth
  [Method](#sam-function-api-method): String
  [Path](#sam-function-api-path): String
  [RequestModel](#sam-function-api-requestmodel): RequestModel
  [RequestParameters](#sam-function-api-requestparameters): List of [ String | RequestParameter ]
  [RestApiId](#sam-function-api-restapiid): String
  [ResponseTransferMode](#sam-function-api-responsetransfermode): String
  TimeoutInMillis: Integer
```

## Properties
<a name="sam-property-function-api-properties"></a>

 `Auth`   <a name="sam-function-api-auth"></a>
此特定 Api\$1Path\$1Method 的身分驗證組態。  
用於在未`DefaultAuthorizer`指定或覆寫預設設定時，覆寫個別路徑上 API `DefaultAuthorizer` `ApiKeyRequired`的設定身分驗證組態。  
*類型*：[ApiFunctionAuth](sam-property-function-apifunctionauth.md)  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `Method`   <a name="sam-function-api-method"></a>
叫用此函數的 HTTP 方法。選項包括 `DELETE`、`GET`、`HEAD`、`OPTIONS`、`PATCH`、`PUT`、 `POST`和 `ANY`。如需詳細資訊，請參閱《 ** [API Gateway 開發人員指南》中的設定 HTTP 方法](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-request.html#setup-method-add-http-method)。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `Path`   <a name="sam-function-api-path"></a>
叫用此函數的 Uri 路徑。必須以 開頭`/`。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `RequestModel`   <a name="sam-function-api-requestmodel"></a>
請求使用此特定 Api\$1Path\$1Method 的模型。這應該參考 [AWS::Serverless::Api](sam-resource-api.md) 資源 `Models`區段中指定的模型名稱。  
*類型*：[RequestModel](sam-property-function-requestmodel.md)  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `RequestParameters`   <a name="sam-function-api-requestparameters"></a>
請求此特定 Api\$1Path\$1Method 的參數組態。所有參數名稱都必須以 開頭`method.request.header`，`method.request`且必須限制為 `method.request.querystring`、 或 `method.request.path`。  
清單可以同時包含參數名稱字串和 [RequestParameter](sam-property-function-requestparameter.md) 物件。對於字串， `Required`和 `Caching` 屬性預設為 `false`。  
*類型*：【 String \$1 [RequestParameter](sam-property-function-requestparameter.md) 】 的清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `RestApiId`   <a name="sam-function-api-restapiid"></a>
RestApi 資源的識別符，必須包含具有指定路徑和方法的操作。一般而言，這會設定為參考此範本中定義的[AWS::Serverless::Api](sam-resource-api.md)資源。  
如果您未定義此屬性， 會使用產生的`OpenApi`文件 AWS SAM 建立預設[AWS::Serverless::Api](sam-resource-api.md)資源。該資源包含由相同範本中未指定 之`Api`事件定義的所有路徑和方法的聯集`RestApiId`。  
這無法參考另一個範本中定義的[AWS::Serverless::Api](sam-resource-api.md)資源。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

`ResponseTransferMode`  <a name="sam-function-api-responsetransfermode"></a>
Lambda 函數整合的回應傳輸模式。設定為 `RESPONSE_STREAM` 以透過 API Gateway 啟用 Lambda 回應串流，允許函數將回應串流回用戶端。設為 時`RESPONSE_STREAM`，API Gateway 會使用 Lambda InvokeWithResponseStreaming API。  
*類型：*字串  
*必要*：否  
*有效值*：`BUFFERED` \$1 `RESPONSE_STREAM`  
*CloudFormation 相容性*：此屬性會直接傳遞至 的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html#cfn-apigateway-method-integration-responsetransfermode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html#cfn-apigateway-method-integration-responsetransfermode) 屬性`AWS::ApiGateway::Method Integration`。

`TimeoutInMillis`  <a name="sam-function-api-timeoutinmillis"></a>
自訂介於 50 和 29,000 毫秒之間的逾時。  
當您指定此屬性時， 會 AWS SAM 修改您的 OpenAPI 定義。OpenAPI 定義必須使用 `DefinitionBody` 屬性內嵌指定。
*類型*：整數  
*必要*：否  
*預設*：29，000 毫秒或 29 秒  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有同等 CloudFormation 屬性。

## 範例
<a name="sam-property-function-api--examples"></a>

### 基本範例
<a name="sam-property-function-api--examples--apievent"></a>

#### YAML
<a name="sam-property-function-api--examples--apievent--yaml"></a>

```
Events:
  ApiEvent:
    Type: Api
    Properties:
      Path: /path
      Method: get
      RequestParameters:
        - method.request.header.Authorization
        - method.request.querystring.keyword:
            Required: true
            Caching: false
```

# ApiFunctionAuth
<a name="sam-property-function-apifunctionauth"></a>

為特定 API、路徑和方法設定事件層級的授權。

## 語法
<a name="sam-property-function-apifunctionauth-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-apifunctionauth-syntax.yaml"></a>

```
  [ApiKeyRequired](#sam-function-apifunctionauth-apikeyrequired): Boolean
  [AuthorizationScopes](#sam-function-apifunctionauth-authorizationscopes): List
  [Authorizer](#sam-function-apifunctionauth-authorizer): String
  [InvokeRole](#sam-function-apifunctionauth-invokerole): String
  OverrideApiAuth: Boolean
  [ResourcePolicy](#sam-function-apifunctionauth-resourcepolicy): ResourcePolicyStatement
```

## Properties
<a name="sam-property-function-apifunctionauth-properties"></a>

 `ApiKeyRequired`   <a name="sam-function-apifunctionauth-apikeyrequired"></a>
此 API、路徑和方法需要 API 金鑰。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 AWS SAM 是唯一的，並且沒有 CloudFormation 同等的。

 `AuthorizationScopes`   <a name="sam-function-apifunctionauth-authorizationscopes"></a>
要套用至此 API、路徑和方法的授權範圍。  
如果您已指定 屬性套用的任何範圍，您指定的範圍將會覆寫該`DefaultAuthorizer`屬性所套用的任何範圍。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 AWS SAM 是唯一的，並且沒有 CloudFormation 同等的。

 `Authorizer`   <a name="sam-function-apifunctionauth-authorizer"></a>
特定函數`Authorizer`的 。  
如果您為`AWS::Serverless::Api`資源指定了全域授權方，則可以將 `Authorizer`設定為 來覆寫授權方`NONE`。如需範例，請參閱 [覆寫 Amazon API Gateway REST API 的全域授權方](#sam-property-function-apifunctionauth--examples--override)。  
如果您使用 `AWS::Serverless::Api` 資源的 `DefinitionBody` 屬性來描述 API，則必須使用 `OverrideApiAuth`搭配 `Authorizer` 來覆寫您的全域授權方。如需詳細資訊，請參閱`OverrideApiAuth`。
*有效值*：`AWS_IAM`、 `NONE`或 AWS SAM 範本中定義之任何授權方的邏輯 ID。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性對 AWS SAM 是唯一的，並且沒有 CloudFormation 同等的。

 `InvokeRole`   <a name="sam-function-apifunctionauth-invokerole"></a>
指定`InvokeRole`用於`AWS_IAM`授權的 。  
*類型：*字串  
*必要*：否  
*預設*：`CALLER_CREDENTIALS`  
*CloudFormation 相容性*：此屬性對 AWS SAM 是唯一的，並且沒有 CloudFormation 同等屬性。  
*其他備註*：`CALLER_CREDENTIALS`映射至 `arn:aws:iam:::<user>/`，這會使用呼叫者登入資料來叫用端點。

`OverrideApiAuth`  <a name="sam-function-apifunctionauth-overrideapiauth"></a>
將 指定為 `true`以覆寫`AWS::Serverless::Api`資源的全域授權方組態。只有在您指定全域授權方並使用 `AWS::Serverless::Api` 資源的 屬性來描述 API 時，才需要此`DefinitionBody`屬性。  
當您將 指定`OverrideApiAuth`為 時`true`， AWS SAM 會使用為 `ApiKeyRequired`、 `Authorizer`或 提供的任何值來覆寫您的全域授權方`ResourcePolicy`。因此，使用 時，至少也必須指定其中一個屬性`OverrideApiAuth`。如需範例，請參閱 [指定 DefinitionBody for AWS::Serverless::Api 時覆寫全域授權方](#sam-property-function-apifunctionauth--examples--override2)。
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `ResourcePolicy`   <a name="sam-function-apifunctionauth-resourcepolicy"></a>
在 API 上設定此路徑的資源政策。  
*類型*：[ResourcePolicyStatement](sam-property-function-resourcepolicystatement.md)  
*必要*：否  
*CloudFormation 相容性*：此屬性對 AWS SAM 是唯一的，且沒有 CloudFormation 同等屬性。

## 範例
<a name="sam-property-function-apifunctionauth--examples"></a>

### Function-Auth
<a name="sam-property-function-apifunctionauth--examples--function-auth"></a>

下列範例會在函數層級指定授權。

#### YAML
<a name="sam-property-function-apifunctionauth--examples--function-auth--yaml"></a>

```
Auth:
  ApiKeyRequired: true
  Authorizer: NONE
```

### 覆寫 Amazon API Gateway REST API 的全域授權方
<a name="sam-property-function-apifunctionauth--examples--override"></a>

您可以為您的`AWS::Serverless::Api`資源指定全域授權方。以下是設定全域預設授權方的範例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
```

若要覆寫 AWS Lambda 函數的預設授權方，您可以將 指定`Authorizer`為 `NONE`。以下是範例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  ...
  MyFn:
    Type: AWS::Serverless::Function
    Properties:
      ...
      Events:
        LambdaRequest:
          Type: Api
          Properties:
            RestApiId: !Ref MyApiWithLambdaRequestAuth
            Method: GET
            Auth:
              Authorizer: NONE
```

### 指定 DefinitionBody for AWS::Serverless::Api 時覆寫全域授權方
<a name="sam-property-function-apifunctionauth--examples--override2"></a>

使用 `DefinitionBody` 屬性描述`AWS::Serverless::Api`資源時，先前的覆寫方法無法運作。以下是將 `DefinitionBody` 屬性用於 `AWS::Serverless::Api` 資源的範例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      DefinitionBody:
        swagger: 2.0
        ...
        paths:
          /lambda-request:
            ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
```

若要覆寫全域授權方，請使用 `OverrideApiAuth` 屬性。以下是使用 `OverrideApiAuth`以 提供的 值覆寫全域授權方的範例`Authorizer`：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      DefinitionBody:
        swagger: 2-0
        ...
        paths:
          /lambda-request:
            ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
    
    MyAuthFn:
      Type: AWS::Serverless::Function
      ...
    
    MyFn:
      Type: AWS::Serverless::Function
        Properties:
          ...
          Events:
            LambdaRequest:
              Type: Api
              Properties:
                RestApiId: !Ref MyApiWithLambdaRequestAuth
                Method: GET
                Auth:
                  Authorizer: NONE
                  OverrideApiAuth: true
                Path: /lambda-token
```

# ResourcePolicyStatement
<a name="sam-property-function-resourcepolicystatement"></a>

為 API 的所有方法和路徑設定資源政策。如需資源政策的詳細資訊，請參閱《 [API Gateway 開發人員指南》中的使用 API Gateway 資源政策控制對 API 的存取](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)。 **

## 語法
<a name="sam-property-function-resourcepolicystatement-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-resourcepolicystatement-syntax.yaml"></a>

```
  [AwsAccountBlacklist](#sam-function-resourcepolicystatement-awsaccountblacklist): List
  [AwsAccountWhitelist](#sam-function-resourcepolicystatement-awsaccountwhitelist): List
  [CustomStatements](#sam-function-resourcepolicystatement-customstatements): List
  [IntrinsicVpcBlacklist](#sam-function-resourcepolicystatement-intrinsicvpcblacklist): List
  [IntrinsicVpcWhitelist](#sam-function-resourcepolicystatement-intrinsicvpcwhitelist): List
  [IntrinsicVpceBlacklist](#sam-function-resourcepolicystatement-intrinsicvpceblacklist): List
  [IntrinsicVpceWhitelist](#sam-function-resourcepolicystatement-intrinsicvpcewhitelist): List
  [IpRangeBlacklist](#sam-function-resourcepolicystatement-iprangeblacklist): List
  [IpRangeWhitelist](#sam-function-resourcepolicystatement-iprangewhitelist): List
  [SourceVpcBlacklist](#sam-function-resourcepolicystatement-sourcevpcblacklist): List
  [SourceVpcWhitelist](#sam-function-resourcepolicystatement-sourcevpcwhitelist): List
```

## Properties
<a name="sam-property-function-resourcepolicystatement-properties"></a>

 `AwsAccountBlacklist`   <a name="sam-function-resourcepolicystatement-awsaccountblacklist"></a>
要封鎖 AWS 的帳戶。  
*類型*：字串的清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `AwsAccountWhitelist`   <a name="sam-function-resourcepolicystatement-awsaccountwhitelist"></a>
要允許 AWS 的帳戶。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型*：字串的清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `CustomStatements`   <a name="sam-function-resourcepolicystatement-customstatements"></a>
要套用至此 API 的自訂資源政策陳述式清單。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `IntrinsicVpcBlacklist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcblacklist"></a>
要封鎖的虛擬私有雲端 (VPCs) 清單，其中每個 VPC 指定為參考，例如[動態參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[內部函數](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `IntrinsicVpcWhitelist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcwhitelist"></a>
要允許的 VPCs 清單，其中每個 VPC 指定為參考，例如[動態參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[內部函數](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `IntrinsicVpceBlacklist`   <a name="sam-function-resourcepolicystatement-intrinsicvpceblacklist"></a>
要封鎖的 VPC 端點清單，其中每個 VPC 端點指定為參考，例如[動態參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[內部函數](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `IntrinsicVpceWhitelist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcewhitelist"></a>
要允許的 VPC 端點清單，其中每個 VPC 端點指定為參考，例如[動態參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[內部函數](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `IpRangeBlacklist`   <a name="sam-function-resourcepolicystatement-iprangeblacklist"></a>
要封鎖的 IP 地址或地址範圍。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `IpRangeWhitelist`   <a name="sam-function-resourcepolicystatement-iprangewhitelist"></a>
要允許的 IP 地址或地址範圍。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `SourceVpcBlacklist`   <a name="sam-function-resourcepolicystatement-sourcevpcblacklist"></a>
要封鎖的來源 VPC 或 VPC 端點。來源 VPC 名稱必須以 開頭`"vpc-"`，來源 VPC 端點名稱必須以 開頭`"vpce-"`。如需此屬性的範例使用方式，請參閱此頁面底部的範例區段。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `SourceVpcWhitelist`   <a name="sam-function-resourcepolicystatement-sourcevpcwhitelist"></a>
要允許的來源 VPC 或 VPC 端點。來源 VPC 名稱必須以 開頭`"vpc-"`，來源 VPC 端點名稱必須以 開頭`"vpce-"`。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

## 範例
<a name="sam-property-function-resourcepolicystatement--examples"></a>

### 資源政策範例
<a name="sam-property-function-resourcepolicystatement--examples--resource-policy-example"></a>

下列範例會封鎖兩個 IP 地址和來源 VPC，並允許 AWS 帳戶。

#### YAML
<a name="sam-property-function-resourcepolicystatement--examples--resource-policy-example--yaml"></a>

```
Auth:
  ResourcePolicy:
    CustomStatements: [{
                         "Effect": "Allow",
                         "Principal": "*",
                         "Action": "execute-api:Invoke",
                         "Resource": "execute-api:/Prod/GET/pets",
                         "Condition": {
                           "IpAddress": {
                             "aws:SourceIp": "1.2.3.4"
                           }
                         }
                       }]
    IpRangeBlacklist:
      - "10.20.30.40"
      - "1.2.3.4"
    SourceVpcBlacklist:
      - "vpce-1a2b3c4d"
    AwsAccountWhitelist:
      - "111122223333"
    IntrinsicVpcBlacklist:
      - "{{resolve:ssm:SomeVPCReference:1}}" 
      - !Ref MyVPC
    IntrinsicVpceWhitelist:
      - "{{resolve:ssm:SomeVPCEReference:1}}" 
      - !Ref MyVPCE
```

# RequestModel
<a name="sam-property-function-requestmodel"></a>

設定特定 Api\$1Path\$1Method 的請求模型。

## 語法
<a name="sam-property-function-requestmodel-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-requestmodel-syntax.yaml"></a>

```
  [Model](#sam-function-requestmodel-model): String
  [Required](#sam-function-requestmodel-required): Boolean
  [ValidateBody](#sam-function-requestmodel-validatebody): Boolean
  [ValidateParameters](#sam-function-requestmodel-validateparameters): Boolean
```

## Properties
<a name="sam-property-function-requestmodel-properties"></a>

 `Model`   <a name="sam-function-requestmodel-model"></a>
在 的模型屬性中定義的模型名稱[AWS::Serverless::Api](sam-resource-api.md)。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `Required`   <a name="sam-function-requestmodel-required"></a>
在指定 API 端點的 OpenApi 定義的參數區段中新增`required`屬性。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `ValidateBody`   <a name="sam-function-requestmodel-validatebody"></a>
指定 API Gateway 是否使用 `Model` 驗證請求內文。如需詳細資訊，請參閱《 [API Gateway 開發人員指南》中的在 API Gateway 中啟用請求驗證](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html)。 **  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `ValidateParameters`   <a name="sam-function-requestmodel-validateparameters"></a>
指定 API Gateway 是否使用 `Model` 驗證請求路徑參數、查詢字串和標頭。如需詳細資訊，請參閱《 [API Gateway 開發人員指南》中的在 API Gateway 中啟用請求驗證](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html)。 **  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

## 範例
<a name="sam-property-function-requestmodel--examples"></a>

### 請求模型
<a name="sam-property-function-requestmodel--examples--request-model"></a>

請求模型範例

#### YAML
<a name="sam-property-function-requestmodel--examples--request-model--yaml"></a>

```
RequestModel:
  Model: User
  Required: true
  ValidateBody: true
  ValidateParameters: true
```

# RequestParameter
<a name="sam-property-function-requestparameter"></a>

設定特定 Api\$1Path\$1Method 的請求參數。

請求參數需要指定 `Required`或 `Caching` 屬性

## 語法
<a name="sam-property-function-requestparameter-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-requestparameter-syntax.yaml"></a>

```
  [Caching](#sam-function-requestparameter-caching): Boolean
  [Required](#sam-function-requestparameter-required): Boolean
```

## Properties
<a name="sam-property-function-requestparameter-properties"></a>

 `Caching`   <a name="sam-function-requestparameter-caching"></a>
將 `cacheKeyParameters` 區段新增至 API Gateway OpenApi 定義  
*類型*：布林值  
*必要*：有條件  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `Required`   <a name="sam-function-requestparameter-required"></a>
此欄位指定是否需要參數  
*類型*：布林值  
*必要*：有條件  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

## 範例
<a name="sam-property-function-requestparameter--examples"></a>

### 請求參數
<a name="sam-property-function-requestparameter--examples--request-parameter"></a>

設定請求參數的範例

#### YAML
<a name="sam-property-function-requestparameter--examples--request-parameter--yaml"></a>

```
RequestParameters:
  - method.request.header.Authorization:
      Required: true
      Caching: true
```