API Gateway body template mapping to retain valid json data-structure of data-element, while still allow for base64-encoding

1

I have the exact same issue as an older question and there was even an accepted solution, but it has been deleted! The thread is: https://repost.aws/questions/QUm3sz-dEESBiezvcnxrnwRQ/api-gateway-body-template-mapping-to-retain-valid-json-data-structure-of-data-element-while-still-allow-for-base-64-encoding

The deleted answer is: https://forums.aws.amazon.com/thread.jspa?threadID=233060

Could someone please help me with this? This is a very frustrating issue.

Thanks.

1 Risposta
0

This is kinda hacky, but you need to work in strings a little further as once you are in json objects there doesn't seem a way to re-stringiify... Here is my snippet...

       { "StreamName": "event-stream-qa", "Records": [
#set($datakey = ".data")
#set($partitionkey = ".key")
#foreach($elem in $input.path('$.records'))
    #set($pathBegin = "$.records[")
    #set($pathEnd = "]")
    #set($currentIndex = $foreach.index)
    #set($dataPath = "$pathBegin$currentIndex$pathEnd$datakey")
    #set($partitionPath = "$pathBegin$currentIndex$pathEnd$partitionkey")
    #set($dataJson = $input.json($dataPath)) 
    #set($partitionJson = $input.json($partitionPath)) 
  { 
    "Data": "$util.base64Encode($dataJson)",
    "PartitionKey": $partitionJson
  }
    #if($foreach.hasNext),#end
#end  
  ]
}

ecordo
con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande