我正在尝试使用GET
方法在现有资源下创建子集合资源;类似的东西:
/customers/{customerId}/accounts
或/customers/{customerId}/accounts/{accountId}
使用Terraform,我已经设法创建了我的customers
和customers/{customerId}
资源 - 它们都有效。
但是当我尝试在customers/{customerId}
下添加资源时,我遇到了一个难以捉摸的Missing Authentication Token
错误(我开始学习的主要是API网关无法找到资源/实现/ lambda),即使一切似乎都正确连线。
示例代码:
resource "aws_api_gateway_resource" "customers" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_rest_api.my-api.root_resource_id}"
path_part = "customers"
}
resource "aws_api_gateway_resource" "single-customer" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_resource.customers.id}"
path_part = "{customerId}"
}
resource "aws_api_gateway_resource" "customers-accounts" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_resource.single-customer.id}"
path_part = "accounts"
}
//----
// GET
//----
resource "aws_api_gateway_method" "get-customers-accounts" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
resource_id = "${aws_api_gateway_resource.customers-accounts.id}"
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "get-customers-accounts-integration" {
content_handling = "CONVERT_TO_TEXT"
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
resource_id = "${aws_api_gateway_resource.customers-accounts.id}"
http_method = "${aws_api_gateway_method.get-customers-accounts.http_method}"
type = "AWS_PROXY"
uri = "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${var.region}:${var.account-id}:function:${var.customers-lambda}/invocations"
integration_http_method = "POST"
}
想法? lambda确实存在,一切看起来都在控制台中,我确实在API网关控制台中重新选择了lambda函数(如果你没有手动进入,那么AWS cli会出现错误,你将获得Missing Authentication Error
在控制台中重新选择你的lambda。
正如我所提到的,Terraform代码似乎有效 - 没有错误。我从尝试访问端点获得的文字消息是
{ message: "Missing Authentication Token" }
不输出日志。如果我尝试通过API网关测试按钮测试资源/端点,我会得到Malformed Lambda Proxy Response
- 但这会产生误导,因为许多有效的工作端点在从“测试”按钮运行时会生成相同的消息