Skip to content

Instantly share code, notes, and snippets.

@vvalorous
vvalorous / faas.md
Created September 29, 2018 02:42 — forked from alexellis/faas.md
FaaS blog post for collaboration with translator

One of 2016's key buzzwords was serverless - but is anyone sure what that means? Both AWS Lambda and Kubernetes Jobs provide their own solutions in this space, but..

I'm not sure that we have a clearly defined standard on what serverless should look like and how it should behave.

Here are some of my thoughts on serverless based upon what I've seen this year:

  • tends involve invoking short-lived functions (Lambda has a default 1-sec timeout)
  • does not publish TCP services - often accesses third-party services or resources
  • tends to be ad-hoc/event-driven such as responding to webhooks
  • should deal gracefully with spikes in traffic
var https = require('https');
var util = require('util');
var webhook = '/services/webhook';
var errorMessage = "ERROR";
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
#!/usr/bin/env python
import boto3
import json
sns = boto3.client("sns")
topic_arn = "YOUR_SNS_TOPIC"
proto = "http"
endpoint = "YOUR_EDNPOINT"
attributes = {"FilterPolicy": json.dumps({"key": ["foo", "bar"]})}
@vvalorous
vvalorous / sns_lambda_slack_webhook.py
Created September 29, 2018 02:40 — forked from daniel-woods/sns_lambda_slack_webhook.py
Create an SNS Topic, with a Lambda function subscribed. Using the below handler, you can parse the vent object for your SNS message and pass it to a Slack webhook URL.
#!/usr/bin/python2.7
# https://gist.github.com/daniel-woods
import json
from urllib2 import urlopen, HTTPError, Request
def post_message(url, data):
req = Request(url, data)
f = urlopen(req)
@vvalorous
vvalorous / sns_lambda_teams_webhook.py
Created September 29, 2018 02:40 — forked from daniel-woods/sns_lambda_teams_webhook.py
Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
#!/usr/bin/python3
# https://gist.github.com/daniel-woods
# Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
import json
from urllib2 import urlopen, HTTPError, Request
def post_message(url, data):
req = Request(url, data)
@vvalorous
vvalorous / codedeploy-to-slack.js
Created September 29, 2018 02:39 — forked from teeli/codedeploy-to-slack.js
CodeDeploy notifications to Slack (AWS Lambda via SNS)
var https = require('https');
var util = require('util');
exports.handler = function (event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var severity = "good";
var message = event.Records[0].Sns.Message;
var messageJSON = JSON.parse(message);
@vvalorous
vvalorous / snsread.py
Created September 29, 2018 02:39 — forked from iMilnb/snsread.py
Basic Flask snippet to handle AWS SNS messages and subscription
from flask import Flask, request
import requests
import json
app = Flask(__name__)
def msg_process(msg, tstamp):
js = json.loads(msg)
msg = 'Region: {0} / Alarm: {1}'.format(
js['Region'], js['AlarmName']
@vvalorous
vvalorous / snsToSlack.js
Created September 29, 2018 02:30 — forked from terranware/snsToSlack.js
AWS Lambda function to Slack Channel hookup
var https = require('https');
var util = require('util');
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
"channel": "#aws-sns",
"username": "AWS SNS via Lamda :: DevQa Cloud",
@vvalorous
vvalorous / sns2slack.js
Created September 29, 2018 02:29 — forked from johnnaegle/sns2slack.js
Posts an Amazon Autoscaling SNS message to a slack webhook
var https = require('https');
var util = require('util');
var webhook = '/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
"text": "*" + event.Records[0].Sns.Subject + "*"
@vvalorous
vvalorous / cloudwatch_log_subscriber.py
Created September 28, 2018 06:02 — forked from bwhaley/cloudwatch_log_subscriber.py
AWS lambda function to subscribe new CloudWatch Log groups to another lambda function
# Lambda function to subscribe all new cloudwatch log groups to a log shipper function
# Used in conjunction with https://github.com/SumoLogic/sumologic-aws-lambda
import os
import logging
import json
import uuid
import boto3
from botocore.exceptions import ClientError