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

110
Views
Why is the view counter showing undefined?

I'm completely lost, I've been trying to figure this out for almost 2 days now. Here is my code, if you need any more information please let me know. I need a break, so I'm not at my best. I made an account for this so I do not have enough status to post embedded pictures.

JS Code as Text

const countUrl = 'https://igf5ctozsa.execute-api.us-east-1.amazonaws.com/default/updateViews'
const countElement = document.getElementById('count');

updateViewCount();

function updateViewCount() {
    fetch(countUrl)
        .then(res => res.json())
        .then(res => {
        countElement.innerText = res.val;
    });
}

Python API as Text

import json, boto3

client = boto3.client('dynamodb')
TableName = 'cloud-resume-stats'

def lambda_handler(event, context):
    response = client.update_item(
        TableName='cloud-resume-stats',
        Key = {
            'stats': {'S': 'viewcount'}
        },
        UpdateExpression = 'ADD Quantity :inc',
        ExpressionAttributeValues = {":inc" : {"N": "1"}},
        ReturnValues = 'UPDATED_NEW'
        )
        
    val = int(response['Attributes']['Quantity']['N'])
    
    return {      
            'statusCode': 200,
            'headers': {
            'Access-Control-Allow-Headers': '*',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': '*'
            },
            'body': val
        
    }

API Response as Text

Test Event Name
TestEvent

Response
{
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Headers": "*",
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "*"
  },
  "body": 147
}

Function Logs
START RequestId: 25413898-aca7-45e7-869e-41dd94879af4 Version: $LATEST
END RequestId: 25413898-aca7-45e7-869e-41dd94879af4
REPORT RequestId: 25413898-aca7-45e7-869e-41dd94879af4  Duration: 75.93 ms  Billed Duration: 76 ms  Memory Size: 512 MB Max Memory Used: 63 MB  Init Duration: 339.61 ms

Request ID
25413898-aca7-45e7-869e-41dd94879af4
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to the body part's value of the Python API Response, I think res is just 147, not the res.val.

fetch(countUrl)
    .then(res => res.json())
    .then(res => {
    //countElement.innerText = res.val; // res is 147
    countElement.innerText = res;
});
about 4 years ago · Juan Pablo Isaza Report
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!