API Gateway에서 “Invalid mapping expression specified” 오류를 해결하려면 어떻게 해야 하나요?

2분 분량
0

AWS CloudFormation 팸플릿, OpenAPI 정의 또는 AWS Command Line Interface(AWS CLI) 명령을 사용하여 프록시 리소스가 포함된 Amazon API Gateway API를 생성했습니다. API에 URL 경로 파라미터를 추가하려고 하면 “Invalid mapping expression specified”라는 오류 메시지가 나타납니다.

간략한 설명

프록시 경로 파라미터 **{proxy+}**에 정의된 URL 경로 파라미터 매핑이 없는 경우 API Gateway는 “잘못된 매핑 표현식이 지정됨” 오류 메시지를 반환합니다.

이 문제를 해결하려면 API를 만드는 데 사용한 도구의 단계를 완료하세요.

해결 방법

CloudFormation 템플릿

AWS: :ApiGateway: :메서드 섹션의 RequestParameters 속성을 정의합니다.

다음 단계를 완료합니다.

  1. RequestParameters 값이 true로 설정되도록 CloudFormation 템플릿을 업데이트합니다.

    예제 템플릿:

    ....
    .
      ProxyMethod:
        Type: 'AWS::ApiGateway::Method'
        Properties:
          .
          .
          RequestParameters:
    
            method.request.path.proxy: true
    
          Integration:
            RequestParameters:
              integration.request.path.proxy: 'method.request.path.proxy'
    
            IntegrationHttpMethod: ANY
            .
            .
    ...
  2. API를 업데이트하려면 CloudFormation 템플릿을 사용하여 CloudFormation 스택을 업데이트하세요.

**참고:**API Gateway 리소스를 업데이트하는 방법에 대한 자세한 내용은 Amazon API Gateway 리소스 유형 레퍼런스를 참조하세요.

OpenAPI 정의

x-amazon-apigateway-any-method 객체에서 파라미터 섹션을 정의합니다.

다음 단계를 완료합니다.

  1. x-amazon-apigateway-any-method 섹션 아래의 파라미터가 다음 값을 갖도록 API 정의를 업데이트하세요.

          "x-amazon-apigateway-any-method": {                "parameters": [
              {
                "name": "proxy",
                "in": "path",
                "required": true,
                "type": "string"
              }
            ]
    
    ....
    
    ....
    
    }
  2. 업데이트된 API 정의 파일을 API Gateway로 가져와서 API를 업데이트합니다.

**참고:**자세한 내용을 알아보려면 Swagger 웹 사이트의 파라미터 설명을 참조하세요.

AWS CLI 명령

**참고:**AWS CLI 명령을 실행할 때 오류가 발생하면, AWS CLI 오류 문제 해결을 참조하세요. 또한 최신 AWS CLI 버전을 사용하고 있는지 확인하세요.

put-integration 명령을 실행하여 통합을 설정할 때 --request-parameters를 추가합니다.

  1. update-method 명령을 실행하여 HTTP 메서드의 메서드 요청 구성을 업데이트합니다.

    aws apigateway update-method \
        --rest-api-id <your-api-id> \
        --resource-id <your-resource-id> \
        --http-method <your-http-method> \
        --patch-operations op="add",path="/requestParameters/method.request.path.proxy",value="true"
  2. put-integration 명령을 실행하여**--request-parameters**가 있는 HTTP 메서드의 통합 요청 구성을 업데이트합니다. 예제 파라미터의 이름은 proxy이고 값은 method.request.path.proxy입니다. put-integration 명령은 VPC 링크HTTP_PROXY 통합을 설정합니다.

    aws apigateway put-integration \
        --rest-api-id <your-api-id>\
        --resource-id <your-resource-id> \
        --http-method <your-http-method> \
        --type HTTP_PROXY \
        --integration-http-method <your-integration-http-method> \
        --uri "<your-integration-endpoint-uri>" \
        --connection-type VPC_LINK \
        --connection-id <your-vpclink-connection-id> \
        --request-parameters "integration.request.path.proxy=method.request.path.proxy"

    참고: 모든 예제 값을 원하는 값으로 바꿉니다.

설정 테스트

다음 단계를 완료합니다.

  1. API Gateway 콘솔을 연 다음 API의 이름을 선택합니다.
  2. URL 경로 파라미터를 확장합니다.
    **참고:**프록시 경로 파라미터에 올바르게 정의된 URL 경로 파라미터 매핑이 포함된 경우 오류가 나타나지 않습니다.

관련 정보

x-amazon-apigateway-integration.requestParameters 객체

프록시 리소스와의 프록시 통합 설정

REST API를 위한 데이터 변환 설정

AWS 공식
AWS 공식업데이트됨 일 년 전