【问题标题】:AWS API Gateway how to get the time stamp in Integration Request > Body Mapping TemplatesAWS API Gateway 如何在集成请求 > 正文映射模板中获取时间戳
【发布时间】:2018-01-25 15:24:50
【问题描述】:

是否可以在集成请求的主体映射模板中检索 API 网关请求的时间戳,使其只能检索大于(或小于)创建日期的记录?

当前设置

API 网关 (GET) -> DynamoDB -- 响应 --> API 网关

身体映射模板

{
"TableName": "table-name-in-dynamodb",
"ScanFilter": {
  "creationDate": {
    "AttributeValueList": [ { "N":"TIMESTAMP_OF_THE_API_REQUEST" } ],
    "ComparisonOperator": "GT"
  }
}

}

我已经读到标题 X-Amzn-Trace-Id 可以用 $input.params('X-Amzn-Trace-Id') 检索,这将返回一个带有版本的字符串编号和时间戳。 AWS API Gateway - How do I get the date/timestamp/epoch in a body mapping template?

我对这一切还是很陌生,所以我不确定如何处理数据。

这可能吗?

【问题讨论】:

  • 这确实限制了 API Gateway 作为 Dynamo 的 CRUD 接口

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


【解决方案1】:

是的,这是可能的。你可以这样做:

身体映射模板

{
"TableName": "table-name-in-dynamodb",
"ScanFilter": {
  "creationDate": {
    "AttributeValueList": [ { "N":"$context.requestTimeEpoch" } ],
    "ComparisonOperator": "GT"
  }
}

但你必须知道$context.requestTimeEpoch 在测试环境中不起作用。 因此,您首先需要在使用 API 之前对其进行部署。

所有关于上下文变量的文档都可以在这里找到:https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

【讨论】:

    猜你喜欢
    • 2018-01-20
    • 2016-01-21
    • 2017-05-02
    • 1970-01-01
    • 2017-11-30
    • 2021-04-20
    • 1970-01-01
    • 2018-05-02
    • 2020-09-28
    相关资源
    最近更新 更多