Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.
I've tried to make it as lean and unobtrusive as possible.
errors/AppError.js
const _ = require('lodash'); | |
const AWS = require('aws-sdk'); | |
const retry = require('bluebird-retry'); | |
function recursiveReq(request, params, key, items = [], count = 0) { | |
return request(params).then(data => { | |
const newItems = items.concat(data[key]); | |
const lastItem = _.last(newItems); | |
const nextToken = _.get(data, 'nextToken', null); |
/* Pre-requisite | |
================== | |
1) Create an Environment (if you don't already have on) and enable it for your request | |
2) Add a new Header with key as "Authorization" and value as "{{hmacAuthHeader}}" | |
3) Add the following Pre-request Script that computes the hmacAuthHeader variable and adds it to the environment | |
4) Fill your CLIENT_KEY and SECRET_KEY with valid values | |
*/ | |
function getPath(url) { | |
var pathRegex = /.+?\:\/\/.+?(\/.+?)(?:#|\?|$)/; |
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "AWS CloudFormation sample template that contains a single Lambda function behind an API Gateway", | |
"Resources": { | |
"GreetingLambda": { | |
"Type": "AWS::Lambda::Function", | |
"Properties": { |
# Official framework image. Look for the different tagged releases at: | |
# https://hub.docker.com/r/library/node/tags/ | |
image: node:6 | |
before_script: | |
- npm install | |
# This folder is cached between builds | |
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache | |
cache: |
provider "aws" { | |
access_key = "${var.access_key}" | |
secret_key = "${var.secret_key}" | |
region = "${var.region}" | |
} | |
resource "aws_iam_role" "iam_for_terraform_lambda" { | |
name = "app_${var.app_env}_lambda" | |
assume_role_policy = <<EOF | |
{ |
$mochaPath = Resolve-Path (Join-Path $PSScriptRoot "..\node_modules\.bin\_mocha.cmd") | |
$setupPath = Resolve-Path (Join-Path $PSScriptRoot "..\test\setup.js") | |
$testFiles = Join-Path $PSScriptRoot "..\src\**\*.test.js" | |
& $mochaPath "$testFiles" --require "$setupPath" --compilers js:babel-register --debug-brk |
config: | |
target: "http://localhost:8080" | |
phases: | |
- duration: 60 | |
arrivalRate: 1 | |
processor: "./processor.js" | |
scenarios: | |
- name: "Load the options page" | |
flow: | |
- get: |
$QueueName = "myQueue" | |
$TopicName = "myTopic" | |
$Region = "us-west-2" | |
$SNSUserAccountID = (Get-EC2SecurityGroup -GroupNames "default")[0].OwnerId | |
$QueueURL = New-SQSQueue -QueueName $QueueName -Region $Region | |
$QueueARN = (Get-SQSQueueAttribute -QueueUrl $QueueURL -AttributeName QueueArn).Attributes['QueueArn'] | |
$TopicARN = New-SNSTopic -Name $TopicName -Region $Region | |
$Sid = "Sid" + (Get-Random) |
Picking the right architecture = Picking the right battles + Managing trade-offs