

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

# 에 대한 사용자 지정 응답 예제 AWS SAM
<a name="serverless-controlling-access-to-apis-customize-response"></a>

귀하의 AWS SAM 템플릿 내에 응답 헤더를 정의하여 일부 API Gateway 오류 응답을 사용자 지정할 수 있습니다. 이렇게 하려면 [게이트웨이 응답 객체](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#gateway-response-object) 데이터 유형을 사용합니다.

다음은 `DEFAULT_5XX` 오류에 대한 사용자 지정 응답을 생성하는 예제 AWS SAM 템플릿입니다.

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      GatewayResponses:
        DEFAULT_5XX:
          ResponseParameters:
            Headers:
              Access-Control-Expose-Headers: "'WWW-Authenticate'"
              Access-Control-Allow-Origin: "'*'"
              ErrorHeader: "'MyCustomErrorHeader'"
          ResponseTemplates:
            application/json: "{\"message\": \"Error on the $context.resourcePath resource\" }"
              
  GetFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.10
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
          raise Exception('Check out the new response!')
      Events:
        GetResource:
          Type: Api
          Properties:
            Path: /error
            Method: get
            RestApiId: !Ref MyApi
```

API Gateway 응답에 대한 자세한 내용은 *API Gateway 개발자 안내서*의 [API Gateway에서의 게이트웨이 응답](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-gatewayResponse-definition.html)을 참조하세요.