I've recently inherited an abandoned AWS project written in Python using AWS Simple Email Service, Lambda, S3 and API Gateway. Poor documentation has ben lost figuring out which files were configured with each service.

Title, I got handed down some AWS project that no longer works. The project was written in Python 2.7, which is appears AWS Lambda has deprecated. So I’ve attempted to update the code to the latest release Py 3.9 and most of my errors are resolved.

Due to very poor documentation & lack of comments, I’ve been stuck trying to figure out which parts of this codebase go to which AWS services.

For example: this project had 3 different __init__.py files & one of them is even empty.

The code apparently was working before the past developer parted ways with the company. The company didn’t have access to the AWS account (totally their fault & I prefer not to have the discussion), but I am now tasked with hooking up all this code to a new AWS account.

I’ve no idea which pieces of this project go to which services. Some of them are obvious. Certainly the Lambda.py is supposed to go to a lambda function.

Hopefully in the code I can find ways to determine where these files were originally uploaded. I am praying that I can find functions, methods or libraries within this code to help suggest things like “oh this .py file interacts with the AWS Simple Email Service” or “wow this .py file interacts with the S3 bucket”

I am coming from Google Cloud Platform, so my knowledge of the python codebase that interacts with AWS is limited. I am excited to take on this role & expand my skillset in cloud technologies. Just performing a little rant & organizing my thoughts before I get too deep into setting up the integrations necessary on AWS to get this code to work on a new AWS account.

In short the project does this:

Get JSON from Webhook, perform calculation & alter JSON, convert to PDF, email PDF to customer, store PDF in S3 bucket.

The project uses a library called pypdftk or Python PDK Toolkit. Hopefully this is compatible with Py 3.9, because apparently Py 2.7 is deprecated on AWS Lambda.

did you have a question or did you just log into reddit to share what you’ve been thinking about?

Is there any cloudformation code? that could serve as a roadmap. It’ll be in a json or yaml file.

If I imagine the simplest version of this, ALL of the code could get packaged into the lambda. Lambda.py might be the entrypoint, and the other code is brought in via “import foo” or “from foo import bar” type of statements.

It could be the case that the entirety of the code is meant to run in lambda. If the runtime is within 15 minutes, all of these interactions would be happening via boto3 calls anyway. One big gotcha: any library external to boto3 or the python “standard library” need to be included in your deployment package, as the Lambda runtime won’t have access to them. I’d suggest using Layers for these, gives you a reusable way to include external libraries in multiple lambda functions.

Was there any test code? if not you’re probably largely fucked. Also this isn’t going to be successful until you have a decent understanding of how to build lambda functions your self.

No idea why you’re downvoted. This is a possibility and it’s even a likely possibility.

yes, the brain hurts from not having a proper software dev team and/or proper team meetings.

Yes actually. This may be the case. I have about 6 different lines of code importing from other sections of the codebase.

Yeah, I have learned that this Python PDF Toolkit, may be need to be added via a Lambda Layer.

I’ve no examples of the code in action. No maps, diagrams or development tools to go off of. I have some sample outputs, and I know the code was working previously. So I assume this is an AWS config issue, not a code issue.

but yes, it appears I need to rename some things in the code to match the new s3 buckets, SES email & such.

Empty init.py files are a normal thing.

The init.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string, unintentionally hiding valid modules that occur later on the module search path. In the simplest case, init.py can just be an empty file…

https://docs.python.org/3/tutorial/modules.html

Get JSON from Webhook, perform calculation & alter JSON, convert to PDF, email PDF to customer, store PDF in S3 bucket.

On the surface, that sounds pretty straightforward. I guess the real logic you need to understand is the calculation part and the generation of the PDF template e.g. is it a specific template or literally just spitting out the JSON data onto a PDF that gets sent to customers.

You achieve this with a lambda function, S3 bucket and SES.

Is starting from scratch an option for you?

Based on what the project does, I’d say that it could be something like:

  • Get JSON from Webhook → API Gateway. You can confirm this by checking the webhook URL. Do you have access to the service configuration that is calling it?
  • Perform calculation & alter JSON, convert to PDF,
    store PDF in S3 bucket. → Lambdas
  • email PDF to customer → Lambda using SES

So, you should create an API Gateway endpoint that uses a proxy to call the initial Lambda. I guess that initial Lambda can be identified because it gets JSON and calls all other Lambdas or a Layer to execute the other tasks.

I’d start by looking at historic log records and browsing the underlying OS to see what I can see. Also if it’s not too complex a solution you could re-engineer to a new solution and deploy that solution accordingly. You may even be able to save some aws costs in the process.

Sounds like a rewrite is going to be easier. The task seems relatively simple, so maybe pull out the calculation/transform and write the rest of the glue yourself.

Take a look for all the boto3 clients in the code. At least hopefully it’s using boto3 . That should tell you what services are being connected to by what parts of the code.