

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 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}}
```

## プロパティ
<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 を記述する場合は、`Authorizer` で `OverrideApiAuth` を使用してグローバルオーソライザーをオーバーライドする必要があります。詳細については「`OverrideApiAuth`」を参照してください。
*有効な値*: テンプレートで定義されているオーソライザーの`AWS_IAM``NONE`論理 ID AWS SAM 。  
*タイプ*: 文字列  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは に AWS SAM 固有であり、 CloudFormation 同等のプロパティはありません。

 `InvokeRole`   <a name="sam-function-apifunctionauth-invokerole"></a>
`AWS_IAM` 認可に使用する `InvokeRole` を指定します。  
*タイプ*: 文字列  
*必須:* いいえ  
*デフォルト*: `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` リソースの `DefinitionBody` プロパティを使用して API を記述する場合にのみ必要です。  
`OverrideApiAuth` として を指定すると`true`、 AWS SAM は `ApiKeyRequired`、、`Authorizer`または に指定された値でグローバルオーソライザーを上書きします`ResourcePolicy`。したがって、`OverrideApiAuth` を使用するときには、これらのプロパティを少なくとも 1 つ指定する必要もあります。例については、[AWS:: Serverless:: Apiの DefinitionBody が指定されている場合にグローバルオーソライザーをオーバーライドする](#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
```

### AWS:: Serverless:: Apiの DefinitionBody が指定されている場合にグローバルオーソライザーをオーバーライドする
<a name="sam-property-function-apifunctionauth--examples--override2"></a>

`DefinitionBody` プロパティを使用して `AWS::Serverless::Api` リソースを記述する場合、以前のオーバーライドメソッドは機能しません。以下は、`AWS::Serverless::Api` リソースの `DefinitionBody` プロパティを使用する例です。

```
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
```