CodePipeline lambda Function: Complete Example

Hello! It takes a few pieces to assemble a working lambda action for CodePipeline. I like to start from a simple example and build up to what I need. Here's the code I use as a starting point. First, a few notes: My pipeline lambda functions are usually small, often only a few dozen lines … Continue reading CodePipeline lambda Function: Complete Example

CloudFormation Custom Resource: Complete Example

Hello! It takes a few pieces to assemble a working CloudFormation Custom Resource. I like to start from a simple example and build up to what I need. Here's the code I use as a starting point. First, a few notes: My custom resources are usually small, often only a few dozen lines (more than … Continue reading CloudFormation Custom Resource: Complete Example

Don’t Import requests From botocore.vendored

Hello! I've seen this anti-pattern scattered around plenty DevOps code, especially in AWS lambda functions: Vendoring libraries like requests into other libraries like botocore is arguably an anti-pattern in general, but reaching in to botocore and importing it in your own code is definitely one. Here are some of the reasons: The maintainers may un-vendor … Continue reading Don’t Import requests From botocore.vendored

Python: JSON Structured Logging

Hello! If you're setting up JSON logging in AWS lambda, check out this instead. You need some extra code to prevent duplicate log messages. Recently, I've been switching to logs structured as JSON. Using the sample command in my pattern for production-ready Python scripts, that means we replace delimited-strings like these: With JSON objects like … Continue reading Python: JSON Structured Logging

Lambda: Building Python 3 Packages

Hello! This is a guide for building lambda zip packages with pip dependencies in Python 3. It expands the AWS guide to: Build your code if it's either a single-file Python module or a pip-installable Python package (e.g. contains a setup.py). Track pip dependencies for single-file Python modules in the standard requirements.txt file. Show the file … Continue reading Lambda: Building Python 3 Packages

CloudWatch Logs Structured as JSON with Python Lambda Functions

Hello! If you're setting up JSON logging in a script and instead of a lambda function, check out this instead. The pattern is a little simpler. Update 2020-08-30: Replaced the explanation of the missing aws_request_id with a link to a new article explaining how to pass that value. Recently, I've been switching to logs structured … Continue reading CloudWatch Logs Structured as JSON with Python Lambda Functions