

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

# の IAM アクセス許可の例 AWS SAM
<a name="serverless-controlling-access-to-apis-permissions"></a>

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

IAM アクセス許可に を使用する AWS SAM テンプレートの例を次に示します。

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Description: 'API with IAM authorization'
      Auth:
        DefaultAuthorizer: AWS_IAM #sets AWS_IAM auth for all methods in this API
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: python3.10
      Events:
        GetRoot:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /
            Method: get
      InlineCode: |
        def handler(event, context):
          return {'body': 'Hello World!', 'statusCode': 200}
```

IAM 許可の詳細については、*API Gateway デベロッパーガイド*の「[API を呼び出すためのアクセスの制御](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html)」を参照してください。