我正在尝试创建一个模板,以便当我调用 api/divide/inputvalue
时,api从 DynamoDB
发送回来对应于 inputvalue
映射的响应 .
它很直接,因为我直接从db获取值而没有任何业务逻辑,因此我不需要任何lambda . 但是我谷歌或所有教程的所有例子他们都在使用lambdas而我现在迷失了,我怎么能让它在没有lambda的情况下工作
这就是我到目前为止所拥有的 . 由于我没有在 ApiGateway::Method
中提供 Uri
,因此此模板中存在错误 . 这就是我目前所坚持的 .
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"Deployment": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": { "Ref": "restApiName" },
"Description": "First Deployment",
"StageName": "StagingStage"
},
"DependsOn" : ["restApiMethod"]
},
"restApiMethod": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
"HttpMethod": "GET",
"ResourceId": {"Ref": "apiRestResource"},
"RestApiId": {"Ref": "restApiName"},
"Integration": {
"Type": "AWS",
"IntegrationHttpMethod": "GET",
"IntegrationResponses": [{"StatusCode": 200}],
"Uri": { "Fn::Sub":"arn.aws.apigateway:${AWS::Region}:dynamodb:action/${restApiName.Arn}"}
},
"MethodResponses": [{"StatusCode": 200}]
},
"DependsOn": ["apiRestResource"]
},
"apiRestResource": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"RestApiId": {"Ref": "restApiName"},
"ParentId": {
"Fn::GetAtt": ["restApiName","RootResourceId"]
},
"PathPart": "divide"
},
"DependsOn": ["restApiName"]
},
"restApiName": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "CalculationApi"
}
}
}
}
1 回答
根据文档,对于
AWS
service-proxy集成类型,Uri属性的结构如下:uri API网关属性参考提供了更多详细信息:
对于调用Query Action的
dynamodb
服务的AWS服务代理,Uri
应该是这样的(使用Fn::Sub的YAML短格式为当前AWS区域插入Ref):至于使用API网关在不使用Lambda函数的情况下访问DynamoDB的更广泛用例,请参阅Andrew Baird的教程博客文章"Using Amazon API Gateway as a Proxy for DynamoDB",并将指定的管理控制台步骤转换为相应的CloudFormation模板资源 .