amazon web services——AWS网关API无法将数组中的DynamoDb JSON转换为常规JSON



我试图创建一个从dynamo db数据库输出json的服务。然而,在amazon gateway api中实现主体映射模板之后,该服务只将dynamodb json的部分转换为常规json。日志中没有可见的错误。我在下面附上了主体映射模板,以及GET的响应主体。

Body Mapping Template:

    #set($inputRoot = $input.path('$'))
    #foreach($elem in $inputRoot.Items) {
        "accession" : "$elem.accession.S",
        "entryName" : "$elem.entryName.S",
        "sequence" : "$elem.sequence.S",
        "sequenceChecksum" : "$elem.sequenceChecksum.S",
        "taxid" : "$elem.taxid.N",
        "features" : "$elem.features.L"
    } #if($foreach.hasNext),#end
    #end

反应:

 {
   "accession" : "P05067",
   "entryName" : "A4_HUMAN",
   "sequence" : "MLPGLALLLLAAWTARALEVPTDGNAGLLAEPQIAMFCGRLNMHMNVQNGKWDSDPSGTKTCIDTKEGILQYCQEVYPELQITNVVEANQPVTIQNWCKRGRKQCKTHPHFVIPYRCLVGEFVSDALLVPDKCKFLHQERMDVCETHLHWHTVAKETCSEKSTNLHDYGMLLPCGIDKFRGVEFVCCPLAEESDNVDSADAEEDDSDVWWGGADTDYADGSEDKVVEVAEEEEVAEVEEEEADDDEDDEDGDEVEEEAEEPYEEATERTTSIATTTTTTTESVEEVVREVCSEQAETGPCRAMISRWYFDVTEGKCAPFFYGGCGGNRNNFDTEEYCMAVCGSAMSQSLLKTTQEPLARDPVKLPTTAASTPDAVDKYLETPGDENEHAHFQKAKERLEAKHRERMSQVMREWEEAERQAKNLPKADKKAVIQHFQEKVESLEQEAANERQQLVETHMARVEAMLNDRRRLALENYITALQAVPPRPRHVFNMLKKYVRAEQKDRQHTLKHFEHVRMVDPKKAAQIRSQVMTHLRVIYERMNQSLSLLYNVPAVAEEIQDEVDELLQKEQNYSDDVLANMISEPRISYGNDALMPSLTETKTTVELLPVNGEFSLDDLQPWHSFGADSVPANTENEVEPVDARPAADRGLTTRPGSGLTNIKTEEISEVKMDAEFRHDSGYEVHHQKLVFFAEDVGSNKGAIIGLMVGGVVIATVIVITLVMLKKKQYTSIHHGVVEVDAAVTPEERHLSKMQQNGYENPTYKFFEQMQN",
   "sequenceChecksum" : "A12EE761403740F5",
   "taxid" : "9606",
   "features" : "[{"M":{"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":" "},"type":"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"Amyloid beta A4 protein"},"type":{"S":"CHAIN"},"end":{"S":"770"},"begin":{"S":"18"}}},{"M":{"ftId":{"S":"PRO_0000000089"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"Soluble APP-alpha"},"type":{"S":"CHAIN"},"end":{"S":"687"},"begin":{"S":"18"}}},{"M":{"ftId":{"S":"PRO_0000000090"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"Soluble APP-beta"},"type":{"S":"CHAIN"},"end":{"S":"671"},"begin":{"S":"18"}}},{"M":{"ftId":{"S":"PRO_0000381966"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"N-APP"},"type":{"S":"CHAIN"},"end":{"S":"286"},"begin":{"S":"18"}}},{"M":{"ftId":{"S":"PRO_0000000091"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"C99"},"type":{"S":"CHAIN"},"end":{"S":"770"},"begin":{"S":"672"}}},{"M":{"ftId":{"S":"PRO_0000000092"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"Beta-amyloid protein 42"},"type":{"S":"CHAIN"},"end":{"S":"713"},"begin":{"S":"672"}}}]"
        }         
