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

Lambda Gotcha: CloudWatch Logs Group Name

Hello! Today's post is a little "gotcha" that sometimes still gets me when I'm developing AWS lambda functions: if you want to stream the function's logs to CloudWatch the log group's name has to follow a specific convention. Suppose I'm creating a lambda function with this CloudFormation snippet: The key piece is this: When AWS … Continue reading Lambda Gotcha: CloudWatch Logs Group Name

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

CloudWatch Logs: Preventing Orphaned Log Groups

Hello! When you need to publish logs to CloudWatch (e.g. from a lambda function), you need an IAM role with access to CloudWatch. It's tempting to use a simple policy like the one in the AWS docs. You might write a CloudFormation template like this: Obviously, the role is too permissive: arn:aws:logs:*:*:* But, there's another … Continue reading CloudWatch Logs: Preventing Orphaned Log Groups

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. Recently, I've been switching to logs structured as JSON. That means output like this: Instead of this: This way, your log processor can reference keys in a JSON object … Continue reading CloudWatch Logs Structured as JSON with Python Lambda Functions

CodePipeline: Python AWS Lambda Functions Without Timeouts

Hello! If you're new to CodePipeline lambda actions check out this complete example first. There’s a gotcha when writing CodePipeline lambda functions that’s easy to miss and if you miss it your pipeline can get stuck in timeout loops that you can't cancel. Here’s how to avoid that. This article assumes you're familiar with CodePipeline … Continue reading CodePipeline: Python AWS Lambda Functions Without Timeouts

Lambda: boto3 CloudWatch Logs

Good morning! If you're writing a regular script (i.e. not a lambda function), check out this article. This pattern outputs traditional delimited strings. If you want to upgrade that into output structured as JSON objects, check out this article. For those custom cases that don't fit into Terraform or CloudFormation, a little bit of Python and some … Continue reading Lambda: boto3 CloudWatch Logs

The Better Alexa Quick Start

You've seen the Life Coach. That was my second Alexa project. The one I used to learn the platform. I began with Amazon's quick start tutorial (update August 2019: broken link to quick start removed, the AWS tutorials have evolved since this article was written), but I didn't like the alexa-skills-kit-color-expert-python example code. It feels like … Continue reading The Better Alexa Quick Start