amazon-web-services - DynamoDB 到 'vanilla' JSON

标签 amazon-web-services amazon-dynamodb aws-api-gateway

我开始使用 AWS 中的一些托管服务。一件看似简单的事情是使用 API 网关来保护和公开对 DynamoDB 的调用。

我已经成功了。然而,它似乎有点笨拙。 DynamoDB 返回如下内容:

{
  "id":{"N":"3"}
  // Lots of other fields
}

当我(以及大多数其他消费者)真的想要这样的东西时:

{
  "id":"3"
  // Lots of other fields
}

在我看来,我有两个选择。

1) 在 AWS API UI 中逐个字段添加响应映射。这看起来很费力并且容易出错:

#set($inputRoot = $input.path('$'))
{
   "Id": "$elem.Id.N"
    // Lots of other fields 
}

2) 在 API Gateway 和 Dynamo 之间编写一个特定的 lambda 来执行此映射。喜欢https://stackoverflow.com/a/42231827/2012130这增加了另一件事需要维护。

还有更好的办法吗?我错过了什么吗?看起来非常接近棒极了。

最佳答案

const AWS = require('aws-sdk');
var db = new AWS.DynamoDB.DocumentClient({
    region: 'us-east-1',
    apiVersion: '2012-08-10'
});

关于amazon-web-services - DynamoDB 到 'vanilla' JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46632780/

相关文章:

python - 显示多个实例的 RDS 指标

amazon-web-services - aws - 浏览网站 - 找不到 404 - 没有这样的桶

在 AWS CDK 代码中引用 Lambda 代码时出现 java.lang.ClassNotFoundException

amazon-web-services - AWS DynamoDB 如何计算 Query 的读取单元?

amazon-web-services - 是否可以通过 Cloudfront 对 API Gateway 进行 IAM 身份验证?

aws-cloudformation - 在 CloudFormation 模板中指定外部 EDGE 网关 ApiId 的格式是什么?

amazon-web-services - 使用 Iam 角色从 Autoscaling 组启动 EC2 节点

java - 如何将 DynamoDB 扫描结果添加到对象列表?

java - Spring Boot + DynamoDB 本地与 Docker : Connect to localhost:8000 failed

yaml - 无法在 AWS::ApiGateway::Model 资源的输出部分中引用 API