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

310
Visualizações
Passing hashed URI in Lambda script

I've written some code that should insert a hashed URI as a header I'm using for cache control. I'm fairly new to JS so I think my formatting may be off but I've borrowed a lot from the Lambda@Edge examples.

var crypto = require("crypto");
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
const etagUri = ''
const eTag = crypto.createHash('sha256').update(etagUri).digest('hex');
request.uri = etagUri;
console.log(`Request uri set to "${request.uri}"`);
callback(null, request);

const response = {
    status: '200',
    statusDescription: 'OK',
    headers: {
        'ETag': [{
            key: 'ETag',
            value: eTag,
        }],
    },
};
return response;
};

I run into an error when I test in the Lambda code editor. I see a lot of debugging with console log but since this runs in the back end I can't get it to print that stuff for me in AWS.

{
 "errorType": "TypeError",
 "errorMessage": "Cannot read property '0' of undefined",
 "trace": [
"TypeError: Cannot read property '0' of undefined",
"    at Runtime.exports.handler (/var/task/index.js:3:34)",
"    at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)"
 ]
}

I know it's not behaving nicely with that request const. Also when I try to deploy this through CloudFront I get a 502 The Lambda function result failed validation: The specified URI is in an invalid format. error which I assume means it can use that to generate the URI but is failing after. I'd love any additional debugging tips for working in Lambda as well!

about 4 years ago · Juan Pablo Isaza
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