Skip to content

Instantly share code, notes, and snippets.

View patrick-fs's full-sized avatar

Patrick@FullStory patrick-fs

View GitHub Profile
/*
This is a simple Redux Middleware that will record Redux actions and state to FullStory. This data will be available in the
console view in FullStory's DevTools during session replay.
Learn more about DevTools here: https://help.fullstory.com/hc/en-us/articles/360020828313-Guide-to-Dev-Tools
Redux Middleware guide here: https://redux.js.org/tutorials/fundamentals/part-4-store#middleware
Please be careful to not record any sensitive information that may be in your Redux state.
*/
@patrick-fs
patrick-fs / cdk_updated_entrypoint.ts
Created October 6, 2020 16:56
The updated API Construct after webpack config for my Bionic article
import { Cors, LambdaRestApi } from '@aws-cdk/aws-apigateway';
import * as core from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
export class ReactshoppeApi extends core.Construct {
private _handler: lambda.Function;
constructor(scope: core.Construct, id: string) {
super(scope, id);
this._handler = new lambda.Function(this, 'ApiHandler', {
@patrick-fs
patrick-fs / cdk_update_npm_scripts.json
Created October 6, 2020 16:55
Updated NPM scripts for my Bionic article
"scripts": {
"build": "tsc && npm run build:webpack",
"build:webpack": "webpack --config packages/functions/webpack.config.js --display-error-details",
"cdk": "cdk",
"bootstrap": "lerna bootstrap",
"deploy": "npm run bootstrap && npm run build && cdk deploy"
}
@patrick-fs
patrick-fs / cdk_webpack_config.ts
Last active October 8, 2020 00:04
The webpack config file for my Bionic article
const path = require('path');
module.exports = {
target: 'node',
mode: 'production',
optimization: {
minimize: true,
sideEffects: false,
},
context: path.resolve(__dirname),
import { APIGatewayProxyEvent } from 'aws-lambda';
import * as AWS from 'aws-sdk';
import { v4 as uuidv4 } from 'uuid';
import { TableNames } from '../reactshoppe-database';
import { success, failure } from './response';
export default async (event: APIGatewayProxyEvent) => {
const ddb = new AWS.DynamoDB.DocumentClient();
let newOrder = {};
// NOTE: in a real application, we’d do more to validate input
import { APIGatewayProxyEvent } from 'aws-lambda';
import ping from './ping';
import checkout from './checkout';
import { failure } from './response';
exports.main = async (event: APIGatewayProxyEvent) => {
const notFound = () => failure(JSON.stringify({ message: 'not found' }), 404);
switch (event.path) {
case '/ping':
return ping();
import { Cors, LambdaRestApi } from '@aws-cdk/aws-apigateway';
import * as core from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
export class ReactshoppeApi extends core.Construct {
private _handler: lambda.Function;
constructor(scope: core.Construct, id: string) {
super(scope, id);
this._handler = new lambda.Function(this, 'ApiHandler', {
import * as cdk from '@aws-cdk/core';
import { ReactshoppeDatabase } from './reactshoppe-database';
import { ReactshoppeApi } from './reactshoppe-api';
export class ReactshoppeApiStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
const api = new ReactshoppeApi(this, 'ReactshoppeApi');
import * as cdk from '@aws-cdk/core';
import { ReactshoppeDatabase } from './reactshoppe-database';
export class ReactshoppeApiStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
new ReactshoppeDatabase(this, 'ReactshoppeDatabase');
}
@patrick-fs
patrick-fs / cdk_DynamoDB.ts
Created September 8, 2020 13:23
CDK Construct for DynamoDB
import * as core from '@aws-cdk/core';
import * as iam from '@aws-cdk/aws-iam';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
export class ReactshoppeDatabase extends core.Construct {
private orderTable: dynamodb.Table;
constructor(scope: core.Construct, id: string) {
super(scope, id);
this.orderTable = new dynamodb.Table(this, TableNames.Order, {