APIゲートウェイエンドポイントからウェブサイトとして設定されたS3バケットをプロキシしようとしています。エンドポイントをコンソールを使用して正常に設定しましたが、CloudFormを使用して設定を再作成することができません。私は成功したバケットウェブサイトのルートを取得することができ、このテンプレートを使用してAWS ApiゲートウェイのプロキシリソースはCloudFormを使用していますか?
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スタックテンプレートを作ってみましたしかし、プロキシリソースは私に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"}
私が間違っている可能性がありますどのように追跡するために500
ことをデバッグするために、私はOを比較しましたか見当がつかない1つのCloudformを作成して(これは動作していない)コンソールで手動で作成したリソース上のaws apigateway get-resource
のutputリソースはまったく同じように見えます。しかし、get-method
の出力は微妙に異なります。私はCloudformを使用してそれらを正確に同じにすることはできません。
の作業方法の設定:
{
"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メソッドではなく、ここに空のオブジェクトがあります。 - 作業構成が機能設定は、コンソールに2を比較すると、すべての
でrequestModels
を持っていませんが私のCFの方法は、"requestModels": {},
を持っているすべての
responseParameters
を持っていませんが私のCFの方法は、"responseParameters": {},
を持っています彼らは一見まったく同じです。 私の知恵はここにあります:私は間違っていますか?これはCloudFormを使用して達成することが可能ですか?
APIゲートウェイコンソールでAPIの詳細ログを有効にしましたか?たぶんそれはあなたに詳細を与えることができます。 – arjabbar
私は自分のスタックを削除して、もう一度ゼロから持ち上げて、今は動作します。だから私は、私の出発点からこれまでの細かい調整を経て実際にはうまくいかなかったと思います。本当にそれを修飾することはできません。とにかく、この投稿はこれを設定する正しい方法を文書化しました:) –