Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
How do I get a full DynamoDB scan response from the aws-sdk-js-v3 without object types? (Marshaled response)

I'm answering this question for myself and others because I found the AWS JS SDK V3 documentation and examples to be super annoying and misleading. The official SDK docs do not provide an example for showing marshaled output so you see a bunch of object types in your response. The DDB Doc client by default will remove those but they don't show you how. The answer I am posting gives you a marshaled response, meaning it cleans out the object type strings.

An example of an unmarshalled response is like this, notice the S for string as the value type.

[
    {
      project_name: { S: 'fake project' },
      service_now_request_id: { S: 'CHG000212312' },
      service_now_request_url: {
        S: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555'
      }
    }
]

If you want a response like below, you should use the full DDB document client:

[
    {
        project_name: 'fake project',
        service_now_request_id: 'CHG000212312',
        service_now_request_url: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555',
    }
]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's my sample code, feel free to nitpick or post a full ES6 version if you want.

const {DynamoDB} = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb');

const client = new DynamoDB({region: "us-west-2",});
const ddbDocClient = DynamoDBDocument.from(client);

async function marshaledScanOutput() {

    const primaryDynamoDBTableName = "yourDDBTableName";

    ddbParams = {TableName: primaryDynamoDBTableName};

    try {
        let testScan = await ddbDocClient.scan(ddbParams);
        let result = [];
    
        do {
            testScan.Items.forEach((item) => result.push(item));
            ddbParams.ExclusiveStartKey = testScan.LastEvaluatedKey;
        } while (typeof testScan.LastEvaluatedKey != "undefined");
    
        console.log(result);
        // Example output:
        // [
        //     {
        //       project_name: 'fake project',
        //       service_now_request_id: 'CHG000212312',
        //       service_now_request_url: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555',
        //     }
        // ]
    }
    catch(error) {
        throw error;
    }
}

marshaledScanOutput();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda