Skip to content

Instantly share code, notes, and snippets.

View thomasmichaelwallace's full-sized avatar
🐧

thomas michael wallace thomasmichaelwallace

🐧
View GitHub Profile
@thomasmichaelwallace
thomasmichaelwallace / aws-sdk-bm-mock.js
Created March 27, 2019 20:38
aws-sdk benchmark: external
const DynamoDB = {
DocumentClient() {
return { get: params => ({ promise: async () => params }) };
},
};
const ddb = new DynamoDB.DocumentClient({ region: 'eu-west-1' });
export async function handleV2(event) { // eslint-disable-line import/prefer-default-export
const { TableName, Key } = event;
@thomasmichaelwallace
thomasmichaelwallace / causes-warnings.js
Created March 26, 2019 09:04
Example of require to cause webpack warnings
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
require('x', 'y');
const webpack = require('webpack');
module.exports = {
// ... your webpack configuration ...
plugins: [
new webpack.ContextReplacementPlugin(
/\/package-name\//,
(data) => {
delete data.dependencies[0].critical;
return data;
@thomasmichaelwallace
thomasmichaelwallace / aws-config.js
Last active March 25, 2019 08:47
Http options timeouts for lambda function
import AWS from 'aws-sdk';
const s3 = new AWS.S3({
httpOptions: {
  connectTimeout: 2 * 1000, // time succeed in starting the call
  timeout: 5 * 1000, // time to wait for a response
  // the aws-sdk defaults to automatically retrying if either of these limits are met.
  },
});
// use S3 happily!
@thomasmichaelwallace
thomasmichaelwallace / build-serverless-template.js
Last active October 31, 2019 09:41
Serverless Commons Example
#!/usr/bin/env node
/* eslint-disable no-console */
const path = require('path');
const fs = require('fs');
const templateFile = path.join(__dirname, '../../serverless.templates.yml');
const projectFile = path.join(__dirname, '../../serverless.project.yml');
const profileFile = path.join(__dirname, `../../serverless.project.${process.env.AWS_PROFILE}.yml`);
const slsFile = path.join(__dirname, '../../serverless.yml');
@thomasmichaelwallace
thomasmichaelwallace / updateDashboards.js
Created July 4, 2018 08:47
Synchronise CloudWatch dashboards
import util from 'util';
import AWS from 'aws-sdk';
// command options
const OPT_NAME = 'my-first-dashboard'; // name of dashboard to sync.
const OPT_TEMPLATE = 'master'; // environment to sync-from.
// dashboard/environment options
const asName = (name, environment) => `${name}-${environment}`; // template for full dashboard name.
const environments = ['master', 'staging', 'production']; // environments to duplicate across
@thomasmichaelwallace
thomasmichaelwallace / bootstrap-xray.js
Created June 28, 2018 14:55
Replace AWS with captured X-Ray
// ensures all aws-sdk calls are based on a singleton, captured using the singleton xray-sdk.
import aws from 'aws-sdk';
import { captureAWS } from 'aws-xray-sdk';
const captured = captureAWS(aws);
export default captured;
@thomasmichaelwallace
thomasmichaelwallace / captureAWS.js
Created June 28, 2018 14:46
capture-xray-example
import AWS from 'aws-sdk';
import { captureAWS } from 'aws-xray-sdk';
const captured = captureAWS(AWS);
const s3 = new captured.S3();
@thomasmichaelwallace
thomasmichaelwallace / post.spec.js
Created August 10, 2017 17:03
A quick introduction to inject-loader.
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
import { expect, use } from 'chai'; // eslint-disable-line import/no-named-default
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
/* directory structure:
/tests/post.spec.js // this test.
/src/post.js // the module to test.
/adapters/mailer/js // a mail-out adapter.
*/
@thomasmichaelwallace
thomasmichaelwallace / ec2-open.json
Created August 9, 2017 21:10
IAM Role Policy to open EC2 to a Lambda
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],