Skip to content

Instantly share code, notes, and snippets.


Is there a better way to handle having an application inside a container that's executed from outside pass logs up?

Ansible-Container has a CLI tool that invokes a conductor container (which contains Ansible, a bunch of deps, etc) and has to get & display logs from the executions inside. To make this work & display logs, we have kind of an odd setup that I'm not sure is right.

In the container

We're logging out a combination of structlog and plain Ansible output to stdout. This means not all the CLI output is parseable as JSON, so we format it inside the container to be shown on the host stdout.

Outside the container

View env.json
"LANG": "en_US.UTF-8",
"AWS_DEFAULT_REGION": "us-east-1",
"AWS_LAMBDA_FUNCTION_NAME": "testenv-dev-hello",
"TESTSTR": "hello",
"PYTHONPATH": "/var/runtime",
"AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/testenv-dev-hello",

sample of a playbook that just uses localhost for a bunch of AWS tasks

- hosts: localhost
  - name: make a VPC for my app
    register: vpc
       region: us-west-2
ryansb /
Last active Feb 18, 2016
Strip down a Python virtualenv by removing symbols from compiled files, thanks to @ogrisel for the tip!
set -e
set -o pipefail
echo "venv original size $(du -sh $VIRTUAL_ENV)"
find $VIRTUAL_ENV/lib/python2.7/site-packages/ -name "*.so" | xargs strip
echo "venv after stripping $(du -sh $VIRTUAL_ENV)"
ryansb /
Created Jan 7, 2016
Check expiring certificates
import datetime
import logging
import socket
import ssl
logger = logging.getLogger()
View gist:08c264d0d17bf672bb55
import boto3
import collections
import datetime
ec = boto3.client('ec2')
def lambda_handler(event, context):
reservations = ec.describe_instances().get(
'Reservations', []
View gist:c5807c6785f326e9510d
import boto3
import collections
import datetime
ec = boto3.client('ec2')
def lambda_handler(event, context):
reservations = ec.describe_instances(
{'Name': 'tag-key', 'Values': ['backup', 'Backup']},
ryansb /
Last active Jan 23, 2021
SQLAlchemy/JSON Notebook - requires Python 3, SQLAlchemy, psycopg2, and Jupyter (formerly IPython Notebook)

Before running this notebook, run:

pip3 install jupyter SQLAlchemy psycopg2

This will install the notebook server and database drivers needed to run these examples. For more information on installing Jupyter (formerly IPython notebook) see their install guide.

Once you've installed the dependencies, run jupyter notebook and it will open your web browser to the notebook's main page. Then upload this notebook (SQLTest.ipynb) and run it.

View SQLAlchemy and namedtuples.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
ryansb / sns_to_slack.js
Created Aug 23, 2015
Forward SNS messages to Slack Webhook receivers with AWS Lambda
View sns_to_slack.js
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = '<KEY STUFF>';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};