Skip to content

Instantly share code, notes, and snippets.

View sonjisov's full-sized avatar

Aleksei Pushkin sonjisov

  • Auckland
View GitHub Profile
const R = require('ramda');
// Imaginary repository that has a promisified method called putHello().
const repo = require('./hello-repo');
// Imaginary notification scheduler.
const notificationService = require('./notification-service');
// First, let's write the steps one by one.
module.exports = R.pipeP(
FROM amazonlinux:latest
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
RUN export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] \
&& \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" \
&& nvm install v6.10.0 \
&& npm install serverless -g \
&& npm install newman -g \
&& npm install serverless-localstack -g
@sonjisov
sonjisov / deploy-dynamodb-table.sh
Last active May 23, 2019 08:59
Deploying a DynamoDB table using a JSON definition file
# Passing the region name as a parameter
region=$1
tableName="JohnWickQuotes"
dir="${BASH_SOURCE%/*}"
tableDefinitionPath="$dir/table-definition.json"
# Trigger table creation
@sonjisov
sonjisov / enable-ttl.sh
Created May 23, 2019 09:02
Enabling TTL on an existing table
region=$1
tableName="JohnWickQuotes"
aws dynamodb update-time-to-live --table-name $tableName --time-to-live-specification Enabled=true,AttributeName=ttl --region $region
@sonjisov
sonjisov / enable-stream.sh
Created May 23, 2019 09:08
Enabling DynamoDB stream settings on an existing table
region=$1
# Quit on error
set -e
# 1. Update stream settings.
aws dynamodb update-table --table-name "JohnWickQuotes" --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES --region $region
service: wick-quotes
provider:
name: aws
runtime: nodejs8.10
stage: dev
environment:
iamRoleStatements:
- Effect: Allow
Action:
const aws = require('aws-sdk');
const dynamodb = new aws.DynamoDB.DocumentClient();
const uuid = require('uuid/v4');
const addToDynamoDb = async ({ butterflyName, bornTime }) => {
const butterflyId = uuid();
const nowTimestamp = new Date().getTime(); // Date when a butterfly is born as an egg
const becomesCaterpilarAt = nowTimestamp + 7 * 24 * 60 * 60 * 1000; // Time when an egg becomes a caterpilar (update terminology in the blog)
const publishToKinesis = async (payload) => {
// Publishing logic here which is irrelevant now
};
// NOTE : Although I believe that this code is mostly correct, I confess that I never ran it
// so it may contain some minor syntax errors or something like that....
export const handler = ({ Records: dynamoDbRecords }) => {
const promises = dynamoDbRecords.map(({ dynamodb: { OldImage: oldImage } }) => {
if (oldImage && oldImage.recordType === 'STATUS_TASK') { // We interested only in deleted records of type STATUS_TASK
return oldImage;