Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda