

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 에 대한 Lambda 권한 부여자 예제 AWS SAM
<a name="serverless-controlling-access-to-apis-lambda-authorizer"></a>

`AWS::Serverless::Api` 리소스 유형은 두 가지 유형의 Lambda 권한 부여자, 즉 `TOKEN` 권한 부여자와 `REQUEST` 권한 부여자를 지원합니다. `AWS::Serverless::HttpApi`리소스 유형은 `REQUEST` 권한 부여자만 지원합니다. 다음은 각 유형의 예입니다.

## Lambda `TOKEN` 권한 부여자 예제(AWS::Serverless::Api)
<a name="serverless-controlling-access-to-apis-lambda-token-authorizer"></a>

 AWS SAM 템플릿 내에 Lambda `TOKEN` 권한 부여자를 정의하여 APIs에 대한 액세스를 제어할 수 있습니다. 이 작업을 수행하려면 [ApiAuth](sam-property-api-apiauth.md) 데이터 유형을 사용합니다. 

다음은 Lambda `TOKEN` 권한 부여자에 대한 예제 AWS SAM 템플릿 섹션입니다.

**참고**  
다음 예제에서는 SAM `FunctionRole`이 암시적으로 생성됩니다.

```
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Auth:
        DefaultAuthorizer: MyLambdaTokenAuthorizer
        Authorizers:
          MyLambdaTokenAuthorizer:
            FunctionArn: !GetAtt MyAuthFunction.Arn

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: index.handler
      Runtime: nodejs12.x
      Events:
        GetRoot:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /
            Method: get

  MyAuthFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: authorizer.handler
      Runtime: nodejs12.x
```

Lambda 권한 부여자에 대한 자세한 내용은 *API Gateway 개발자 안내서*의 [API Gateway Lambda 권한 부여자 사용](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html)을 참조하세요.

## Lambda `REQUEST` 권한 부여자 예제(AWS::Serverless::Api)
<a name="serverless-controlling-access-to-apis-lambda-request-authorizer"></a>

 AWS SAM 템플릿 내에 Lambda `REQUEST` 권한 부여자를 정의하여 APIs에 대한 액세스를 제어할 수 있습니다. 이 작업을 수행하려면 [ApiAuth](sam-property-api-apiauth.md) 데이터 유형을 사용합니다. 

다음은 Lambda `REQUEST` 권한 부여자에 대한 예제 AWS SAM 템플릿 섹션입니다.

```
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Auth:
        DefaultAuthorizer: MyLambdaRequestAuthorizer
        Authorizers:
          MyLambdaRequestAuthorizer:
            FunctionPayloadType: REQUEST
            FunctionArn: !GetAtt MyAuthFunction.Arn
            Identity:
              QueryStrings:
                - auth

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: index.handler
      Runtime: nodejs12.x
      Events:
        GetRoot:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /
            Method: get

  MyAuthFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: authorizer.handler
      Runtime: nodejs12.x
```

Lambda 권한 부여자에 대한 자세한 내용은 *API Gateway 개발자 안내서*의 [API Gateway Lambda 권한 부여자 사용](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html)을 참조하세요.

## Lambda 권한 부여자 예제(AWS::Serverless::HttpApi)
<a name="serverless-controlling-access-to-apis-lambda-authorizer-httpapi"></a>

 AWS SAM 템플릿 내에 Lambda 권한 부여자를 정의하여 HTTP APIs에 대한 액세스를 제어할 수 있습니다. 이 작업을 수행하려면 [HttpApiAuth](sam-property-httpapi-httpapiauth.md) 데이터 유형을 사용합니다. 

다음은 Lambda 권한 부여자에 대한 예제 AWS SAM 템플릿 섹션입니다.

```
Resources:
  MyApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: Prod
      Auth:
        DefaultAuthorizer: MyLambdaRequestAuthorizer
        Authorizers:
          MyLambdaRequestAuthorizer:
            FunctionArn: !GetAtt MyAuthFunction.Arn
            FunctionInvokeRole: !GetAtt MyAuthFunctionRole.Arn
            Identity:
              Headers:
                - Authorization
            AuthorizerPayloadFormatVersion: 2.0
            EnableSimpleResponses: true

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: index.handler
      Runtime: nodejs12.x
      Events:
        GetRoot:
          Type: HttpApi
          Properties:
            ApiId: !Ref MyApi
            Path: /
            Method: get
            PayloadFormatVersion: "2.0"

  MyAuthFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: authorizer.handler
      Runtime: nodejs12.x
```