aws api-gateway
の設定に何が問題なのかよく分かりません。私は私のステージング(eu-west-1)環境用と私のライブ(us-east-1)環境用の2つの領域を使用しています。AWS Api-Gatewayの間違った領域
ステージングでAPIをビルドして実行すると、すべて正常に動作します。しかし、私はライブに私のAPIを実行しようとすると、私は次のエラーを取得する:
{"message": "Internal server error"}
これを試してみて、デバッグするために、私はAWSコンソールに「テスト」機能を使用してAPIを実行し、GETリクエストを行いました。私の驚いたことに、私はリクエストヘッダーの領域が間違っていたことに気づいた(私たちの代わりに東西-1)。また、テストは502応答で、次のメッセージを返しました:
{"Message":"Functions from 'us-east-1' are not reachable in this region ('eu-west-1')","Type":"User"}
eu-west-1
地域で実行されていることを意味していますか?
コンソールで自分の地域をチェックすると、テストを実行するときに私は明らかにus-east-1
になっています。また、私のAPIゲートウェイURIの領域はus-east-1
です。
https://.execute-api。 たち-東-1 .amazonaws.com/PROD
私は私のリクエストヘッダを持っていることがわかります。ホスト=ラムダを。 EU-西-1 .amazonaws.com と出力の私は、次のプロパティがあります。
エンドポイントのリクエストURI:https://lambda。 EU-西-1 .amazonaws.com/2015年3月31日/機能/ ARN:AWS:ラムダ:たち-東-1 ::機能:/呼び出し
私はなぜ私の見当がつかない地域が混在している!私はそれが私のビルドプロセスと関係があるかもしれないと思ったが、すべてをダブルチェックした後、何が原因か分かりませんでした。私は目の新鮮なセットが何かを拾うことができると期待しています!
私のAPIをビルドするには、swagger.yamlファイルとcloudformation.jsonファイルの組み合わせを使用します。
SWAGGER: このファイルには、ファイルをawsに送信する前にノードスクリプトの実行を置き換えるプレースホルダがあります。
---
swagger: 2.0
info:
title: ServerlessExpress
basePath: /YOUR_API_GATEWAY_STAGE
schemes:
- https
paths:
/:
x-amazon-apigateway-any-method:
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
uri: arn:aws:apigateway:YOUR_AWS_REGION:lambda:path/2015-03-31/functions/arn:aws:lambda:YOUR_AWS_REGION:YOUR_ACCOUNT_ID:function:api-gateway-service/invocations
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
options:
consumes:
- application/json
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
/{proxy+}:
x-amazon-apigateway-any-method:
produces:
- application/json
parameters:
- name: proxy
in: path
required: true
type: string
responses: {}
x-amazon-apigateway-integration:
uri: arn:aws:apigateway:YOUR_AWS_REGION:lambda:path/2015-03-31/functions/arn:aws:lambda:YOUR_AWS_REGION:YOUR_ACCOUNT_ID:function:api-gateway-service/invocations
httpMethod: POST
type: aws_proxy
options:
consumes:
- application/json
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
definitions:
Empty:
type: object
title: Empty Schema
CLOUDFORMATION:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS Serverless Express.",
"Parameters": {
"AwsServerlessExpressS3Bucket": {
"Type": "String",
"Description": "The S3 bucket in which the lambda function code is stored. Bucket names are region-unique, so you must change this."
},
"LambdaFunctionS3Key": {
"Type": "String",
"AllowedPattern": ".*\\.zip",
"Description": "The S3 object for the lambda function code package.",
"Default": "lambda-function.zip"
},
"ApiGatewaySwaggerS3Key": {
"Type": "String",
"AllowedPattern": ".*\\.yaml",
"Description": "The S3 object for the swagger definition of the API Gateway API.",
"Default": "simple-proxy-api.yaml"
}
},
"Resources": {
"ApiGatewayApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Description": "AWS Serverless Express API",
"BodyS3Location": {
"Bucket": {
"Ref": "ServerlessExpressBucket"
},
"Key": {
"Ref": "ApiGatewaySwaggerS3Key"
}
}
}
},
"ApiGatewayApiDeployment": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"StageName": "YOUR_API_GATEWAY_STAGE"
}
},
"LambdaApiGatewayExecutionPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": ["LambdaFunction", "Arn"]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Join": ["", ["arn:aws:execute-api:", {
"Ref": "AWS::Region"
}, ":", {
"Ref": "AWS::AccountId"
}, ":", {
"Ref": "ApiGatewayApi"
}, "/*/*"]]
}
}
},
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "ServerlessExpressBucket"
},
"S3Key": {
"Ref": "LambdaFunctionS3Key"
}
},
"FunctionName": "api-gateway-service",
"Handler": "lambda.serverlessExpress",
"Description": "Service running on api-gateway",
"MemorySize": 128,
"Role": {
"Fn::Join": ["", ["arn:aws:iam::", {
"Ref": "AWS::AccountId"
}, ":role/service-lambda"]]
},
"Runtime": "nodejs4.3",
"Timeout": 30
}
}
},
"Outputs": {
"LambdaFunctionConsoleUrl": {
"Description": "Console URL for the Lambda Function.",
"Value": {
"Fn::Join": ["", ["https://", {
"Ref": "AWS::Region"
}, ".console.aws.amazon.com/lambda/home?region=", {
"Ref": "AWS::Region"
}, "#/functions/", {
"Ref": "LambdaFunction"
}]]
}
},
"ApiGatewayApiConsoleUrl": {
"Description": "Console URL for the API Gateway API's Stage.",
"Value": {
"Fn::Join": ["", ["https://", {
"Ref": "AWS::Region"
}, ".console.aws.amazon.com/apigateway/home?region=", {
"Ref": "AWS::Region"
}, "#/apis/", {
"Ref": "ApiGatewayApi"
}, "/stages/YOUR_API_GATEWAY_STAGE"]]
}
},
"ApiUrl": {
"Description": "Invoke URL for your API. Clicking this link will perform a GET request on the root resource of your API.",
"Value": {
"Fn::Join": ["", ["https://", {
"Ref": "ApiGatewayApi"
}, ".execute-api.", {
"Ref": "AWS::Region"
}, ".amazonaws.com/YOUR_API_GATEWAY_STAGE/"]]
}
}
}
}
良いsleuthing。これは本当に私の頭を傷つけていました。なぜなら、あなたは不可能であったはずの状況を説明しているようでした。 –