我是亚马逊网络服务的新手,所以我会在这里写很多内容,因为我不确定是什么导致了我的问题。
我正在尝试使用亚马逊网络服务产品部署微服务应用程序。我的应用程序不会很大,所以我选择Lambdas作为计算“机器”(是的,它是无服务器的)。因为我有Java背景,所以我选择this示例作为我的样板。
到目前为止,我所做的是两个简单的服务,用于测试目的:
@RestController
@EnableWebMvc
public class PingPong {
@RequestMapping(path = "/ping", method = RequestMethod.GET)
public String ping() {
return "pong pong pong";
}
}
第二个具有相似的代码(唯一的区别是句子pong pong pong 2
)。
我的应用程序的yamls如下:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Ping2 application
Resources:
PingSecondFunction:
Type: AWS::Serverless::Function
Properties:
Handler: test.view.LambdaHandler::handleRequest
Runtime: java8
CodeUri: target/serverless-spring-example-1.0-SNAPSHOT.jar
MemorySize: 192
Policies: AWSLambdaBasicExecutionRole
Timeout: 20
Events:
GetResource:
Type: Api
Properties:
Path: /{proxy+}
Method: any
部署后(两者都有)我得到了两个lambdas和两个API。到目前为止,我能够对lambda执行测试(他们工作得很好)。我也可以通过“工作”端点(.execute-api.eu-central-1.amazonaws.com / Prod / ping)执行我的API。
当我尝试访问我的任何API(api.mydomain.com/ping1/ping)时,它们已经死了。
因此我决定查看CloudWatch日志,这是我能在那里找到的:
Endpoint request body after transformations: {"resource":"/{proxy+}","path":"/ping1/ping","httpMethod":"GET","headers":
显然我得到了404这样的请求。
我应该如何部署我的API以使它们在一个域下工作?
我梦想的配置是在以下服务API:
mydomain.com/apps/<api-name>/v1/ping
我选择了子域名,因为在mydomain.com
下我收到了来自S3的静态内容,我想避免在其中查找/apps
目录 - 换句话说,我想先让我的终端工作在任何终点下,然后开始对其他东西进行医生治疗)。
当然,我可以将我的映射写为@RequestMapping(path = "/ping1/ping")
,但我不想要这个解决方案。原因是,我希望保持我的服务紧凑(能够在任何URL下部署它们而无需更改代码)。
我无法通过AWS工具对我的API进行测试:
在进行这样的测试后我得到了500 "message": "Internal server error"
。在日志中我可以看到:
Wed Mar 22 19:12:26 UTC 2017 : Endpoint request body after transformations: {"resource":"/{proxy+}","path":"/ping","httpMethod":"GET","headers":null,"queryStringParameters":null,"pathParameters":{"proxy":"ping"},"stageVariables":null,"requestContext":{"accountId":"548199570266","resourceId":"eydd71","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"548199570266","cognitoIdentityId":null,"caller":"548199570266","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"ASIAJ5ZPFHH6DH42SZTQ","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::548199570266:root","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_112)","user":"548199570266"},"resourcePath":"/{proxy+}","httpMethod":"GET","apiId":"mckfbehxul"},"body":null,"isBase64Encoded":false}
我应该如何进行测试以避免这种情况?