Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!