10 Recommendations for writing pragmatic AWS Lambdas in Python
Can we please stop with those X ways to do Y articles from Medium? (my personal ask)
Why? Are they not useful?
It’s not my article.
I enjoyed it and found it useful, so I shared in case it helped others… I thought that’s what “Submit a new link” was for?
I just read an article on Medium with 10 recommendations on how to avoid those articles. I could find the link if you want.
Good article. I’m not sure what the other commenters seem to have issues with. These all seem like pretty practical advice for Lambda functions.
Have you looked at AWS Lambda Powertools, it’s a package from AWS that’ll help with your logging recommendations — making them far simpler to implement.
Separate the Lambda handler from the core logic
This is especially useful, allowing you to test the logic easily. It’s also useful for changing the way your lambda is invoked.
Someone has a case of “the curse of knowledge”
Thanks, I guess if I try hard I can learn this skill on my own.
Thanks for sharing, very useful!
Great article
Summary
- use a linter (flake8)
- Separate the Lambda handler from the core logic
- Implement separate responsibilities in separate methods
- Push external dependencies into small, low-level methods
- Initialise external dependencies in the constructor if you can
- Don’t handle errors just because you can
- Use custom exceptions for flow-specific errors
- Use a logger and pick the right logging level
- Configure the minimum log level via CloudFormation
- Decorators are an elegant way to log Lambda context
Ok I will answer seriously. I get like 10-15 articles of those format (X ways of Y) each day in my daily digest and since I have Medium Premium (or how is it called) I can read those ones behind paywall too. So what is wrong with them in my opinion: this is some buzzfeed-y tech format, they are usually very superficial and most of the advices are trivial. Also they are repeated over and over because people just rehash the same points, because everyone wants to publish something on Medium. There is little drive for quality or depth, making this format the lowest hanging fruit. If you look into those recommendations most of them are trivial programming advice and present little true expertise on the matter.
About this specific article, recommendations 1 to 8 are just general good programming tips not specific to AWS Lambda. Recommendation 9 is not bad and actually AWS Lambda specific. Recommendation 10 is also not bad but it is just a Python technique that has nothing to do with AWS Lambda. If the article would have been more in depth something like this https://awslabs.github.io/aws-lambda-powertools-python/ would have been mentioned.
is there somethink like this for js ?
Would love to see fartcookies and cr235riders 300/400 self published content…must be some stunning stuff
One thing I want to note here is that if your lambda is expected to be invoked fairly frequently, you want to initialize your class instance before handler function. Lambda (service) executes part before handler once per environment initialization, so if you have something reusable, like boto3 client or requests’ session, it’s better to reuse it