Response Headers
{"Content-Type":"application/json"}
Logs
Execution log for request test-request
Mon Aug 08 15:26:05 UTC 2016 : Starting execution for request: test-invoke-request
Mon Aug 08 15:26:05 UTC 2016 : HTTP Method: GET, Resource Path: /proteins/{accession}
Mon Aug 08 15:26:05 UTC 2016 : Method request path: {accession=P05067}
Mon Aug 08 15:26:05 UTC 2016 : Method request query string: {}
Mon Aug 08 15:26:05 UTC 2016 : Method request headers: {}
Mon Aug 08 15:26:05 UTC 2016 : Method request body before transformations: null
Mon Aug 08 15:26:05 UTC 2016 : Endpoint request URI: https://dynamodb.us-west-2.amazonaws.com/?Action=Query
Mon Aug 08 15:26:05 UTC 2016 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************************b0b302, X-Amz-Date=20160808T152605Z, x-amzn-apigateway-api-id=9x56sueb85, Accept=application/json, User-Agent=AmazonAPIGateway_9x56sueb85, X-Amz-Security-Token=AgoGb3JpZ2luEJv//////////wEaCXVzLXdlc3QtMiKAAlXlB1cz9vo5Kf2llpupTpP1fTiHMBBbZhOmQW30/jCc5Q3RV+BM9k0LtqfJXRdRpzw5DEHg1dmlA1k8Ljha+og4RGYFdpj/9wdc4u1WKnZdy/lZFUAMey0YotNc+RniWyMq+ZiVhY94Sv/zKJ+dxSGkDZbz5A6Jbfj4EfVFuMLC3kHA4tJKWp6PCXpyHJqFqQ+UuI/q0coHNQv0euBD6hNUBOEBZes2TIQdTha8f4k+avX7o1f3LcpIjfvdPN4InOXZ7ZMHDgpLEuxurOZ7taZjoXftHxpRG2GAciTNj7gQASCsxRAQL/4gujC6yydGievEE6V5Zn5prIRnHPz0Lmcq8QII8f//////////ARAAGgw5MTUzMzI4Mzc1NDAiDD4AxveOBPRjUQ28ZirFAj5mJUN8gxUfXUQc1AzD08pLgpAtrz11K1Xgax/ATvptUj//Pcy+4fS90PqdZSqMSmS8KsD0X46m7GfhNNzuQypCdY3lyyN [TRUNCATED]
Mon Aug 08 15:26:05 UTC 2016 : Endpoint request body after transformations: {
    "TableName": "Protein_DB",
    "IndexName": "accession-index",
    "KeyConditionExpression": "accession = :v1",
        "ExpressionAttributeValues": {
            ":v1":  {
                "S": "P05067"
            }
        }
}
Mon Aug 08 15:26:05 UTC 2016 : Endpoint response body before transformations: {"Count":1,"Items":[{"accession":{"S":"P05067"},"features":{"L":[{"M":{"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":" "},"type":{"S":"SIGNAL"},"evidences":{"L":[{"M":{"source":{"M":{"id":{"S":"12665801"},"alternativeUrl":{"S":"http://europepmc.org/abstract/MED/12665801"},"name":{"S":"PubMed"},"url":{"S":"http://www.ncbi.nlm.nih.gov/pubmed/12665801"}}},"code":{"S":"ECO:0000269"}}},{"M":{"source":{"M":{"id":{"S":"2900137"},"alternativeUrl":{"S":"http://europepmc.org/abstract/MED/2900137"},"name":{"S":"PubMed"},"url":{"S":"http://www.ncbi.nlm.nih.gov/pubmed/2900137"}}},"code":{"S":"ECO:0000269"}}},{"M":{"source":{"M":{"id":{"S":"3597385"},"alternativeUrl":{"S":"http://europepmc.org/abstract/MED/3597385"},"name":{"S":"PubMed"},"url":{"S":"http://www.ncbi.nlm.nih.gov/pubmed/3597385"}}},"code":{"S":"ECO:0000269"}}}]},"end":{"S":"17"},"begin":{"S":"1"}}},{"M":{"ftId":{"S":"PRO_0000000088"},"category":{"S":"MOLECULE_PROCESSING"},"description":{"S":"Amyloid b [TRUNCATED]
Mon Aug 08 15:26:05 UTC 2016 : Endpoint response headers: {x-amzn-RequestId=J0J7K1RFDOGEK20V70T0HKJ14JVV4KQNSO5AEMVJF66Q9ASUAAJG, x-amz-crc32=273504943, Content-Length=75281, Date=Mon, 08 Aug 2016 15:26:05 GMT, Content-Type=application/x-amz-json-1.0}
Mon Aug 08 15:26:05 UTC 2016 : Method response body after transformations: 
         {
            "accession" : "P05067",
            "entryName" : "A4_HUMAN",
            "sequence" : "MLPGLALLLLAAWTARALEVPTDGNAGLLAEPQIAMFCGRLNMHMNVQNGKWDSDPSGTKTCIDTKEGILQYCQEVYPELQITNVVEANQPVTIQNWCKRGRKQCKTHPHFVIPYRCLVGEFVSDALLVPDKCKFLHQERMDVCETHLHWHTVAKETCSEKSTNLHDYGMLLPCGIDKFRGVEFVCCPLAEESDNVDSADAEEDDSDVWWGGADTDYADGSEDKVVEVAEEEEVAEVEEEEADDDEDDEDGDEVEEEAEEPYEEATERTTSIATTTTTTTESVEEVVREVCSEQAETGPCRAMISRWYFDVTEGKCAPFFYGGCGGNRNNFDTEEYCMAVCGSAMSQSLLKTTQEPLARDPVKLPTTAASTPDAVDKYLETPGDENEHAHFQKAKERLEAKHRERMSQVMREWEEAERQAKNLPKADKKAVIQHFQEKVESLEQEAANERQQLVETHMARVEAMLNDRRRLALENYITALQAVPPRPRHVFNMLKKYVRAEQKDRQHTLKHFEHVRMVDPKKAAQIRSQVMTHLRVIYERMNQSLSLLYNVPAVAEEIQDEVDELLQKEQNYSDDVLANMISEPRISYGNDALMPSLTETKTTVELLPVNGEFSLDDLQPWHSFGADSVPANTENEVEPVDARPAADRGLTTRPGSGLTNIKTEEISEVKMDAEFRHDSGYEVHHQKLVFFAEDVGSNKGAIIGLMVGGVVIATVIVITLVMLKKKQYTSIHHGVVEVDAAVTPEERHLSKMQQNGYENPTYKFFEQMQN",
            "sequenceChecksum" : "A12EE761403740F5",
            "taxid" : "9606",
             [TRUNCATED]
Mon Aug 08 15:26:05 UTC 2016 : Method response headers: {Content-Type=application/json}
Mon Aug 08 15:26:05 UTC 2016 : Successfully completed execution
Mon Aug 08 15:26:05 UTC 2016 : Method completed with status: 200

我试图格式化特征字段,但收效甚微。下面是我的尝试:

#set($inputRoot = $input.path('$'))
        #foreach($elem in $inputRoot.Items) {
            "accession" : "$elem.accession.S",
            "entryName" : "$elem.entryName.S",
            "sequence" : "$elem.sequence.S",
            "sequenceChecksum" : "$elem.sequenceChecksum.S",
            "taxid" : "$elem.taxid.N",
            "features" : "$elem.features.L"
        }#if($foreach.hasNext),#end
#end
#foreach($elem in $inputRoot.Items.features)
      {
        "alternativeSequence": "$elem.alternativeSequence.S",
        "begin": "$elem.begin.S",
        "category": "$elem.category.S",
        "description": "$elem.description.S",
        "end": "$elem.end.S",
        "evidences": "$elem.evidences.L",
        "ftID": "$elem.ftId.S",
        "type": "$elem.type.S"
      }#if($foreach.hasNext),#end
#end``

问题是'features'字段吗?我想你只是在不必要的时候加了引号。

#set($inputRoot = $input.path('$'))
#foreach($elem in $inputRoot.Items) {
    "accession" : "$elem.accession.S",
    "entryName" : "$elem.entryName.S",
    "sequence" : "$elem.sequence.S",
    "sequenceChecksum" : "$elem.sequenceChecksum.S",
    "taxid" : "$elem.taxid.N",
    "features" : $elem.features.L
} #if($foreach.hasNext),#end
#end

问题是$elem是一个变量而不是函数,不能在foreach循环中重用。必须为变量指定一个新名称,如$elem1。我在下面附上了最终的工作体模板。

#set($inputRoot = $input.path('$'))
     #foreach($elem in $inputRoot.Items) {
        "accession" : "$elem.accession.S",
        "entryName" : "$elem.entryName.S",
        "sequence" : "$elem.sequence.S",
        "sequenceChecksum" : "$elem.sequenceChecksum.S",
        "taxid" : $elem.taxid.N,
        "features" : [
                        #foreach($elem1 in $elem.features.L){
                            "alternativeSequence": "$elem1.M.alternativeSequence.S",
                            "begin": "$elem1.M.begin.S",
                            "category": "$elem1.M.category.S",
                            "description": "$elem1.M.description.S",
                            "end": "$elem1.M.end.S",
                            "evidences": [
                                            #foreach($elem2 in $elem1.M.evidences.L){
                                                "code":"$elem2.M.code.S",
                                                "source" : #foreach($elem3 in $elem2.M.source){
                                                           "alternativeUrl" : "$elem3.alternativeUrl.S",
                                                           "id":"$elem3.id.S",
                                                           "name":"$elem3.name.S",
                                                           "url":"$elem3.url.S",
                                                       }#if($foreach.hasNext),#end
                                                       #end
                                            }#if($foreach.hasNext),#end
                                            #end
                                        ],
                            "ftID": "$elem1.M.ftId.S",
                            "type": "$elem1.M.type.S"
                        }#if($foreach.hasNext),#end
                        #end
                    ]
    }#if($foreach.hasNext),#end
<标题>

相关内容

  • 没有找到相关文章

最新更新