Fixing an AWS Lambda function with LLMs


  A few years ago my wife wanted to move her website from Namecheap to something else, but cheaper. We decided on AWS, given 95% of what she needed was just an S3 bucket plus Cloudfront. The trouble was the last 5%, a password protected web page. This requires a AWS Lambda function. Then I ran across this blog post and GitHub repo. It worked, and got the job done. All for the low low price of around $1 a month, down from Namecheap’s $5 a month.

  Fast forward to a few months ago, she gets an email from AWS. It says Hey, update your Lambda to something newer than NodeJS 16.. Yesterday she said, Hey, can you get that done so I can deleted that email to remind me to get it done?. I said Sure, and then hopped on her laptop that I had used to set it all up via terraform. Except I found, as she tends to do, she had deleted all the files at some point.

  So I start trying to get it to work with NodeJS 20. I googled, and can’t find any updates or even signs of anyone else trying to update it. I then turned to ChatGPT 3.5. I basically asked it to convert the code from NodeJS 16 to 20. It gave me ideas, but didn’t give me any code. So I quickly moved on to models than I run locally via llama.cpp like phind/codellama-34b, TheBloke/Llama-2-70B-Chat-GGUF, and miqudev/miqu-1-70b. With phind/codellama-34b the model is from 2021, and told me NodeJS 20 isn’t the current LTS, 16 is latest. TheBloke/Llama-2-70B-Chat-GGUF gave me code, but did a ok at best job of it. Along the way I realized I was asking the wrong question. I didn’t need NodeJS 16 to 20. I really needed AWS SDK for Javascript v2 to v3. I did try AWS’s migration tool, but it was of very limited help. The miqudev/miqu-1-70b model did better.

  I kept running into the issue of even when I had code that worked without major errors. It would tell me that the password was wrong when I knew it was correct. I finally had enough with the painfully slow local models, even with my Ryzen 5950X + 128gb DDR4 + PNY RTX 3090. I had a choice, pay OpenAI for ChatGPT 4 again, or try the new Claude Pro, aka Claude 3 Opus, from Anthropic. Both are $20 a month. Knowing that many people complain that ChatGPT 4’s quality has been sliding, I picked Claude Pro.

  I did get quick, concise, and helpful answers from Claude Pro. Yet I ended up right back in the same place. I had working code, but also saw the wrong password error in Cloudwatch. This is where I said forget Javascript. Python is a language I know, and AWS Lambda supports it too. I then asked Claude Pro to convert the Javascript code to Python. Which it did without trouble. I did have to jump threw a few hoops to get the code working with AWS Lambda.

  1. Run mkdir package on my Fedora 39 desktop, which just happens to be x86_64 and have Python 3.12 like AWS Lambda.
  2. Run pip install --target ./package boto3 cryptography.
  3. Rename lambda_function.py that Claude Pro had suggested to bucket_access_button.py to solve the module bucket_access_button not found error in Cloudwatch from AWS Lambda.
  4. Rename the lambda_handler function in the code Claude Pro gave me to handler to solve the Handler 'handler' error in Cloudwatch from AWS Lambda.
  5. Run cd package ; zip -r ../deplyoment_package.zip . to make deplyoment_package.zip.
  6. Upload deplyoment_package.zip to AWS Lambda
  7. Switch the runtime to [Python](https://en.wikipedia.org/wiki/Python_(programming_language) 3.12

  In hindsight I probably could have asked any of the LLMs to convert the code from Javascript code to Python. I found someone else complaining of the same thing in a GitHub issue, but with no resolution. It was probably either a bug in the the AWS SDK for Javascript or NodeJS.