

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

# の API キーの例 AWS SAM
<a name="serverless-controlling-access-to-apis-keys"></a>

 AWS SAM テンプレート内で APIs キーを要求することで、API へのアクセスを制御できます。これを実行するには、[ApiAuth](sam-property-api-apiauth.md) データ型を使用します。

API キーの AWS SAM テンプレートセクションの例を次に示します。

```
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Auth:
        ApiKeyRequired: true # sets for all methods

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Handler: index.handler
      Runtime: nodejs12.x
      Events:
        ApiKey:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /
            Method: get
            Auth:
              ApiKeyRequired: true
```

詳細については、*API Gateway デベロッパーガイド*の「[API キーを使用した使用量プランの作成と使用](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)」を参照してください。