AWS Api Gateway proxy resource using Cloudformation?

I am trying to proxy an S3 bucket configured as a website from an API gateway endpoint. I configured the endpoint successfully using the console, but I cannot recreate the configuration using Cloudformation.

After many trial and error and guesswork, I came up with the following CF stack template, which is pretty close to me:

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

Using this template, I can successfully get the root of the bucket website, but the proxy resource gives me 500:

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"}

I don't know how to debug this 500.

, , aws apigateway get-resource , ( ), , Cloudformation ( ). . 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"
}

:

  • responseTemplates "application/json": null. , null Cloudformation. CF- .
  • CF "responseParameters": {},, responseParameters
  • CF "requestModels": {},, requestModels

, .

: ? Cloudformation?

+4
1

: . . .

+1

Source: https://habr.com/ru/post/1690566/


All Articles