- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在以下场景中尝试使用 terraform api_gateway 进行 POC。
path=/demo/user(GET) -> 调用 lamda 函数 (hello)。
path=/demo/user/{id)(put) -> 调用 lamda 函数(测试)。
所以我在这里创建了以下资源
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "demo"
}
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "AWS_PROXY"
uri = "<lambda function arn>/invocation"
}
在 terraform apply 中,它正在/demo 下创建资源
但在这里我如何实现路径?
path=/demo/user(GET) -> 调用 lamda 函数 (hello)。
path=/demo/user/{id)(PUT) -> 调用 lamda 函数(测试)。
任何评论都将受到高度赞赏。
最佳答案
对于/demo/user (GET),您需要在“demo”下创建资源“user”,并添加“user”资源的集成。对于/demo/user/{id} (PUT),您需要在“user”下创建另一个资源“userId”,并添加“userId”资源的集成。
必须使用相应的 Lambda 函数为它们添加 Http 方法和 Lambda 集成。
更新后的代码如下所示。
# root resource
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
# demo resource (corresponding to path /demo)
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "demo"
}
# user resource (corresponding to path /demo/user)
resource "aws_api_gateway_resource" "MyDemoUserResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_resource.MyDemoResource.id
path_part = "user"
}
# adding GET method for path /demo/user
resource "aws_api_gateway_method" "MyDemoUserGetMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoUserResource.id
http_method = "GET"
authorization = "NONE"
}
# userId resource (corresponding to path /demo/user/{id})
resource "aws_api_gateway_resource" "MyDemoUserIdResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_resource.MyDemoUserResource.id
path_part = "{id}"
}
# adding PUT method for path /demo/user/{id}
resource "aws_api_gateway_method" "MyDemoUserIdPutMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoUserIdResource.id
http_method = "PUT"
authorization = "NONE"
}
# adding Lambda integration for GET at /demo/user
resource "aws_api_gateway_integration" "MyDemoUserIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoUserResource.id
http_method = aws_api_gateway_method.MyDemoUserGetMethod.http_method
type = "AWS_PROXY"
uri = "<lambda function arn>/invocation"
}
# adding Lambda integration for PUT at /demo/user/{id}
resource "aws_api_gateway_integration" "MyDemoUserIdIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoUserIdResource.id
http_method = aws_api_gateway_method.MyDemoUserIdPutMethod.http_method
type = "AWS_PROXY"
uri = "<lambda function arn>/invocation"
}
引用文献
关于amazon-web-services - terraform aws apigateway path_part,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69271797/
我在以下场景中尝试使用 terraform api_gateway 进行 POC。 path=/demo/user(GET) -> 调用 lamda 函数 (hello)。 path=/demo/us
我在以下场景中尝试使用 terraform api_gateway 进行 POC。 path=/demo/user(GET) -> 调用 lamda 函数 (hello)。 path=/demo/us
我是一名优秀的程序员,十分优秀!