2017-12-11 14 views
4

API 게이트웨이 끝점에서 웹 사이트로 구성된 S3 버킷을 프록시하려고합니다. 콘솔을 사용하여 끝점을 성공적으로 구성했지만 Cloudformation을 사용하여 구성을 다시 만들 수 없습니다. 나는 성공적으로 버킷 웹 사이트의 루트를 얻을 수있는이 템플릿을 사용하여CloudForm을 사용하는 AWS Api 게이트웨이 프록시 리소스는 무엇입니까?

Resources: 
    Api: 
    Type: 'AWS::ApiGateway::RestApi' 
    Properties: 
     Name: ApiDocs 

    Resource: 
    Type: 'AWS::ApiGateway::Resource' 
    Properties: 
     ParentId: !GetAtt Api.RootResourceId 
     RestApiId: !Ref Api 
     PathPart: '{proxy+}' 

    RootMethod: 
    Type: 'AWS::ApiGateway::Method' 
    Properties: 
     HttpMethod: ANY 
     ResourceId: !GetAtt Api.RootResourceId 
     RestApiId: !Ref Api 
     AuthorizationType: NONE 
     Integration: 
     IntegrationHttpMethod: ANY 
     Type: HTTP_PROXY 
     Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/' 
     PassthroughBehavior: WHEN_NO_MATCH 
     IntegrationResponses: 
      - StatusCode: 200 

    ProxyMethod: 
    Type: 'AWS::ApiGateway::Method' 
    Properties: 
     HttpMethod: ANY 
     ResourceId: !Ref Resource 
     RestApiId: !Ref Api 
     AuthorizationType: NONE 
     RequestParameters: 
     method.request.path.proxy: true 
     Integration: 
     CacheKeyParameters: 
      - 'method.request.path.proxy' 
     RequestParameters: 
      integration.request.path.proxy: 'method.request.path.proxy' 
     IntegrationHttpMethod: ANY 
     Type: HTTP_PROXY 
     Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/{proxy}' 
     PassthroughBehavior: WHEN_NO_MATCH 
     IntegrationResponses: 
      - StatusCode: 200 

    Deployment: 
    DependsOn: 
     - RootMethod 
     - ProxyMethod 
    Type: 'AWS::ApiGateway::Deployment' 
    Properties: 
     RestApiId: !Ref Api 
     StageName: dev 

:

시행 착오와 추측을 많이 후, 나는 아주 가까이 저를 얻는 다음 CF 스택 템플릿으로 왔어요

curl -i https://abcdef.execute-api.eu-west-1.amazonaws.com/dev/index.html 
HTTP/1.1 500 Internal Server Error 
Content-Type: application/json 
Content-Length: 36 
Connection: keep-alive 
Date: Mon, 11 Dec 2017 16:36:02 GMT 
x-amzn-RequestId: 6014a809-de91-11e7-95e4-dda6e24d156a 
X-Cache: Error from cloudfront 
Via: 1.1 8f6f9aba914cc74bcbbf3c57e10df26a.cloudfront.net (CloudFront) 
X-Amz-Cf-Id: TlOCX3eemHfY0aiVk9MLCp4qFzUEn5I0QUTIPkh14o6-nh7YAfUn5Q== 

{"message": "Internal server error"} 

내가 어떻게 500

잘못 될 것인가 추적하는 것을 디버깅하는 방법 아무 생각이 없다, 내가 비교 한 오 :하지만 프록시 자원은 500 나에게 준다 utlput aws apigateway get-resource의 자원 (내가 작동하고있는 콘솔)에서 수동으로 생성 한 하나의 Cloudform으로 만들었습니다 (그렇지 않습니다). 리소스는 정확히 비슷합니다. 그러나 get-method의 출력은 미묘하게 다르기 때문에 Cloudformation을 사용하여 정확하게 동일하게 만들 수 있는지 확신 할 수 없습니다.

작동 방법 구성 :

{ 
    "apiKeyRequired": false, 
    "httpMethod": "ANY", 
    "methodIntegration": { 
    "integrationResponses": { 
     "200": { 
     "responseTemplates": { 
      "application/json": null 
     }, 
     "statusCode": "200" 
     } 
    }, 
    "passthroughBehavior": "WHEN_NO_MATCH", 
    "cacheKeyParameters": [ 
     "method.request.path.proxy" 
    ], 
    "requestParameters": { 
     "integration.request.path.proxy": "method.request.path.proxy" 
    }, 
    "uri": "http://muybucket.s3-website-eu-west-1.amazonaws.com/{proxy}", 
    "httpMethod": "ANY", 
    "cacheNamespace": "abcdefg", 
    "type": "HTTP_PROXY" 
    }, 
    "requestParameters": { 
    "method.request.path.proxy": true 
    }, 
    "authorizationType": "NONE" 
} 

구성 작동하지 않습니다

{ 
    "apiKeyRequired": false, 
    "httpMethod": "ANY", 
    "methodIntegration": { 
     "integrationResponses": { 
      "200": { 
       "responseParameters": {}, 
       "responseTemplates": {}, 
       "statusCode": "200" 
      } 
     }, 
     "passthroughBehavior": "WHEN_NO_MATCH", 
     "cacheKeyParameters": [ 
      "method.request.path.proxy" 
     ], 
     "requestParameters": { 
      "integration.request.path.proxy": "method.request.path.proxy" 
     }, 
     "uri": "http://mybucket.s3-website-eu-west-1.amazonaws.com/{proxy}", 
     "httpMethod": "ANY", 
     "requestTemplates": {}, 
     "cacheNamespace": "abcdef", 
     "type": "HTTP_PROXY" 
    }, 
    "requestParameters": { 
     "method.request.path.proxy": true 
    }, 
    "requestModels": {}, 
    "authorizationType": "NONE" 
} 

의 차이 :

  • 작업 구성이 "application/json": null-responseTemplates 세트가 있습니다. 지금까지 내가 알 수있는 것처럼, 구름 형성을 사용하여 null으로 명시 적으로 매핑을 설정할 수있는 방법이 없습니다. 내 CF 메서드 대신 여기에 빈 개체가 있습니다. 작업 구성이 콘솔에서 두 개의 비교 모든

에서 requestModels이없는 상태에서 작업 구성이, 내 CF 방법은 "requestModels": {},을 가지고 모든

  • 에서 responseParameters이없는 동안
  • 내 CF 방법은 "responseParameters": {},있다 , 그들은 분명히 똑같습니다.

    여기 내 재치가 끝났습니다. 내가 뭘 잘못하고 있니? CloudForm을 사용하여이를 달성 할 수 있습니까?

  • +0

    API 게이트웨이 콘솔에서 API에 대한 자세한 로깅을 설정해 보셨습니까? 어쩌면 그것은 당신에게 더 많은 세부 사항을 줄 수 있습니다. – arjabbar

    +0

    어휴, 그래서 내 스택을 삭제하고 처음부터 다시 한 번 올렸지 만 이제는 작동합니다. 그래서 제 시작점에서부터 약간의 미세 조정을 거쳐이 작업으로가는 것이 실제로 효과가 없었던 것 같습니다. 정말 자격이 없습니다. 어쨌든,이 게시물은 이제 이것을 설정하는 올바른 방법을 문서화합니다 :) –

    답변

    1

    답변 : 위 내용은 정확합니다. 일련의 단계를 거쳐이 솔루션에 도달했고 템플릿을 반복해서 반복 적용했습니다. 이 구성으로 스택을 삭제하고 새 스택을 배치하면 원하는 효과를 얻을 수 있습니다.