Я не совсем уверен, что не так с моей установкой aws api-gateway
. У меня есть два региона, которые я использую, один для моей среды (eu-west-1), а другой для моей жизни (us-east-1).AWS Api-Gateway неверный регион
Когда я строю и запускаю свой api в постановке, все работает отлично. Однако, когда я пытаюсь запустить свой апи в прямом эфире, я получаю следующее сообщение об ошибке:
{"message": "Internal server error"}
Чтобы попробовать и отладки это я запускал API с помощью функции «тест» в консоли AWS и выполняется запрос GET , К моему удивлению, я заметил, что регион в заголовке запроса был неправильным (eu-west-1 вместо us-east-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-gateway uri - us-east-1
.
https: //.execute-api. нас-восток-1 .amazonaws.com/прод
Я могу видеть, что мой заголовок запроса имеет: Host = лямбда. ес-запад 1 .amazonaws.com и на выходе у меня есть следующее свойство:
запроса Endpoint URI: https://lambda. ес-запад-1 .amazonaws.com/2015-03-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/"]]
}
}
}
}
Хорошее слежение. Это действительно заставило меня почесывать голову, потому что вы, казалось, описывали ситуацию, которая была бы невозможна. –