Import existing AWS Lambda functions into PyCharm?
I have a moderate suite of AWS Lambda functions implemented over a period of a couple of years in a combination of Python and JavaScript. I have now moved all my server-side and desktop development to JetBrains products and they are absolutely wonderful. I need to do quite a lot of maintenance on the AWS Lambda functions now and would like to use PyCharm and WebStorm. I have experimentally authored a new Python based lambda function using PyCharm and it is pretty good. But my problem is now how I can get the existing body of code into the JetBrains environment? I was expecting to be able to select the lambda function in the AWS explorer and have an import option - rather like Cloud9 - but I can't see one. I'm sure that I can export the functions from AWS and manually set up new projects in PyCharm, but I have a lot of code and it will be a painful and error prone process - am I missing some easy way?
TIA
Martin
Please sign in to leave a comment.
Were you able to find the solutions?
Im looking the way to export my perfect aws lambda project to JetBrains.The project was created as deeplens and I wanna to export it.
But i cant explict action to such looking obvoious issue
Hi there and sorry for the delay responding - your message got buried in spam! I ended up writing a couple of simple shell scripts that took away a lot of the grunt work, but I still had to do some manual post processing to complete the job...
My script is "getFunctions.sh" :
#!/usr/bin/env bash
#You need to have aws-cli installed and configured
#Credits to Reddit user u/aa93 for the suggestions
mkdir code
aws lambda list-functions --region eu-west-2 | \
grep FunctionName | \
cut -d '"' -f4 | \
while read -r name; do
aws lambda get-function --region eu-west-2 --function-name $name | jq -r '.Code.Location' | xargs wget -O ./code/$name.zip
done
Run that in a scratch directory and it will bring down copies of all your lambda functions as zip files.
I then ran "expandZips.sh" :
#!/bin/sh
for file in *.zip; do
fn=`basename $file .zip`
echo "$file"
echo "$fn"
mkdir "$fn"
unzip -d "$fn" "$file"
done
which loops through all the zip files, expanding them out to individual directories on your PC.
I'm sure that it would be possible to write a script that would take each of those directories and make the necessary additions to turn it into a Pycharm AWS Serverless project. I only had a couple of dozen functions to import - and half of them were coded in Javascript which I wanted to convert to Python, so I decided to do it manually. It was easy enough to create the first Pycharm project manually, then take copies of it and drop in the source code that was downloaded and extracted using my scripts above.