The visitor counter is working! After some time off for the holidays I got back to banging my head against the 403 errors I was getting when my site called the API. The Lambda function worked when I tested it in Lambda and returned the incremented count number. I had the correct CORS headers set up so it wasn't a CORS issue as far as I could tell.
I followed the AWS troubleshooting for 403 errors and I could curl OPTIONS and get a valid preflight response but not GET or POST.
To refresh my memory on the whole process I decided to start from the beginning and set up a new Lambda function and API with the intent to figure out what I did wrong with my existing setup.
The new Lambda function worked just as before since it was the exact same code. My first API was a REST API so for this version I chose an HTTP API. AWS does more of the setup work for you with this version but it eliminates some potential for mistakes on my end.
The new API created a new IAM role which I had to grant access to Lambda and after that it worked! I could call the invoke URL and get the count instead of an error!
I updated the URL in my javascript for the resume site and pushed the changes. Loaded up the site again and there it was: "You are visitor 1".
Top comments (0)