

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

# HttpApiFunctionAuth
<a name="sam-property-function-httpapifunctionauth"></a>

イベントレベルでの認可を設定します。

特定の API とパスとメソッドの認証を設定します

## 構文
<a name="sam-property-function-httpapifunctionauth-syntax"></a>

 AWS Serverless Application Model (AWS SAM) テンプレートでこのエンティティを宣言するには、次の構文を使用します。

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

```
  [AuthorizationScopes](#sam-function-httpapifunctionauth-authorizationscopes): List
  [Authorizer](#sam-function-httpapifunctionauth-authorizer): String
```

## プロパティ
<a name="sam-property-function-httpapifunctionauth-properties"></a>

 `AuthorizationScopes`   <a name="sam-function-httpapifunctionauth-authorizationscopes"></a>
この API、パス、およびメソッドに適用する認可スコープです。  
ここにリストされているスコープは、`DefaultAuthorizer` によって適用されたスコープを上書きします (存在する場合)。  
*タイプ*: リスト  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは に固有 AWS SAM であり、 CloudFormation 同等のものはありません。

 `Authorizer`   <a name="sam-function-httpapifunctionauth-authorizer"></a>
特定の関数用の `Authorizer` です。IAM 認証を使用するには、 テンプレートの `Globals` セクションで `EnableIamAuthorizer` の `AWS_IAM` および `true` を指定します。  
API でグローバルオーソライザーを指定しており、特定の関数を公開する場合は、`Authorizer` を `NONE` に設定して上書きします。  
*タイプ*: 文字列  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは に固有 AWS SAM であり、 CloudFormation 同等のプロパティはありません。

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

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

関数レベルでの認可の指定

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

```
Auth:
  Authorizer: OpenIdAuth
  AuthorizationScopes:
    - scope1
    - scope2
```

### IAM 認可
<a name="sam-property-function-httpapifunctionauth--examples--iam-authorization"></a>

イベントレベルで IAM 認可を指定します。イベントレベルで `AWS_IAM` 認可を使用するには、テンプレートの `Globals` セクションで `EnableIamAuthorizer` の `true` を指定する必要もあります。詳細については、「[AWS SAM テンプレートのグローバルセクション](sam-specification-template-anatomy-globals.md)」を参照してください。

#### YAML
<a name="sam-property-function-httpapifunctionauth--examples--iam-authorization--yaml"></a>

```
Globals:
  HttpApi:
    Auth:
      EnableIamAuthorizer: true

Resources:
  HttpApiFunctionWithIamAuth:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: HttpApi
          Properties:
            Path: /iam-auth
            Method: GET
            Auth:
              Authorizer: AWS_IAM
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
          return {'body': 'HttpApiFunctionWithIamAuth', 'statusCode': 200}
      Runtime: python3.9
```